improve_install

This commit is contained in:
xiaomlove
2021-01-22 19:43:15 +08:00
parent cf044448c7
commit b80264f7b7
3 changed files with 20 additions and 80 deletions

View File

@@ -1,8 +1,4 @@
<?php
# IMPORTANT: Do not edit below unless you know what you are doing!
if(!defined('IN_TRACKER'))
die('Hacking attempt!');
function get_langfolder_cookie()
{
global $deflang;
@@ -1754,7 +1750,7 @@ function getExportedValue($input,$t = null) {
return 'NULL';
}
function dbconn($autoclean = false)
function dbconn($autoclean = false, $doLogin = true)
{
if (DB::getInstance()->isConnected()) {
return;
@@ -1768,7 +1764,9 @@ function dbconn($autoclean = false)
mysql_query("SET collation_connection = 'utf8_general_ci'");
mysql_query("SET sql_mode=''");
userlogin();
if ($doLogin) {
userlogin();
}
// if (!$useCronTriggerCleanUp && $autoclean) {
// register_shutdown_function("autoclean");
@@ -4402,4 +4400,20 @@ function return_category_image($categoryid, $link="")
return $catimg;
}
function saveSetting($prefix, $nameAndValue)
{
$prefix = strtolower($prefix);
$datetimeNow = date('Y-m-d H:i:s');
$sql = "insert into settings (name, value, created_at, updated_at) values ";
$data = [];
foreach ($nameAndValue as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
}
$data[] = sprintf("(%s, %s, %s, %s)", sqlesc("$prefix.$name"), sqlesc($value), sqlesc($datetimeNow), sqlesc($datetimeNow));
}
$sql .= implode(",", $data) . " on duplicate key update value = values(value)";
sql_query($sql) or sqlerr(__FILE__, __LINE__);
}
?>

View File

@@ -1,58 +0,0 @@
<?php
/**
* update 1.5 to 1.6, run in console
* @author xiaomlove<1939737565@qq.com>
*/
function printLine($msg, $exit = false)
{
echo sprintf("[%s] %s%s", date('Y-m-d H:i:s'), $msg, PHP_EOL);
if ($exit) {
exit(0);
}
}
if (php_sapi_name() != 'cli') {
printLine("Please run in console!", true);
}
//environment check
printLine("Checking the environment...");
if (version_compare(PHP_VERSION, '7.2.0', '<')) {
printLine(sprintf('Your PHP version: %s not match, require >= 7.2.0', PHP_VERSION));
}
$requireExtensions = ['mysqli', 'mbstring', 'gd', 'json'];
foreach ($requireExtensions as $ext) {
if (extension_loaded($ext)) {
printLine("extension: $ext is loaded.");
} else {
printLine("Error: required extension: $ext is not loaded!", true);
}
}
if (!extension_loaded('redis')) {
printLine("warning: redis is not loaded. highly recommand install it, see: https://pecl.php.net/package/redis/");
}
$gdInfo = gd_info();
$gdShouldAvaliable = ['JPEG Support', 'PNG Support', 'GIF Read Support'];
foreach ($gdShouldAvaliable as $value) {
if (!isset($gdInfo[$value]) || !$gdInfo[$value]) {
printLine("Error: gd $value is not available", true);
}
}
//create .env file
$rootPath = dirname(__DIR__);
$envExample = "$rootPath/.env.example";
$env = "$rootPath/.env";
if (!file_exists("$rootPath.env")) {
printLine("Error: $envExample not exists.");
}
$copyResult = copy($envExample, $env);
if ($copyResult !== true) {
}

View File

@@ -8,7 +8,6 @@ parked();
if (get_user_class() < UC_SYSOP)
permissiondenied();
$datetimeNow = date('Y-m-d H:i:s');
function go_back()
{
global $lang_settings;
@@ -21,21 +20,6 @@ function yesorno($title, $name, $value, $note="")
tr($title, "<input type='radio' id='".$name."yes' name='".$name."'".($value == "yes" ? " checked=\"checked\"" : "")." value='yes' /> <label for='".$name."yes'>".$lang_settings['text_yes']."</label> <input type='radio' id='".$name."no' name='".$name."'".($value == "no" ? " checked=\"checked\"" : "")." value='no' /> <label for='".$name."no'>".$lang_settings['text_no']."</label><br />".$note, 1);
}
function saveSetting($prefix, $nameAndValue)
{
global $datetimeNow;
$sql = "insert into settings (name, value, created_at, updated_at) values ";
$data = [];
foreach ($nameAndValue as $name => $value) {
if (is_array($value)) {
$value = json_encode($value);
}
$data[] = sprintf("(%s, %s, %s, %s)", sqlesc("$prefix.$name"), sqlesc($value), sqlesc($datetimeNow), sqlesc($datetimeNow));
}
$sql .= implode(",", $data) . " on duplicate key update value = values(value)";
sql_query($sql) or sqlerr(__FILE__, __LINE__);
}
$action = isset($_POST['action']) ? $_POST['action'] : 'showmenu';
$allowed_actions = array('basicsettings','mainsettings','smtpsettings','securitysettings','authoritysettings','tweaksettings', 'botsettings','codesettings','bonussettings','accountsettings','torrentsettings', 'attachmentsettings', 'advertisementsettings', 'savesettings_basic', 'savesettings_main','savesettings_smtp','savesettings_security','savesettings_authority','savesettings_tweak','savesettings_bot','savesettings_code','savesettings_bonus', 'savesettings_account','savesettings_torrent', 'savesettings_attachment', 'savesettings_advertisement', 'showmenu');
if (!in_array($action, $allowed_actions))