mirror of
https://gitlab.com/JKANetwork/CheckServer.git
synced 2026-02-16 10:11:34 +01:00
Start again
This commit is contained in:
143
install.php
Executable file → Normal file
143
install.php
Executable file → Normal file
@@ -1,92 +1,51 @@
|
||||
<?php
|
||||
define('VERSION','0.9.4');
|
||||
//define('INSTALLER_MODE','1');
|
||||
require_once 'lib/loadTwig.php';
|
||||
|
||||
$db_file = __DIR__."/sqlite.db3";
|
||||
if (is_file($db_file)){ //Go to install if not.
|
||||
header('Location: index.php'); //Ya está instalado. Borra la base de datos si quieres forzar una reinstalación
|
||||
}
|
||||
|
||||
if (!isset($_POST['websiteName']) && !isset($_POST['username']) && !isset($_POST['passw1']) && !isset($_POST['passw2'])){
|
||||
echo $twig->render('install.twig');
|
||||
}else{
|
||||
if ($_POST['passw1'] !== $_POST['passw2']){
|
||||
die("Passwords didn't match");
|
||||
}else{
|
||||
//Creamos toda la base de datos
|
||||
require_once "lib/dbwrapper.php"; //For using database
|
||||
$db_conn = dbw_connect("sqlite",$db_file); //Create database
|
||||
$sqlcreate='
|
||||
BEGIN TRANSACTION;
|
||||
CREATE TABLE "VISITS" (
|
||||
`ID_C` INTEGER,
|
||||
`date` INTEGER,
|
||||
`visits` INTEGER DEFAULT 0,
|
||||
`uniqueVisits` INTEGER DEFAULT 0,
|
||||
FOREIGN KEY(`ID_C`) REFERENCES `Sites`(`ID_Site`)
|
||||
);
|
||||
CREATE TABLE "USERS" (
|
||||
`ID_U` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`nick` TEXT NOT NULL UNIQUE,
|
||||
`passw` TEXT,
|
||||
`fullRights` INTEGER NOT NULL
|
||||
);
|
||||
CREATE TABLE "TOKENS" (
|
||||
`ID_T` TEXT UNIQUE,
|
||||
`name` TEXT,
|
||||
PRIMARY KEY(`ID_T`)
|
||||
);
|
||||
CREATE TABLE "SYS" (
|
||||
`option` TEXT UNIQUE,
|
||||
`value` TEXT
|
||||
);
|
||||
CREATE TABLE "NEWS" (
|
||||
`ID_N` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`text` TEXT NOT NULL,
|
||||
`timestamp` INTEGER NOT NULL,
|
||||
`sentBy` TEXT
|
||||
);
|
||||
CREATE TABLE "GROUPS" (
|
||||
`ID_G` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT NOT NULL
|
||||
);
|
||||
CREATE TABLE "CHKHIST" (
|
||||
`ID_CHist` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`ID_C` INTEGER,
|
||||
`code` INTEGER,
|
||||
`errorText` TEXT,
|
||||
`timestamp` INTEGER,
|
||||
FOREIGN KEY(`ID_C`) REFERENCES `Sites`(`ID_Site`)
|
||||
);
|
||||
CREATE TABLE "CHECKS" (
|
||||
`ID_C` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`ID_G` INTEGER,
|
||||
`name` TEXT NOT NULL,
|
||||
`url` TEXT,
|
||||
`manStatus` INTEGER,
|
||||
`ID_TC` INTEGER,
|
||||
`urlParam` TEXT,
|
||||
`exceptedRes` TEXT,
|
||||
FOREIGN KEY(`ID_G`) REFERENCES `GROUPS`(`ID_G`),
|
||||
FOREIGN KEY(`ID_TC`) REFERENCES `TYPECHK`(`ID_TC`)
|
||||
);
|
||||
COMMIT;';
|
||||
dbw_multi_query($db_conn,$sqlcreate); //Create scheme
|
||||
$user = $_POST['username'];
|
||||
$pass = hash("sha256",$_POST['passw1']);
|
||||
dbw_query($db_conn,"INSERT INTO USERS (nick,passw,fullRights) VALUES('$user','$pass',1)"); //Create user
|
||||
|
||||
//System opts
|
||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('maxTimeSave',14)");
|
||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('lang','$_POST[lang]')");
|
||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('websiteTitle','Status')");
|
||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('version','".VERSION."')");
|
||||
dbw_query($db_conn,"INSERT INTO SYS VALUES ('maintenance','0')");
|
||||
|
||||
echo $twig->render('install.twig', array('part' => 2));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
session_start(); session_destroy(); //No session in install
|
||||
require_once 'functions.php';
|
||||
if (file_exists(dirname(__FILE__).'/config/config.php')){
|
||||
die("Ya está instalado. Borre el fichero /config/config.php si quiere reiniciar la instalación");
|
||||
}
|
||||
|
||||
//Comprobaciones
|
||||
if (!function_exists('socket_create') ){
|
||||
sendmsg('error','Debes activar el soporte para socket en el php.ini');
|
||||
}
|
||||
if (!is_writable(__DIR__ .'/config/') ){
|
||||
sendmsg('error','Debes dar permisos de escritura al directorio config');
|
||||
}
|
||||
|
||||
if (isset($_POST['adminname'])){
|
||||
|
||||
list($adminname,$adminmail,$adminname,$adminpass,$dbhost,$dbdata,$dbuser,$dbpass) = array(
|
||||
cleanData($_POST['adminname']),cleanData($_POST['adminmail']),cleanData($_POST['adminname']),cleanData($_POST['adminpass']),
|
||||
cleanData($_POST['dbhost']),cleanData($_POST['dbdata']),cleanData($_POST['dbuser']),cleanData($_POST['dbpass'])
|
||||
);
|
||||
|
||||
$db_conn = dbw_connect('mysqli',$dbhost,$dbdata,$dbuser,$dbpass);
|
||||
if (!$db_conn){
|
||||
sendmsg('error','No se puede conetar a la base de datos');
|
||||
renderPage('install.twig');
|
||||
die();
|
||||
}
|
||||
|
||||
dbw_multi_query($db_conn,file_get_contents(dirname(__FILE__).'/assets/sqlinstalldata.sql'),1); //1 is erase buffer then. (For insert)
|
||||
//Crear usuario admin
|
||||
dbw_query($db_conn,"INSERT INTO USERS (`Name`,`Password`,`Email`,`PE_admin`) VALUES('$adminname','x','$adminmail',1)");
|
||||
$id_u = dbw_last_id($db_conn);
|
||||
$password = hash("sha256",$id_u.$adminpass); //Password with salt (id_u)
|
||||
dbw_query($db_conn,"UPDATE USERS SET `Password`='$password' WHERE ID_U='$id_u'");
|
||||
//Create config file
|
||||
$configfile = "<?php
|
||||
define('ENCPASSWD','".RandomString(12)."');
|
||||
define('SGBD','mysqli');
|
||||
define('DBSERVER','".$dbhost."');
|
||||
define('DBUSER','".$dbuser."');
|
||||
define('DBPASS','".$dbpass."');
|
||||
define('DBDATABASE','".$dbdata."');
|
||||
define('DEBUG',false); ?>";
|
||||
file_put_contents(dirname(__FILE__).'/config/config.php', $configfile);
|
||||
|
||||
header("location: index.php");
|
||||
die("<p>Instalado. Dirigiéndote al <a href='index.php'>login</a>, gracias por usar CheckServer</p>");
|
||||
}else{
|
||||
renderPage('install.twig');
|
||||
}
|
||||
Reference in New Issue
Block a user