-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
110 lines (91 loc) · 3.27 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
// To generate favicon pack: http://realfavicongenerator.net/
define('ROOT_PATH', dirname(__FILE__));
define('ROOT_URL', rtrim(dirname($_SERVER['PHP_SELF']), '\\\/'));
ini_set('session.gc_maxlifetime', 3600);
session_set_cookie_params(3600);
session_start();
$page_title = 'Nikagi';
$page_class = '';
$page_button_back = false;
$page_button_admin = true;
$page_button_help = true;
$config = parse_ini_file(ROOT_PATH . '/config/config.ini');
if ( !isset($config['username']) || empty($config['username'])
|| !isset($config['password']) || empty($config['password'])
|| !isset($config['length']) || !preg_match('/^\d+$/', $config['length'])
|| !isset($config['lowercases']) || !in_array($config['lowercases'], array("0", "1"))
|| !isset($config['uppercases']) || !in_array($config['uppercases'], array("0", "1"))
|| !isset($config['digits']) || !in_array($config['digits'], array("0", "1"))
|| !isset($config['symbols']) || !in_array($config['symbols'], array("0", "1"))
) {
// Launch Nikagi installation
include ROOT_PATH . '/pages/install.php';
} else {
define('ADMIN_USERNAME', $config['username']);
define('ADMIN_PASSWORD', $config['password']);
define('DEFAULT_LENGTH', $config['length']);
define('DEFAULT_LOWERCASES', (bool)$config['lowercases']);
define('DEFAULT_UPPERCASES', (bool)$config['uppercases']);
define('DEFAULT_DIGITS', (bool)$config['digits']);
define('DEFAULT_SYMBOLS', (bool)$config['symbols']);
if (isset($_GET['admin'])) {
checkLogin();
include ROOT_PATH . '/pages/admin.php';
} elseif (isset($_GET['add'])) {
checkLogin();
include ROOT_PATH . '/pages/add.php';
} elseif (isset($_GET['delete'])) {
checkLogin();
include ROOT_PATH . '/pages/delete.php';
} elseif (isset($_GET['login'])) {
include ROOT_PATH . '/pages/login.php';
} else {
include ROOT_PATH . '/pages/generate.php';
session_destroy();
}
}
function checkLogin() {
if (!isset($_SESSION['logged'])) {
header('location:'. ROOT_URL .'/?login');
die;
}
}
function writeINI($assoc_arr, $path, $has_sections = false) {
$content = "";
if ($has_sections) {
foreach ($assoc_arr as $key=>$elem) {
$content .= "[".$key."]\n";
foreach ($elem as $key2=>$elem2) {
if(is_array($elem2))
{
for($i=0;$i<count($elem2);$i++)
{
$content .= $key2."[] = \"".$elem2[$i]."\"\n";
}
}
else if($elem2=="") $content .= $key2." = \n";
else $content .= $key2." = \"".$elem2."\"\n";
}
}
}
else {
foreach ($assoc_arr as $key=>$elem) {
if(is_array($elem))
{
for($i=0;$i<count($elem);$i++)
{
$content .= $key."[] = \"".$elem[$i]."\"\n";
}
}
else if($elem=="") $content .= $key." = \n";
else $content .= $key." = \"".$elem."\"\n";
}
}
if (!$handle = fopen($path, 'w')) {
return false;
}
$success = fwrite($handle, $content);
fclose($handle);
return $success;
}