From aa09458715f621a5cd805bbe5c5b316c7febdba3 Mon Sep 17 00:00:00 2001 From: Simplaf234 <68116034+Simplaf234@users.noreply.github.com> Date: Fri, 10 Jul 2020 14:32:59 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D1=89=D0=B8=D0=BA=20(=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Доработал установщик, который ранее выкладывался в #44. Если остались проблемы — напишите, какие. --- install.php | 444 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 444 insertions(+) create mode 100644 install.php diff --git a/install.php b/install.php new file mode 100644 index 0000000..27698c9 --- /dev/null +++ b/install.php @@ -0,0 +1,444 @@ + + + + + + Установка Simpla + + + +
+
+

Установка Simpla 2.3

+ +
+
+ + + + + + + + Пользовательское соглашение: +

"; + print "

"; +} + +// +// Настройка mysql +// +function dbconfig() +{ + $configfile = 'config/config.php'; + + $dbhost = 'localhost'; + $dbname = ''; + $dbuser = ''; + $dbpassword = ''; + $error = ''; + + if(isset($_POST['dbhost'])) + $dbhost = $_POST['dbhost']; + if(isset($_POST['dbname'])) + $dbname = $_POST['dbname']; + if(isset($_POST['dbuser'])) + $dbuser = $_POST['dbuser']; + if(isset($_POST['dbpassword'])) + $dbpassword = $_POST['dbpassword']; + + if(!empty($dbname) && !empty($dbuser)) + { + $GLOBALS['lk'] = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname); + if (mysqli_connect_errno()) { + printf("Не удалось подключиться: Connect %s\n", mysqli_connect_error()); + exit(); + } + + if (!mysqli_query($GLOBALS['lk'], 'SET NAMES utf8') === TRUE) { + printf("Не удалось подключиться: Query\n "); + } + + if(!is_readable('simpla.sql')) + $error = 'Файл simpla.sql не найден'; + + if(!is_writable('config/config.php')) + $error = 'Поставьте права на запись для файла config/config.php'; + + if(empty($error)) + { + mysqlrestore('simpla.sql'); + + # Запишем конфиги с базой + $conf = file_get_contents('config/config.php'); + $conf = preg_replace("/db_name.*;/i", 'db_name = "'.$dbname.'"', $conf); + $conf = preg_replace("/db_server.*;/i", 'db_server = "'.$dbhost.'"', $conf); + $conf = preg_replace("/db_user.*;/i", 'db_user = "'.$dbuser.'"', $conf); + $conf = preg_replace("/db_password.*;/i", 'db_password = "'.$dbpassword.'"', $conf); + $cf = fopen('config/config.php', 'w'); + fwrite($cf, $conf); + fclose($cf); + + print "

База данных успешно настроена

"; + print "

"; + exit(); + + } + + } + + + + print "

Введите параметры базы данных MySQL

"; + if(empty($error)) + print "

Существующие данные в базе будут уничтожены!

"; + if(!empty($error)) + print "

$error

"; + print "

"; + print ""; + print ""; + print ""; + print ""; + print ""; + print "
Сервер
Имя базы
Логин
Пароль

"; + +} + + + +// +// Настройка лицензии +// +function license() +{ + $license = ''; + $error = ''; + + $end = date("Y-m-d", time()+60*60*24*31); // на 31 день + $c = ''; + for($i=0; $iВаша тестовая лицензия действительна до: $enddate;

"; + else + print "

Благодарим вас за использование лицензионной версии Simpla!

"; + + print "

"; + exit(); + } + + + + } + + print "

Для работы Simpla необходим лицензионный ключ:

"; + if(!empty($error)) + print "

$error

"; + print "

"; + print "

"; + + +} + +// +// Установка пароля администратора +// +function adminconf() +{ + $current_dir = dirname(__FILE__); + $error = ''; + if(isset($_POST['login']) && isset($_POST['password'])) + { + + if(!is_writable($current_dir.'/simpla/.passwd')) + $error = 'Поставьте права на запись для файла '.$current_dir.'/simpla/.passwd'; + + if(!is_writable($current_dir.'/simpla/.htaccess')) + $error = 'Поставьте права на запись для файла '.$current_dir.'/simpla/.htaccess'; + + if(empty($error)) + { + $login = $_POST['login']; + $password = $_POST['password']; + $encpassword = crypt_apr1_md5($password); + + $path_to_passwd = $current_dir.'/simpla/.passwd'; + + $passstring = $login.':'.$encpassword; + $passfile = fopen($path_to_passwd, 'w'); + fputs($passfile, $passstring); + fclose($passfile); + + + $htaccess = file_get_contents($current_dir.'/simpla/.htaccess'); + $htaccess = preg_replace("/AuthUserFile .*\n/i", "AuthUserFile $path_to_passwd\n", $htaccess); + + $htafile = fopen($current_dir.'/simpla/.htaccess', 'w'); + fwrite($htafile, $htaccess); + fclose($htafile); + print "

Пароль администратора установлен успешно. Не забудьте его.

"; + print "

"; + exit(); + + + } + + } + + print "

Задайте логин и пароль администратора сайта.

"; + if(!empty($error)) + print "

$error

"; + print "

"; + print ""; + print ""; + print ""; + print "
Логин
Пароль

"; +} + + +// +// Конечный шаг +// +function finalstep() +{ + @unlink('simpla.sql'); + @unlink('install.php'); + + if(is_file('install.php')) + $error = 'Обязательно удалите файлы install.php и simpla.sql'; + + $url = rtrim('http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI']), '/'); + print "

Установка завершена успешно

"; + print "

Адрес вашего сайта: $url

"; + print "

Панель управления: $url/simpla

"; + print "

Приятной работы с Simpla!

"; + if(!empty($error)) + print "

$error

"; +} + + + + +function crypt_apr1_md5($plainpasswd) { + $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8); + $len = strlen($plainpasswd); + $text = $plainpasswd.'$apr1$'.$salt; + $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd)); + for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); } + for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd{0}; } + $bin = pack("H32", md5($text)); + for($i = 0; $i < 1000; $i++) { + $new = ($i & 1) ? $plainpasswd : $bin; + if ($i % 3) $new .= $salt; + if ($i % 7) $new .= $plainpasswd; + $new .= ($i & 1) ? $bin : $plainpasswd; + $bin = pack("H32", md5($new)); + } + for ($i = 0; $i < 5; $i++) { + $k = $i + 6; + $j = $i + 12; + if ($j == 16) $j = 5; + $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp; + } + $tmp = chr(0).chr(0).$bin[11].$tmp; + $tmp = strtr(strrev(substr(base64_encode($tmp), 2)), + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", + "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); + return "$"."apr1"."$".$salt."$".$tmp; +} + + + +################################################################## +################################################################## + + +function mysqlrestore($filename) +{ + $templine = ''; + $fp = fopen($filename, 'r'); + + // Loop through each line + if($fp) + while(!feof($fp)) { + $line = fgets($fp); + // Only continue if it's not a comment + if (substr($line, 0, 2) != '--' && $line != '') { + // Add this line to the current segment + $templine .= $line; + // If it has a semicolon at the end, it's the end of the query + if (substr(trim($line), -1, 1) == ';') { + // Perform the query + mysqli_query($GLOBALS['lk'], $templine) or print('Error performing query \'' . $templine . '\': ' . mysqli_error() . '

'); + // Reset temp variable to empty + $templine = ''; + } + } + } + + fclose($fp); +} + +################################################################## +################################################################## + + +function check_license($license) +{ + $p=11; $g=2; $x=7; $r = ''; $s = $x; + $bs = explode(' ', $license); + foreach($bs as $bl){ + for($i=0, $m=''; $idomains, $l->expiration, $l->comment) = explode('#', $r, 3); + + $l->domains = explode(',', $l->domains); + + $h = getenv("HTTP_HOST"); + if(substr($h, 0, 4) == 'www.') $h = substr($h, 4); + if(!in_array($h, $l->domains) || (strtotime($l->expiration)expiration!='*')) + return false; + else + { + return $l->expiration; + } + +}