diff --git a/php/composer.json b/php/composer.json index 9ebdadc..006fd00 100644 --- a/php/composer.json +++ b/php/composer.json @@ -5,6 +5,7 @@ "kryptonit3/sonarr": "^1.0", "guzzlehttp/guzzle": "^6.2", "symfony/polyfill-mbstring": "^1.2", - "kryptonit3/couchpotato": "1.0.0" - } + "kryptonit3/couchpotato": "1.0.0", + "ext-json": "*" + } } diff --git a/php/util.php b/php/util.php index 1371c7f..e97f9ad 100644 --- a/php/util.php +++ b/php/util.php @@ -3,6 +3,7 @@ require_once dirname(__FILE__) . '/vendor/autoload.php'; require_once dirname(__FILE__) . '/JsonXmlElement.php'; require_once dirname(__FILE__) . '/multiCurl.php'; +if (file_exists('/var/www/util/serverUtil.php')) require_once '/var/www/util/serverUtil.php'; function array_diff_assoc_recursive($array1, $array2) { @@ -2509,49 +2510,51 @@ function translateControl($string, $searchArray) { return $string; } -function write_log($text, $level = false, $caller = false, $force=false, $skip=false) { - $log = file_build_path(dirname(__FILE__), '..', 'logs', "Phlex.log.php"); - $pp = false; - if ($force && isset($_GET['pollPlayer'])) { - $pp = true; - unset($_GET['pollPlayer']); - } - if (!file_exists($log)) { - touch($log); - chmod($log, 0666); - $authString = "; ".PHP_EOL; - file_put_contents($log,$authString); - } - if (filesize($log) > 10485760) { - $oldLog = file_build_path(dirname(__FILE__),"..",'logs',"Phlex.log.php.old"); - if (file_exists($oldLog)) unlink($oldLog); - rename($log, $oldLog); - touch($log); - chmod($log, 0666); - $authString = "; ".PHP_EOL; - file_put_contents($log,$authString); - } - - $aux = microtime(true); - $now = DateTime::createFromFormat('U.u', $aux); - if (is_bool($now)) $now = DateTime::createFromFormat('U.u', $aux += 0.001); - $date = $now->format("m-d-Y H:i:s.u"); - $level = $level ? $level : "DEBUG"; - $user = $_SESSION['plexUserName'] ?? false; - $user = $user ? "[$user] " : ""; - $caller = $caller ? getCaller($caller) : getCaller(); - if (!$skip) $text = protectMessage(($text)); - - if ((isset($_GET['pollPlayer']) || isset($_GET['passive'])) || ($text === "") || !file_exists($log)) return; - - $line = "[$date] [$level] ".$user."[$caller] - $text".PHP_EOL; - - if ($pp) $_SESSION['pollPlayer'] = true; - if (!is_writable($log)) return; - if (!$handle = fopen($log, 'a+')) return; - if (fwrite($handle, $line) === FALSE) return; - - fclose($handle); +if (!function_exists('write_log')) { + function write_log($text, $level = false, $caller = false, $force = false, $skip = false) { + $log = file_build_path(dirname(__FILE__), '..', 'logs', "Phlex.log.php"); + $pp = false; + if ($force && isset($_GET['pollPlayer'])) { + $pp = true; + unset($_GET['pollPlayer']); + } + if (!file_exists($log)) { + touch($log); + chmod($log, 0666); + $authString = "; " . PHP_EOL; + file_put_contents($log, $authString); + } + if (filesize($log) > 10485760) { + $oldLog = file_build_path(dirname(__FILE__), "..", 'logs', "Phlex.log.php.old"); + if (file_exists($oldLog)) unlink($oldLog); + rename($log, $oldLog); + touch($log); + chmod($log, 0666); + $authString = "; " . PHP_EOL; + file_put_contents($log, $authString); + } + + $aux = microtime(true); + $now = DateTime::createFromFormat('U.u', $aux); + if (is_bool($now)) $now = DateTime::createFromFormat('U.u', $aux += 0.001); + $date = $now->format("m-d-Y H:i:s.u"); + $level = $level ? $level : "DEBUG"; + $user = $_SESSION['plexUserName'] ?? false; + $user = $user ? "[$user] " : ""; + $caller = $caller ? getCaller($caller) : getCaller(); + if (!$skip) $text = protectMessage(($text)); + + if ((isset($_GET['pollPlayer']) || isset($_GET['passive'])) || ($text === "") || !file_exists($log)) return; + + $line = "[$date] [$level] " . $user . "[$caller] - $text" . PHP_EOL; + + if ($pp) $_SESSION['pollPlayer'] = true; + if (!is_writable($log)) return; + if (!$handle = fopen($log, 'a+')) return; + if (fwrite($handle, $line) === FALSE) return; + + fclose($handle); + } } function writeSession($key, $value, $unset = false) { diff --git a/php/webApp.php b/php/webApp.php index 5ed9a28..38b65fa 100644 --- a/php/webApp.php +++ b/php/webApp.php @@ -182,6 +182,8 @@ function scriptDefaults() { ini_set('max_execution_time', 300); error_reporting(E_ERROR); $errorLogPath = file_build_path(dirname(__FILE__),'..', 'logs', 'Phlex_error.log.php'); + $host = gethostname(); + if (file_exists("/var/s3bucket/$host.log")) $errorLogPath = "/var/s3bucket/$host.log"; ini_set("error_log", $errorLogPath); date_default_timezone_set((date_default_timezone_get() ? date_default_timezone_get() : "America/Chicago")); }