prepare for v1.6.0-beta

This commit is contained in:
xiaomlove
2021-01-30 13:53:15 +08:00
parent 328e8ef953
commit 1ad59dd4cd
15 changed files with 151 additions and 66 deletions

View File

@@ -6,4 +6,11 @@ MYSQL_DATABASE=nexusphp
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DATABASE=0
REDIS_DATABASE=0
USE_CRON_TRIGGER_CLEANUP=false
LOG_FILE=/tmp/nexus.log
LOG_SPLIT=daily
TIMEZONE=PRC

13
config/nexus.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
return [
'timezone' => env('TIMEZONE', 'PRC'),
'log_file' => env('LOG_FILE', '/tmp/nexus.log'),
'log_split' => env('LOG_SPLIT', 'daily'),
'use_cron_trigger_cleanup' => env('USE_CRON_TRIGGER_CLEANUP', false),
];

View File

@@ -4,6 +4,7 @@ if(!defined('IN_TRACKER'))
die('Hacking attempt!');
function printProgress($msg) {
do_log($msg);
echo $msg.'...done<br />';
ob_flush();
flush();

View File

@@ -401,7 +401,7 @@ $SUBSPATH = "subs";
//Make sure you have wget installed on your OS
//replace "http://www.nexusphp.com/" with your own site address
$useCronTriggerCleanUp = config('use_cron_trigger_clean_up', false);
$useCronTriggerCleanUp = config('nexus.use_cron_trigger_cleanup', false);
//some promotion rules
//$promotionrules_torrent = array(0 => array("mediumid" => array(1), "promotion" => 5), 1 => array("mediumid" => array(3), "promotion" => 5), 2 => array("catid" => array(402), "standardid" => array(3), "promotion" => 4), 3 => array("catid" => array(403), "standardid" => array(3), "promotion" => 4));
$promotionrules_torrent = array();

View File

@@ -2,6 +2,18 @@
if(!defined('IN_TRACKER')) {
die('Hacking attempt!');
}
define('ROOT_PATH', $rootpath);
define('VERSION_NUMBER', '1.6.0');
define('IS_ANNOUNCE', (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php'));
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID']);
} else {
define('REQUEST_ID', intval(NEXUS_START * 10000));
}
ini_set('date.timezone', config('nexus.timezone'));
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 0);
if (!file_exists($rootpath . '.env')) {
$installScriptRelativePath = 'install/install.php';
$installScriptFile = $rootpath . "public/$installScriptRelativePath";
@@ -10,16 +22,8 @@ if (!file_exists($rootpath . '.env')) {
exit(0);
}
}
error_reporting(E_ALL);
ini_set('display_errors', 0);
if (!empty($_SERVER['HTTP_X_REQUEST_ID'])) {
define('REQUEST_ID', $_SERVER['HTTP_X_REQUEST_ID']);
} else {
define('REQUEST_ID', intval(NEXUS_START * 10000));
}
define('ROOT_PATH', $rootpath);
define('VERSION_NUMBER', '1.6.0');
define('IS_ANNOUNCE', (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php'));
require $rootpath . 'vendor/autoload.php';
require $rootpath . 'nexus/Database/helpers.php';
require $rootpath . 'classes/class_advertisement.php';
@@ -31,7 +35,6 @@ if (!IS_ANNOUNCE) {
$Cache = new class_cache_redis(); //Load the caching class
$Cache->setLanguageFolderArray(get_langfolder_list());
define('TIMENOW', time());
define('TIMENOW_STRING', date('Y-m-d H:i:s'));
$USERUPDATESET = array();
$query_name=array();

View File

@@ -1870,19 +1870,21 @@ function userlogin() {
function autoclean() {
global $autoclean_interval_one, $rootpath;
$now = TIMENOW;
$res = sql_query("SELECT value_u FROM avps WHERE arg = 'lastcleantime'");
$row = mysql_fetch_array($res);
if (!$row) {
do_log("SELECT value_u FROM avps WHERE arg = 'lastcleantime', empty");
sql_query("INSERT INTO avps (arg, value_u) VALUES ('lastcleantime',$now)") or sqlerr(__FILE__, __LINE__);
return false;
}
$ts = $row[0];
if ($ts + $autoclean_interval_one > $now) {
do_log("ts: {$ts} + autoclean_interval_one: $autoclean_interval_one > now: $now");
return false;
}
sql_query("UPDATE avps SET value_u=$now WHERE arg='lastcleantime' AND value_u = $ts") or sqlerr(__FILE__, __LINE__);
if (!mysql_affected_rows()) {
do_log("UPDATE avps SET value_u=$now WHERE arg='lastcleantime' AND value_u = $ts, affectedRows = 0");
return false;
}
require_once($rootpath . 'include/cleanup.php');

View File

@@ -5,15 +5,7 @@ if(!defined('IN_TRACKER'))
function dbconn_announce() {
$config = config('database.mysql');
if (!@mysql_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']))
{
die('dbconn: mysql_connect: ' . mysql_error());
}
mysql_query("SET NAMES UTF8");
mysql_query("SET collation_connection = 'utf8_general_ci'");
mysql_query("SET sql_mode=''");
\Nexus\Database\DB::getInstance()->autoConnect();
}
function hash_where_arr($name, $hash_arr) {

View File

@@ -147,18 +147,14 @@ function dd($vars)
function do_log($log, $level = 'info')
{
global $TWEAK;
$logging = sys_get_temp_dir() . '/nexus_' . date('Y-m-d') . '.log';
if (!empty($TWEAK['logging'])) {
$logging = $TWEAK['logging'];
}
if (($fd = fopen($logging, 'a')) !== false) {
$logFile = getLogFile();
if (($fd = fopen($logFile, 'a')) !== false) {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$content = sprintf(
"[%s] [%s] [%s] %s:%s %s%s%s %s%s",
date('Y-m-d H:i:s'),
$level,
REQUEST_ID,
defined('REQUEST_ID') ? REQUEST_ID : '',
$backtrace[0]['file'] ?? '',
$backtrace[0]['line'] ?? '',
$backtrace[1]['class'] ?? '',
@@ -172,6 +168,43 @@ function do_log($log, $level = 'info')
}
}
function getLogFile()
{
static $logFile;
if (!is_null($logFile)) {
return $logFile;
}
$config = config('nexus');
$logFile = sys_get_temp_dir() . '/nexus_' . date('Y-m-d') . '.log';
if (!empty($config['log_file'])) {
$logFile = $config['log_file'];
}
$validSplit = ['daily', 'monthly'];
if (empty($config['log_split']) || !in_array($config['log_split'], $validSplit)) {
return $logFile;
}
$lastDotPos = strrpos($logFile, '.');
if ($lastDotPos !== false) {
$prefix = substr($logFile, 0, $lastDotPos);
$suffix = substr($logFile, $lastDotPos);
} else {
$prefix = $logFile;
$suffix = '';
}
switch ($config['log_split']) {
case 'daily':
$logFile = sprintf('%s-%s%s', $prefix, date('Y-m-d'), $suffix);
break;
case 'monthly':
$logFile = sprintf('%s-%s%s', $prefix, date('Ym'), $suffix);
break;
default:
break;
}
return $logFile;
}
function config($key, $default = null)
{
static $configs;

View File

@@ -680,8 +680,6 @@ $lang_settings = array
'text_email_notification_note' => "是否允许用户在收取新短讯、评论等时候收到邮件提示。",
'text_users_get' => "首次升级至此等级的用户将获得",
'text_invitations_default' => "个邀请名额。默认",
'row_logging' => '运行日志路径',
'text_logging_note' => '请填写你的运行时日志路径',
);
?>

View File

@@ -680,8 +680,6 @@ $lang_settings = array
'text_email_notification_note' => "是否允許用戶在收取新短訊、評論等時候收到郵件輔助說明。",
'text_users_get' => "首次升級至此等級的用戶將獲得",
'text_invitations_default' => "個邀請名額。預設",
'row_logging' => '運行日誌路徑',
'text_logging_note' => '請填寫妳的運行時日誌路徑',
);
?>

View File

@@ -680,8 +680,6 @@ $lang_settings = array
'text_email_notification_note' => "Allow users to receive email notification when he gets new pm, comment, etc.",
'text_users_get' => "Users would get ",
'text_invitations_default' => " invitations the first time he is promoted to this class. Default ",
'row_logging' => 'Runtime log path',
'text_logging_note' => 'Please enter your runtime log path',
);
?>

View File

@@ -8,8 +8,6 @@ class DB
private static $instance;
private static $queries = [];
private $isConnected = false;
private function __construct()
@@ -55,8 +53,6 @@ class DB
$this->driver->query("SET collation_connection = 'utf8_general_ci'");
$this->driver->query("SET sql_mode=''");
$this->isConnected = true;
$log = json_encode(func_get_args());
do_log($log);
return true;
}
@@ -66,7 +62,6 @@ class DB
return null;
}
$config = config('database.mysql');
do_log(json_encode($config));
return $this->connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
}

View File

@@ -10,6 +10,8 @@ class Install
private $minimumPhpVersion = '7.2.0';
private $progressKeyPrefix = '__step';
protected $steps = ['环境检测', '添加 .env 文件', '创建数据表', '导入数据', '创建管理员账号'];
protected $initializeTables = [
@@ -18,9 +20,15 @@ class Install
'searchbox', 'secondicons', 'sources', 'standards', 'stylesheets', 'sysoppanel', 'teams', 'torrents_state', 'uploadspeed', 'agent_allowed_family',
];
protected $envNames = ['MYSQL_HOST', 'MYSQL_PORT', 'MYSQL_USERNAME', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', 'REDIS_HOST', 'REDIS_PORT', 'REDIS_DATABASE'];
public function __construct()
{
if (!session_id()) {
session_start();
}
$this->currentStep = min(intval($_REQUEST['step'] ?? 1) ?: 1, count($this->steps) + 1);
}
@@ -29,6 +37,31 @@ class Install
return $this->currentStep;
}
public function canAccessStep($step)
{
for ($i = 1; $i < $step; $i++) {
$progressKey = $this->getProgressKey($i);
if (!isset($_SESSION[$progressKey])) {
do_log("check step: $i, session doesn't have, session: " . json_encode($_SESSION));
return false;
}
}
do_log("check step: $step, can access, session: " . json_encode($_SESSION));
return true;
}
public function doneStep($step)
{
$progressKey = $this->getProgressKey($step);
do_log("doneStep: $step, $progressKey = 1");
$_SESSION[$progressKey] = 1;
}
private function getProgressKey($step)
{
return $this->progressKeyPrefix . $step;
}
public function getLogFile()
{
return sprintf('%s/nexus_install_%s.log', sys_get_temp_dir(), date('Ymd'));
@@ -221,6 +254,7 @@ class Install
public function nextStep()
{
$this->doneStep($this->currentStep);
$this->gotoStep($this->currentStep + 1);
}
@@ -308,13 +342,14 @@ class Install
}
$mergeData = array_merge($envExampleData, $envData);
$formControls = [];
foreach ($mergeData as $key => $value) {
if (isset($_POST[$key])) {
$value = $_POST[$key];
foreach ($this->envNames as $name) {
$value = $mergeData[$name];
if (isset($_POST[$name])) {
$value = $_POST[$name];
}
$formControls[] = [
'label' => $key,
'name' => $key,
'label' => $name,
'name' => $name,
'value' => $value,
];
}
@@ -324,6 +359,10 @@ class Install
public function createAdministrator($username, $email, $password, $confirmPassword)
{
$count = get_row_count('users', 'where class = 16');
if ($count > 0) {
throw new \InvalidArgumentException("Administrator already exists");
}
if (!validusername($username)) {
throw new \InvalidArgumentException("Innvalid username: $username");
}
@@ -398,7 +437,7 @@ class Install
}
fwrite($fp, $content);
fclose($fp);
$this->doLog("[CREATE ENV] $envFile with content: \n $content");
$this->doLog("[CREATE ENV] $envFile with content: $content");
return true;
}
@@ -464,6 +503,12 @@ class Install
if (!in_array($table, $this->initializeTables)) {
continue;
}
//if table not empty, skip
$count = get_row_count($table);
if ($count > 0) {
$this->doLog("[IMPORT DATA] $table, not empty, skip");
continue;
}
$this->doLog("[IMPORT DATA] $table, $sql");
sql_query("truncate table $table");
sql_query($sql);

View File

@@ -1,9 +1,6 @@
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 0);
if (!session_id()) {
session_start();
}
$rootpath = dirname(dirname(__DIR__)) . '/';
define('ROOT_PATH', $rootpath);
$isPost = $_SERVER['REQUEST_METHOD'] == 'POST';
@@ -15,6 +12,10 @@ require $rootpath . 'nexus/Database/helpers.php';
$install = new \Nexus\Install\Install();
$currentStep = $install->currentStep();
$maxStep = $install->maxStep();
if (!$install->canAccessStep($currentStep)) {
$install->gotoStep(1);
}
$error = $copy = '';
//step 1
if ($currentStep == 1) {
@@ -35,7 +36,7 @@ if ($currentStep == 2) {
$install->createEnvFile($_POST);
$install->nextStep();
} catch (\Exception $exception) {
$_SESSION['error'] = $exception->getMessage();
$error = $exception->getMessage();
break;
}
break;
@@ -60,7 +61,7 @@ if ($currentStep == 3) {
$install->createTable($shouldCreateTable);
$install->nextStep();
} catch (\Exception $exception) {
$_SESSION['error'] = $exception->getMessage();
$error = $exception->getMessage();
break;
}
break;
@@ -90,7 +91,7 @@ if ($currentStep == 3) {
// sql_query($sqlAlter);
// }
// } catch (\Exception $e) {
// $_SESSION['error'] = $e->getMessage();
// $error = $e->getMessage();
// break;
// }
// }
@@ -113,7 +114,7 @@ if ($currentStep == 4) {
$install->importInitialData();
$install->nextStep();
} catch (\Exception $e) {
$_SESSION['error'] = $e->getMessage();
$error = $e->getMessage();
break;
}
break;
@@ -126,7 +127,7 @@ if ($currentStep == 5) {
$install->createAdministrator($_POST['username'], $_POST['email'], $_POST['password'], $_POST['confirm_password']);
$install->nextStep();
} catch (\Exception $exception) {
$_SESSION['error'] = $exception->getMessage();
$error = $exception->getMessage();
}
}
$pass = true;
@@ -134,7 +135,7 @@ if ($currentStep == 5) {
['label' => '用户名', 'name' => 'username', 'value' => $_POST['username'] ?? ''],
['label' => '邮箱', 'name' => 'email', 'value' => $_POST['email'] ?? ''],
['label' => '密码', 'name' => 'password', 'value' => $_POST['password'] ?? ''],
['label' => '重复密码', 'name' => 'confirm_password', 'value' => $_POST['confirm_password'] ?? ''],
['label' => '确认密码', 'name' => 'confirm_password', 'value' => $_POST['confirm_password'] ?? ''],
];
}
?>
@@ -186,13 +187,13 @@ if ($currentStep == 5) {
}
echo'</div>';
if (!empty($_SESSION['error'])) {
echo sprintf('<div class="text-center text-red-500 p-4">Error: %s</div>', nl2br($_SESSION['error']));
unset($_SESSION['error']);
if (!empty($error)) {
echo sprintf('<div class="text-center text-red-500 p-4">Error: %s</div>', nl2br($error));
unset($error);
}
if (!empty($_SESSION['copy'])) {
echo sprintf('<div class="text-center"><textarea class="w-1/2 h-40 border">%s</textarea></div>', $_SESSION['copy']);
unset($_SESSION['copy']);
if (!empty($copy)) {
echo sprintf('<div class="text-center"><textarea class="w-1/2 h-40 border">%s</textarea></div>', $copy);
unset($copy);
}
?>
<div class="mt-10 text-center">
@@ -207,7 +208,7 @@ if ($currentStep == 5) {
</div>
</div>
<div class="mt-10 text-center">
欢迎使用 NexusPHP 安装程序,如有疑问,点击<a href="http://nexusphp.org/" target="_blank" class="text-blue-500 p-1">这里</a>获取参考
欢迎使用 NexusPHP 安装程序,如有疑问,点击<a href="http://nexusphp.org/" target="_blank" class="text-blue-500 p-1">这里</a>获取帮助
</div>
</body>
<script>

View File

@@ -41,7 +41,7 @@ if ($action == 'savesettings_main') // save main
'showpolls','showstats','showlastxtorrents', 'showtrackerload','showshoutbox','showfunbox','showoffer','sptime','showhelpbox','enablebitbucket',
'smalldescription','altname','extforum','extforumurl','defaultlang','defstylesheet', 'donation','spsct','browsecat','specialcat','waitsystem',
'maxdlsystem','bitbucket','torrentnameprefix', 'showforumstats','verification','invite_count','invite_timeout', 'seeding_leeching_time_calc_start',
'startsubid', 'logo', 'use_cron_trigger_cleanup', 'showlastxforumposts'
'startsubid', 'logo', 'showlastxforumposts'
);
GetVar($validConfig);
$MAIN = [];
@@ -185,7 +185,7 @@ elseif ($action == 'savesettings_authority') // save user authority
elseif ($action == 'savesettings_tweak') // save tweak
{
stdhead($lang_settings['head_save_tweak_settings']);
$validConfig = array('where','iplog1','bonus','datefounded', 'enablelocation', 'titlekeywords', 'metakeywords', 'metadescription', 'enablesqldebug', 'sqldebug', 'cssdate', 'enabletooltip', 'prolinkimg', 'analyticscode', 'logging');
$validConfig = array('where','iplog1','bonus','datefounded', 'enablelocation', 'titlekeywords', 'metakeywords', 'metadescription', 'enablesqldebug', 'sqldebug', 'cssdate', 'enabletooltip', 'prolinkimg', 'analyticscode');
GetVar($validConfig);
$TWEAK = [];
foreach($validConfig as $config) {
@@ -245,7 +245,6 @@ elseif ($action == 'tweaksettings') // tweak settings
tr($lang_settings['row_see_sql_debug'], "<input type='checkbox' name='enablesqldebug' value='yes'".($TWEAK['enablesqldebug'] == 'yes' ? " checked='checked'" : "")." />".$lang_settings['text_allow'].classlist('sqldebug',UC_STAFFLEADER,$TWEAK['sqldebug'], UC_MODERATOR).$lang_settings['text_see_sql_list'].get_user_class_name(UC_SYSOP,false,true,true),1);
tr($lang_settings['row_tracker_founded_date'],"<input type='text' style=\"width: 300px\" name=datefounded value='".($TWEAK["datefounded"] ? $TWEAK["datefounded"] : '2007-12-24')."'> <br />".$lang_settings['text_tracker_founded_date_note'], 1);
tr($lang_settings['row_css_date'],"<input type='text' style=\"width: 300px\" name=cssdate value='".($TWEAK["cssdate"] ? $TWEAK["cssdate"] : '')."'> <br />".$lang_settings['text_css_date'], 1);
tr($lang_settings['row_logging'],"<input type='text' style=\"width: 300px\" name=logging value='".($TWEAK["logging"] ? $TWEAK["logging"] : '')."'> <br />".$lang_settings['text_logging_note'], 1);
tr($lang_settings['row_save_settings'],"<input type='submit' name='save' value='".$lang_settings['submit_save_settings']."'>", 1);
print ("</form>");