[go: up one dir, main page]

Menu

[r29]: / install / index.php  Maximize  Restore  History

Download this file

337 lines (314 with data), 15.5 kB

  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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?php
session_start();
ob_start(); //required for plugins/filters and PDF output
require_once '../cfg/param.php'; // Config file
if(!isset($_GET["step"])) $_GET["step"] = "";
if(!isset($_GET['lang'])) $_GET['lang'] = "";
if(!isset($_POST["dbhost"])) $_POST["dbhost"] = "";
if(!isset($_POST["dbuser"])) $_POST["dbuser"] = "";
if(!isset($_POST["dbpassword"])) $_POST["dbpassword"] = "";
if(!isset($_POST["dbbase"])) $_POST["dbbase"] = "";
//Language in mc_settings
if((!isset($_SESSION['lang']))||($_SESSION['lang']=="") )
{
$_SESSION['lang']="en";
}
if($_GET['lang']!=""){$_SESSION['lang']=$_GET['lang'];}
$lang=$_SESSION['lang'];
include '../locales/'.$lang.'/locale.'.$lang.".php"; // exemple "locales/fr/locale.fr with fr as $lang variable
function print_connect_form()
{
global $locales, $cfg_host, $cfg_user, $cfg_password, $cfg_database;
echo '<form method="post" action="index.php?step=1b"><table><tr>
<td>'.$locales["Connect_host"].'</td><td><input type="text" name="dbhost" value="';
if($_POST["dbhost"]!="") echo $_POST["dbhost"]; else echo $cfg_host;
echo '"/></td></tr>
<td>'.$locales["Connect_user"].'</td><td><input type="text" name="dbuser" value="';
if($_POST["dbuser"]!="") echo $_POST["dbuser"]; else echo $cfg_user;
echo '"/></td></tr>
<td>'.$locales["Connect_pass"].'</td><td><input type="password" name="dbpassword" value="';
if($_POST["dbpassword"]!="") echo $_POST["dbpassword"]; else echo $cfg_password;
echo '"/></td></tr>
<td>'.$locales["Connect_db"].'</td><td><input type="text" name="dbbase" value="';
if($_POST["dbbase"]!="") echo $_POST["dbbase"]; else echo $cfg_database;
echo '"/></td></tr>
<td></td><td><input type="submit" name="dbsubmit" value="'.$locales["Next_step"].'"/></td></tr>';
}
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
?>
<head>
<title><?php echo $locales["Installation"]; if($_GET["step"]!="") echo " - ".$locales["Installation_step"]." : ".$_GET["step"];?></title>
</head>
<body>
<?php
echo "<h1>".$locales["Installation"]."</h1>\n";
if($_GET["step"]!="") echo "<h2>".$locales["Installation_step"]." : ".$_GET["step"]."</h2>\n";
//Language
echo '<form method="get" name="language_select" action="index.php">';
$get_keys = array_keys($_GET);
for($i=0;$i<sizeOf($get_keys);$i++)
{
if($get_keys[$i] != "lang")
echo "<input type=\"hidden\" name=\"".$get_keys[$i]."\" value=\"".$_GET[$get_keys[$i]]."\"/>";
}
echo '<select name="lang" label="'.$locales["Language"].'">';
if($fp = fopen("../locales/lc.locales","r"))
{
while (!feof($fp))
{
$ligne = fgets($fp, 4096);
if (preg_match("/^(.+):(.+)$/", $ligne, $regs)) {
echo "<option value=\"".$regs[1]."\"";
if($regs[1]==$lang) echo " selected=\"selected\"";
echo ">".$regs[2]."</option>";
}
}
fclose($fp);
}
echo '</optgroup></select><input type="submit" value="OK" style="display:none;"/></form>';
switch($_GET["step"])
{
case "1b":
if(($_POST["dbhost"]!="")&&($_POST["dbuser"]!="")&&($_POST["dbpassword"]!="")&&($_POST["dbbase"]!=""))
{
//Testing database connection
$DB_connexion = mysql_connect($_POST["dbhost"], $_POST["dbuser"], $_POST["dbpassword"]);
if (! $DB_connexion){
//problem with the connection
echo '<p>'.$locales["Connexion_error"]."</p>\n";
print_connect_form();
}
else
if(!mysql_select_db($_POST["dbbase"])){
echo '<p>'.$locales["Connexion_error"]."</p>\n";
print_connect_form();
}
//else everything is OK, saving config, and go to step 3
else
{
if($param_file_open = fopen("../cfg/param.php","r"))
{
$contenu_param_file_open = fread($param_file_open, filesize("../cfg/param.php"));
fclose($param_file_open);
$contenu_param_file_open = preg_replace('/\$'."cfg_host(.*)=(.*);(.*)/",'\$cfg_host = "'.$_POST['dbhost']."\"; //Set during install", $contenu_param_file_open);
$contenu_param_file_open = preg_replace('/\$'."cfg_user(.*)=(.*);(.*)/", "\$cfg_user = \"".$_POST["dbuser"]."\"; //Set during install", $contenu_param_file_open);
$contenu_param_file_open = preg_replace('/\$'."cfg_password(.*)=(.*);(.*)/", "\$cfg_password = \"".$_POST["dbpassword"]."\"; //Set during install", $contenu_param_file_open);
$contenu_param_file_open = preg_replace('/\$'."cfg_database(.*)=(.*);(.*)/", "\$cfg_database = \"".$_POST["dbbase"]."\"; //Set during install", $contenu_param_file_open);
if($param_file_write = fopen("../cfg/param.php","w"))
{fwrite($param_file_write, $contenu_param_file_open); fclose($param_file_write);}
}
header("Location:index.php?step=2");
}
}
else
{
echo '<p>'.$locales["Fill_all_fields"]."</p>\n";
print_connect_form();
}
break;
case "1a":
//Testing database connection
$DB_connexion = mysql_connect($cgf_host, $cfg_user, $cfg_password);
if (! $DB_connexion){
//problem with the connection
echo '<p>'.$locales["Connexion_error"]."</p>\n";
print_connect_form();
}
else if(!mysql_select_db($cfg_database)){
echo '<p>'.$locales["Connexion_error"]."</p>\n";
print_connect_form();
}
else header("Location:index.php?step=2");
break;
case "2":
// Posted data, saving and proceeding
if(isset($_POST["prefix_submit"]))
{
$traitOK = true;
if($_POST["dbprefix"]!=$cfg_table_prefix)
{
if($param_file_open = fopen("../cfg/param.php","r"))
{
$contenu_param_file_open = fread($param_file_open, filesize("../cfg/param.php"));
fclose($param_file_open);
$contenu_param_file_open = preg_replace('/\$'."cfg_table_prefix(.*)=(.*);(.*)/",'\$cfg_table_prefix = "'.$_POST['dbprefix']."\"; //Set during install", $contenu_param_file_open);
if($param_file_write = fopen("../cfg/param.php","w"))
{
if(fwrite($param_file_write, $contenu_param_file_open))
fclose($param_file_write);
else $traitOK = false;
}
else $traitOK = false;
}
else $traitOK = false;
}
if($traitOK) header("Location:index.php?step=3");
}
//nothing posted yet
echo '<form method="post"><p>'.$locales["Data_Table_prefix"].' : <input type="text" name="dbprefix" value="'.$cfg_table_prefix.'"/> <input type="submit" name="prefix_submit" value="'.$locales["Next_step"].'"/></p></form>';
break;
case "3":
// Posted data, saving and proceeding
if(isset($_POST["dblaunch"]))
{
$traitOK = true;
if($sql_file_open = fopen($_POST["install-type"],"r"))
{
$contenu_sql_file_open = fread($sql_file_open, filesize($_POST["install-type"]));
fclose($sql_file_open);
$comment_patterns = array('/\/\*.*(\n)*.*(\*\/)?/', //C comments
'/\s*--.*\n/', //inline comments start with --
'/\s*#.*\n/', //inline comments start with #
);
$contenu_sql_file_open = preg_replace($comment_patterns, "\n", $contenu_sql_file_open);
$contenu_sql_file_open = preg_replace('/mc_/', $cfg_table_prefix, $contenu_sql_file_open);
$statements = explode(";\n", $contenu_sql_file_open);
$statements = preg_replace("/\s/", ' ', $statements);
$DB_connexion = mysql_connect($cfg_host, $cfg_user, $cfg_password);
if (! $DB_connexion){
die('<p>'.$locales["Connexion_error"]."</p>\n");
}
if(!mysql_select_db($cfg_database)){
die('<p>'.$locales["Connexion_error"]."</p>\n");
}
$compteurQuery=1;
foreach ($statements as $query) {
if (trim($query) != '') {
echo '<p>'.$locales["Executing_query"].' : '.$compteurQuery++."</p>\n";
$result_requete=mysql_query($query,$DB_connexion);
if(!$result_requete)
{
echo '<p style="color : red;">'.$locales["ErrMsg_SQL"]." : ".mysql_error($DB_connexion)."</p>";
$traitOK = false;
}
else echo '<p style="color : green;">OK</p>';
}
}
}
if($traitOK)
{
echo '<form method="POST" action="index.php?step=4"><p>'.$locales["Update_finished"].' <input type="submit" name="update_finished" value="'.$locales["Next_step"].'"/></p></form>';
}
}
//nothing posted yet
else
{
echo '<form method="post"><p>'.$locales["Install_type"].' : <select name="install-type">';
if ($dh = opendir("."))
{
while (($SQLfile = readdir($dh)) !== false)
if (substr($SQLfile, strlen($SQLfile) - 4) == '.sql')
{
echo '<option value="'.$SQLfile.'">'.str_replace("_"," ",substr($SQLfile, 0,strlen($SQLfile) - 4))."</option>";
}
}
closedir($dh);
echo '</select></p>
<p>'.$locales["Launch_SQL_script"].' <input type="submit" name="dblaunch" value="'.$locales["Next_step"].'"/></p></form>';
}
break;
case "4":
// Posted data, saving and proceeding
if(isset($_POST["settings_submit"]))
{
$traitOK = true;
if(($_POST["site_title"]=="")||($_POST["site_email"]=="")||($_POST["site_author"]=="")||($_POST["admin_login"]=="")||($_POST["admin_password"]=="")||($_POST["admin_password_confirm"]=="")||($_POST["check_version_url"]=="")||($_POST["log_entries"]==""))
{
echo '<p>'.$locales["Fill_all_fields"]."</p>\n";
$traitOK = false;
}
if($traitOK)
{
if($_POST["admin_password"] != $_POST["admin_password_confirm"])
{
echo '<p>'.$locales["ErrMsg_PwDiff"]."</p>\n";
$traitOK = false;
}
}
if($traitOK)
{
$DB_connexion = mysql_connect($cfg_host, $cfg_user, $cfg_password);
if (! $DB_connexion){
die('<p>'.$locales["Connexion_error"]."</p>\n");
}
if(!mysql_select_db($cfg_database)){
die('<p>'.$locales["Connexion_error"]."</p>\n");
}
$requete_insert_admin = "INSERT INTO ".$cfg_table_prefix."users(login,password,email,level,language) VALUES ('".addslashes($_POST["admin_login"])."', MD5('".addslashes($_POST["admin_password"])."'),'".addslashes($_POST["site_email"])."', '3','".$lang."')";
$envoi_requete_insert_admin = mysql_query($requete_insert_admin,$DB_connexion);
if(!$envoi_requete_insert_admin)
{'<p>'.$locales["ErrMsg_SQL"]." : ".mysql_error($DB_connexion)."</p>\n";$traitOK = false;}
}
if($traitOK)
{
if($param_file_open = fopen("../cfg/param.php","r"))
{
$contenu_param_file_open = fread($param_file_open, filesize("../cfg/param.php"));
fclose($param_file_open);
if($_POST['site_title']!=$cfg_site_title) $contenu_param_file_open = preg_replace('/\$'."cfg_site_title(.*)=(.*);(.*)/",'\$cfg_site_title = "'.$_POST['site_title']."\"; //Set during install", $contenu_param_file_open);
if($_POST['site_email']!=$cfg_site_email) $contenu_param_file_open = preg_replace('/\$'."cfg_site_email(.*)=(.*);(.*)/",'\$cfg_site_email = "'.$_POST['site_email']."\"; //Set during install", $contenu_param_file_open);
if($_POST['site_author']!=$cfg_site_author) $contenu_param_file_open = preg_replace('/\$'."cfg_site_author(.*)=(.*);(.*)/",'\$cfg_site_author = "'.$_POST['site_author']."\"; //Set during install", $contenu_param_file_open);
if($_POST['check_version_url']!=$cfg_check_version_site) $contenu_param_file_open = preg_replace('/\$'."cfg_check_version_site(.*)=(.*);(.*)/",'\$cfg_check_version_site = "'.$_POST['check_version_url']."\"; //Set during install", $contenu_param_file_open);
if($_POST['log_entries']!=$cfg_max_log_entries) $contenu_param_file_open = preg_replace('/\$'."cfg_max_log_entries(.*)=(.*);(.*)/",'\$cfg_max_log_entries = "'.$_POST['log_entries']."\"; //Set during install", $contenu_param_file_open);
if($param_file_write = fopen("../cfg/param.php","w"))
{
if(fwrite($param_file_write, $contenu_param_file_open))
fclose($param_file_write);
else $traitOK = false;
}
else $traitOK = false;
}
else $traitOK = false;
}
if($traitOK) header("Location:index.php?step=5");
}
//nothing posted yet
if(!isset($_POST["site_title"])) $_POST["site_title"] = "";
if(!isset($_POST["site_email"])) $_POST["site_email"] = "";
if(!isset($_POST["site_author"])) $_POST["site_author"] = "";
if(!isset($_POST["admin_login"])) $_POST["admin_login"] = "";
if(!isset($_POST["check_version_url"])) $_POST["check_version_url"] = "";
if(!isset($_POST["log_entries"])) $_POST["log_entries"] = "";
echo '<form method="post"><table><tr><td>'.$locales["Site_Title"].'</td><td><input type="text" name="site_title" value="';
if($_POST["site_title"]!="") echo $_POST["site_title"]; else echo $cfg_site_title;
echo '"/></td></tr><tr><td>'.$locales["Site_email"].'</td><td><input type="text" name="site_email" value="';
if($_POST["site_email"]!="") echo $_POST["site_email"]; else echo $cfg_site_email;
echo '"/></td></tr><tr><td>'.$locales["Site_author"].'</td><td><input type="text" name="site_author" value="';
if($_POST["site_author"]!="") echo $_POST["site_author"]; else echo $cfg_site_author;
echo '"/></td></tr><tr><td>'.$locales["admin_login"].'</td><td><input type="text" name="admin_login" value="';
if($_POST["admin_login"]!="") echo $_POST["admin_login"];
echo '"/></td></tr><tr><td>'.$locales["UserPassWord"].'</td><td><input type="password" name="admin_password" value="';
echo '"/></td></tr><tr><td>'.$locales["UserConfirmPassword"].'</td><td><input type="password" name="admin_password_confirm" value="';
echo '"/></td></tr><tr><td>'.$locales["Site_check_version"].'</td><td><input type="text" name="check_version_url" value="';
if($_POST["check_version_url"]!="") echo $_POST["check_version_url"]; else echo $cfg_check_version_site;
echo '"/></td></tr><tr><td>'.$locales["Site_log_entries"].'</td><td><input type="text" name="log_entries" value="';
if($_POST["log_entries"]!="") echo $_POST["log_entries"]; else echo $cfg_max_log_entries;
echo '"/></td></tr><tr><td></td><td><input type="submit" name="settings_submit" value="'.$locales["Next_step"].'"/></td</tr></table></form>';
break;
case "5":
if(isset($_POST["install_finished"]))
{
if ($dh = opendir("."))
{
while (($file = readdir($dh)) !== false)
unlink($file);
}
closedir($dh);
rmdir(".");
header("Location:../index.php");
}
echo '<form method="POST"><p>'.$locales["Install_finished"].' <input type="submit" name="install_finished" value="'.$locales["Next_step"].'"/></p></form>';
break;
case "":
if(($cfg_host=="")||($cfg_user=="")||($cfg_password=="")||($cfg_database==""))
{
echo '<h2>'.$locales["Connect_param"]."</h2>\n";
print_connect_form();
}
else header("Location:index.php?step=1a");
break;
}
ob_end_flush();
?>
</body>
</html>