<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once '../engine.php';
require_once INC. 'incCSS.html';
require_once INC. 'incJS.html';
if (file_exists(INSTALL. 'lock')) {
echo '<script>window.location.href = "/index.php"</script>';
}
if (isset($_POST['dbhost']) && isset($_POST['dbuser']) && isset($_POST['dbpass']) && isset($_POST['dbname']) && isset($_POST['user']) && isset($_POST['email']) && isset($_POST['pass']) && isset($_POST['pass1'])) {
$dbhost = filter_input(INPUT_POST, 'dbhost', FILTER_SANITIZE_STRING);
$dbuser = filter_input(INPUT_POST, 'dbuser', FILTER_SANITIZE_STRING);
$dbpass = filter_input(INPUT_POST, 'dbpass', FILTER_SANITIZE_STRING);
$dbname = filter_input(INPUT_POST, 'dbname', FILTER_SANITIZE_STRING);
$content1 = '<?php';
$content2 = '$db_host = "'.$dbhost.'";';
$content3 = '$db_user = "'.$dbuser.'";';
$content4 = '$db_pass = "'.$dbpass.'";';
$content5 = '$db_name = "'.$dbname.'";';
$user = filter_input(INPUT_POST, 'user', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
$pass = filter_input(INPUT_POST, 'pass', FILTER_SANITIZE_STRING);
$pass1 = filter_input(INPUT_POST, 'pass1', FILTER_SANITIZE_STRING);
if (file_exists(INC.'dbcfg.php')) {
require_once PAGES. 'database.php';
} else {
$file = fopen(INC."dbcfg.php", "a");
fwrite($file, $content1);
fwrite($file, "\n");
fwrite($file, $content2);
fwrite($file, "\n");
fwrite($file, $content3);
fwrite($file, "\n");
fwrite($file, $content4);
fwrite($file, "\n");
fwrite($file, $content5);
fwrite($file, "\n");
fclose($file);
require_once PAGES. 'database.php';
}
//Sprawdzenie długości nicka
if ((strlen($user)<3) || (strlen($user)>20)) {
$reg_ok = false;
$_SESSION['register_error'] = "Twój login musi posiadać od 3 do 20 znaków !";
echo '<script>window.location.href = "/install/install.php"</script>';
}
//Sprawdź poprawność nick'a
if (ctype_alnum($user) == false) {
$reg_ok = false;
$_SESSION['register_error'] = "Twój login musi się składać tylko z liter i cyfr bez polskich znaków !";
echo '<script>window.location.href = "/install/install.php"</script>';
}
// Sprawdź poprawność adresu email
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
if (empty($email)) {
$reg_ok = false;
$_SESSION['register_error'] = "Twój email nie jest poprawny !";
echo '<script>window.location.href = "/install/install.php"</script>';
}
//Sprawdzenie długości hasła
if ((strlen($pass)<8) || (strlen($pass)>20)) {
$reg_ok = false;
$_SESSION['register_error']="Hasło musi posiadać od 8 do 20 znaków!";
echo '<script>window.location.href = "/install/install.php"</script>';
}
//Sprawdź poprawność hasła
if ($pass != $pass1) {
$reg_ok = false;
$_SESSION['register_error'] = "Podane hasła różnią się !";
echo '<script>window.location.href = "/install/install.php"</script>';
}
if ($reg_ok == true) {
$sql1 = "CREATE TABLE `_news` (
`nid` int(11) NOT NULL,
`title` text NOT NULL,
`body` varchar(128) NOT NULL,
`author` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
$sql2 = "CREATE TABLE `_users` (
`uid` int(11) NOT NULL,
`created` date NOT NULL,
`name` text NOT NULL,
`password` varchar(128) NOT NULL,
`email` varchar(32) NOT NULL,
`gid` int(11) NOT NULL,
`avatar` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
$sql3 = "ALTER TABLE `_news`
ADD PRIMARY KEY (`nid`);ALTER TABLE `_users`
ADD PRIMARY KEY (`uid`);ALTER TABLE `_news`
MODIFY `nid` int(11) NOT NULL AUTO_INCREMENT;ALTER TABLE `_users`
MODIFY `uid` int(11) NOT NULL AUTO_INCREMENT;";
try {
$stmt = $dbh->prepare($sql1);
$stmt->execute();
$stmt = $dbh->prepare($sql2);
$stmt->execute();
$stmt = $dbh->prepare($sql3);
$stmt->execute();
$pass_hash = password_hash($pass, PASSWORD_DEFAULT);
$lock = fopen('lock', "a");
$txt = 'lock';
fwrite($lock, $txt);
fclose($lock);
} catch (PDOException $error) {
exit($error->getMessage());
}
}
}
?>