|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Prepare reading of SQL dump file and executing SQL statements |
|
5
|
|
|
* @param $sql_dump_file |
|
6
|
|
|
*/ |
|
7
|
|
|
function apphp_db_install($sql_dump_file) { |
|
8
|
|
|
global $error_mg; |
|
9
|
|
|
global $admin_username; |
|
10
|
|
|
global $admin_password; |
|
11
|
|
|
global $database_prefix; |
|
12
|
|
|
global $password_encryption; |
|
13
|
|
|
global $db; |
|
14
|
|
|
|
|
15
|
|
|
$sql_array = array(); |
|
16
|
|
|
$query = ''; |
|
17
|
|
|
|
|
18
|
|
|
// get sql dump content |
|
19
|
|
|
$sql_dump = file($sql_dump_file); |
|
20
|
|
|
|
|
21
|
|
|
// replace database prefix if exists |
|
22
|
|
|
$sql_dump = str_ireplace('<DB_PREFIX>', $database_prefix, $sql_dump); |
|
23
|
|
|
|
|
24
|
|
|
// disabling magic quotes at runtime |
|
25
|
|
|
if(get_magic_quotes_runtime()){ |
|
26
|
|
|
function stripslashes_runtime(&$value){ |
|
27
|
|
|
$value = stripslashes($value); |
|
28
|
|
|
} |
|
29
|
|
|
array_walk_recursive($sql_dump, 'stripslashes_runtime'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
// add ';' at the end of file to catch last sql query |
|
33
|
|
|
if(substr($sql_dump[count($sql_dump)-1], -1) != ';') $sql_dump[count($sql_dump)-1] .= ';'; |
|
34
|
|
|
|
|
35
|
|
|
// replace username and password if exists |
|
36
|
|
|
if(EI_USE_ADMIN_ACCOUNT){ |
|
37
|
|
|
$sql_dump = str_ireplace('<USER_NAME>', $admin_username, $sql_dump); |
|
38
|
|
|
if(EI_USE_PASSWORD_ENCRYPTION){ |
|
39
|
|
|
if($password_encryption == 'AES'){ |
|
40
|
|
|
$sql_dump = str_ireplace('<PASSWORD>', 'AES_ENCRYPT(\''.$admin_password.'\', \''.EI_PASSWORD_ENCRYPTION_KEY.'\')', $sql_dump); |
|
41
|
|
|
}else if($password_encryption == 'MD5'){ |
|
42
|
|
|
$sql_dump = str_ireplace('<PASSWORD>', 'MD5(\''.$admin_password.'\')', $sql_dump); |
|
43
|
|
|
}else{ |
|
44
|
|
|
$sql_dump = str_ireplace('<PASSWORD>', 'AES_ENCRYPT(\''.$admin_password.'\', \''.EI_PASSWORD_ENCRYPTION_KEY.'\')', $sql_dump); |
|
45
|
|
|
} |
|
46
|
|
|
}else{ |
|
47
|
|
|
$sql_dump = str_ireplace('<PASSWORD>', '\''.$admin_password.'\'', $sql_dump); |
|
48
|
|
|
} |
|
49
|
|
|
}else{ |
|
50
|
|
|
$sql_dump = str_ireplace('<USER_NAME>', '', $sql_dump); |
|
51
|
|
|
$sql_dump = str_ireplace('<PASSWORD>', "''", $sql_dump); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// encode connection, server, client etc. |
|
55
|
|
|
if(EI_USE_ENCODING){ |
|
56
|
|
|
$db->SetEncoding(EI_DUMP_FILE_ENCODING, EI_DUMP_FILE_COLLATION); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
foreach($sql_dump as $sql_line){ |
|
60
|
|
|
$tsl = trim(utf8_decode($sql_line)); |
|
61
|
|
|
if(($sql_line != '') && (substr($tsl, 0, 2) != '--') && (substr($tsl, 0, 1) != '?') && (substr($tsl, 0, 1) != '#')){ |
|
62
|
|
|
$query .= $sql_line; |
|
63
|
|
|
if(preg_match("/;\s*$/", $sql_line)){ |
|
64
|
|
|
if(strlen(trim($query)) > 5){ |
|
65
|
|
|
if(EI_MODE == 'debug'){ |
|
66
|
|
|
if(!$db->Query($query)){ $error_mg[] = '<b>SQL</b>:'.$query.'<br /><br /><b>'.lang_key('error').'</b>:<br />'.$db->Error(); return false; } |
|
67
|
|
|
}else{ |
|
68
|
|
|
if(!@$db->Query($query)) return false; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
$query = ''; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns language key |
|
80
|
|
|
* @param $key |
|
81
|
|
|
*/ |
|
82
|
|
|
function lang_key($key){ |
|
83
|
|
|
global $arrLang; |
|
84
|
|
|
$output = ''; |
|
85
|
|
|
|
|
86
|
|
|
if(isset($arrLang[$key])){ |
|
87
|
|
|
$output = $arrLang[$key]; |
|
88
|
|
|
}else{ |
|
89
|
|
|
$output = str_replace('_', ' ', $key); |
|
90
|
|
|
} |
|
91
|
|
|
return $output; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Remove bad chars from input |
|
96
|
|
|
* @param $str_words - input |
|
97
|
|
|
**/ |
|
98
|
|
|
function prepare_input($str_words, $escape = false, $level = 'high') |
|
99
|
|
|
{ |
|
100
|
|
|
$found = false; |
|
101
|
|
|
$str_words = htmlentities(strip_tags($str_words)); |
|
102
|
|
|
if($level == 'low'){ |
|
103
|
|
|
$bad_string = array('drop', '--', 'insert', 'xp_', '%20union%20', '/*', '*/union/*', '+union+', 'load_file', 'outfile', 'document.cookie', 'onmouse', '<script', '<iframe', '<applet', '<meta', '<style', '<form', '<body', '<link', '_GLOBALS', '_REQUEST', '_GET', '_POST', 'include_path', 'prefix', 'ftp://', 'smb://', 'onmouseover=', 'onmouseout='); |
|
104
|
|
|
}else if($level == 'medium'){ |
|
105
|
|
|
$bad_string = array('select', 'drop', '--', 'insert', 'xp_', '%20union%20', '/*', '*/union/*', '+union+', 'load_file', 'outfile', 'document.cookie', 'onmouse', '<script', '<iframe', '<applet', '<meta', '<style', '<form', '<body', '<link', '_GLOBALS', '_REQUEST', '_GET', '_POST', 'include_path', 'prefix', 'ftp://', 'smb://', 'onmouseover=', 'onmouseout='); |
|
106
|
|
|
}else{ |
|
107
|
|
|
$bad_string = array('select', 'drop', '--', 'insert', 'xp_', '%20union%20', '/*', '*/union/*', '+union+', 'load_file', 'outfile', 'document.cookie', 'onmouse', '<script', '<iframe', '<applet', '<meta', '<style', '<form', '<img', '<body', '<link', '_GLOBALS', '_REQUEST', '_GET', '_POST', 'include_path', 'prefix', 'http://', 'https://', 'ftp://', 'smb://', 'onmouseover=', 'onmouseout='); |
|
108
|
|
|
} |
|
109
|
|
|
for($i = 0; $i < count($bad_string); $i++){ |
|
110
|
|
|
$str_words = str_replace($bad_string[$i], '', $str_words); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if($escape){ |
|
114
|
|
|
$str_words = encode_text($str_words); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $str_words; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Get encoded text |
|
122
|
|
|
* @param $string |
|
123
|
|
|
*/ |
|
124
|
|
|
function encode_text($string = '') |
|
125
|
|
|
{ |
|
126
|
|
|
$search = array("\\","\0","\n","\r","\x1a","'",'"',"\'",'\"'); |
|
127
|
|
|
$replace = array("\\\\","\\0","\\n","\\r","\Z","\'",'\"',"\\'",'\\"'); |
|
128
|
|
|
return str_replace($search, $replace, $string); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
function is_email($value) |
|
132
|
|
|
{ |
|
133
|
|
|
return preg_match('/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/', $value); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
function draw_side_navigation($step = 1, $draw = true) |
|
138
|
|
|
{ |
|
139
|
|
|
$steps = array( |
|
140
|
|
|
'1'=>array('url'=>'start.php', 'text'=>lang_key('start')), |
|
141
|
|
|
'2'=>array('url'=>'server_requirements.php', 'text'=>lang_key('server_requirements')), |
|
142
|
|
|
'3'=>array('url'=>'database_settings.php', 'text'=>lang_key('database_settings')), |
|
143
|
|
|
'4'=>array('url'=>'administrator_account.php', 'text'=>lang_key('administrator_account')), |
|
144
|
|
|
'5'=>array('url'=>'ready_to_install.php', 'text'=>lang_key('ready_to_install')), |
|
145
|
|
|
'6'=>array('url'=>'complete_installation.php', 'text'=>lang_key('completed')) |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
$output = '<div class="left-part">'; |
|
149
|
|
|
$output .= '<ul class="left-menu">'; |
|
150
|
|
|
foreach($steps as $key => $val){ |
|
151
|
|
|
if($step > $key){ |
|
152
|
|
|
$css_class = ' class="passed"'; |
|
153
|
|
|
$output .= '<li'.$css_class.'><a href="'.$val['url'].'">'.$val['text'].'</a></li>'; |
|
154
|
|
|
}else if($step == $key){ |
|
155
|
|
|
$css_class = ' class="current"'; |
|
156
|
|
|
$output .= '<li'.$css_class.'><label>'.$val['text'].'</label></li>'; |
|
157
|
|
|
}else{ |
|
158
|
|
|
$output .= '<li><label>'.$val['text'].'</label></li>'; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
///'.$key.'. |
|
162
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
$output .= '</ul>'; |
|
165
|
|
|
$output .= '</div>'; |
|
166
|
|
|
|
|
167
|
|
|
if($draw) echo $output; |
|
168
|
|
|
else return $output; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|