From a6f2419c5ecdccd783bb9a5d98612ea1ab72f924 Mon Sep 17 00:00:00 2001
From: xiaomlove <353856593@qq.com>
Date: Mon, 31 May 2021 21:04:49 +0800
Subject: [PATCH] cleanup in cli
---
include/cleanup.php | 5 ++---
include/cleanup_cli.php | 26 ++++++++++++++++++++++++++
include/config.php | 2 +-
include/globalfunctions.php | 13 +++++++++----
4 files changed, 38 insertions(+), 8 deletions(-)
create mode 100644 include/cleanup_cli.php
diff --git a/include/cleanup.php b/include/cleanup.php
index 69ddf730..db27c75f 100644
--- a/include/cleanup.php
+++ b/include/cleanup.php
@@ -4,9 +4,8 @@ if(!defined('IN_TRACKER'))
die('Hacking attempt!');
function printProgress($msg) {
- echo $msg.'...done
';
- ob_flush();
- flush();
+ $br = php_sapi_name() == 'cli' ? "\n" : "
";
+ echo sprintf("[%s] %s ... done!%s", date('Y-m-d H:i:s'), $msg, $br);
}
function torrent_promotion_expire($days, $type = 2, $targettype = 1){
diff --git a/include/cleanup_cli.php b/include/cleanup_cli.php
new file mode 100644
index 00000000..0091787d
--- /dev/null
+++ b/include/cleanup_cli.php
@@ -0,0 +1,26 @@
+getMessage());
+ throw new \RuntimeException($exception->getMessage());
+}
+
diff --git a/include/config.php b/include/config.php
index ff97c422..883a5180 100644
--- a/include/config.php
+++ b/include/config.php
@@ -69,7 +69,7 @@ foreach ($settings as $name => $value) {
$SITENAME = $BASIC['SITENAME'];
//$BASEURL = $BASIC['BASEURL'];
-$BASEURL = $_SERVER['HTTP_HOST'];
+$BASEURL = $_SERVER['HTTP_HOST'] ?? '';
$announce_urls = array();
//$announce_urls[] = $BASIC['announce_url'];
$announce_urls[] = $BASEURL . '/announce.php';
diff --git a/include/globalfunctions.php b/include/globalfunctions.php
index f07cd5ef..4cb6db02 100644
--- a/include/globalfunctions.php
+++ b/include/globalfunctions.php
@@ -47,7 +47,7 @@ function getip() {
} elseif (isset($_SERVER['HTTP_CLIENT_IP']) && validip($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else {
- $ip = $_SERVER['REMOTE_ADDR'];
+ $ip = $_SERVER['REMOTE_ADDR'] ?? '';
}
} else {
if (getenv('HTTP_X_FORWARDED_FOR') && validip(getenv('HTTP_X_FORWARDED_FOR'))) {
@@ -55,7 +55,7 @@ function getip() {
} elseif (getenv('HTTP_CLIENT_IP') && validip(getenv('HTTP_CLIENT_IP'))) {
$ip = getenv('HTTP_CLIENT_IP');
} else {
- $ip = getenv('REMOTE_ADDR');
+ $ip = getenv('REMOTE_ADDR') ?? '';
}
}
@@ -158,8 +158,9 @@ function do_log($log, $level = 'info')
if (($fd = fopen($logFile, 'a')) === false) {
$fd = fopen(sys_get_temp_dir() . '/nexus.log', 'a');
}
- static $uid, $passkey, $env;
+ static $uid, $passkey, $env, $sequence;
if (is_null($uid)) {
+ $sequence = 0;
if (IN_NEXUS) {
global $CURUSER;
$user = $CURUSER;
@@ -172,14 +173,18 @@ function do_log($log, $level = 'info')
$passkey = $user->passkey ?? $_REQUEST['passkey'] ?? '';
$env = env('APP_ENV');
}
+ } else {
+ $sequence++;
}
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$content = sprintf(
- "[%s] [%s] [%s] [%s] %s.%s %s:%s %s%s%s %s%s",
+ "[%s] [%s] [%s] [%s] [%s] [%s] %s.%s %s:%s %s%s%s %s%s",
date('Y-m-d H:i:s'),
defined('REQUEST_ID') ? REQUEST_ID : '',
$uid,
$passkey,
+ $sequence,
+ sprintf('%.3f', microtime(true) - NEXUS_START),
$env, $level,
$backtrace[0]['file'] ?? '',
$backtrace[0]['line'] ?? '',