-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.php
114 lines (100 loc) · 3.73 KB
/
install.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
111
112
113
114
<?php
/**
* created by: Yuval Leshem
* http://simplegalleryma.sourceforge.net/
**/
// see if script already ran, and we have config.php file
switch($_SERVER['REQUEST_METHOD'])
{
// install script is running...
case 'POST':
$config = array();
// get form data
$config["db_host"] = $_POST['dbhost'];
$config["db_user"] = $_POST['dbuser'];
$config["db_pwd"] = $_POST['dbpass'];
$config["database"] = $_POST['dbname'];
// get domain and directory (For cookie configuration)
$config["domain"] = $_SERVER['SERVER_NAME'];
// connect to database
if (!mysql_connect($config[db_host], $config[db_user], $config[db_pwd]))
die("Can't connect to database" . mysql_error());
if (!mysql_select_db($config["database"]))
die("Can't select database" . mysql_error());
// run database installation script
$f = fopen("db.sql","r+");
$sqlFile = fread($f,filesize("db.sql"));
$sqlArray = explode(';',$sqlFile);
fclose($f);
foreach ($sqlArray as $stmt) {
if (strlen($stmt)>3){
if (!mysql_query($stmt)){
die("problem installing database, " . mysql_error());
}
}
}
// install admin user
$user = $_POST['user'];
$password = $_POST['pass'];
$usersql = "INSERT INTO `users` VALUES (1, '" . $user . "', '" . md5($password) . "')";
if (!mysql_query($usersql)) {
die("problem inserting admin user into database, " . mysql_error());
}
// write config.php
$config_file = fopen("config.php", "w");
fwrite($config_file, "<?php\n// This file was generated by the installation script\n");
foreach ($config as $key => $value) {
fwrite($config_file, "$" . $key . "='" . $value . "';\n");
}
fwrite($config_file, "?>");
fclose($config_file);
// finally, delete (unlink) installation file, otherwise we're not safe :(
unlink('install.php');
echo "<html><head><title>Installation done</title></head><body>";
echo "Installation successful!<br/>";
echo "Admin username = " . $user . "<br/>";
echo "Admin password = " . $password . "<br/>";
echo "<a href='index.php'>Go to gallery administration</a>";
echo "</body></html>";
break;
// initializing. display installation form
case 'GET':
?>
<!doctype html>
<html>
<head>
<title>Simple Gallery Installation script</title>
<link rel='stylesheet' type='text/css' href='css/install.css'>
</head>
<body>
<a href="http://simplegalleryma.sourceforge.net/">Simple Gallery @Sourceforge</a>
<h1>Simple Gallery Installation</h1>
<h2>Please enter the following information:</h2><br/>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<label for="dbhost">mysql host name:</label><br>
<textarea class='tarea' name="dbhost" id="dbhost" rows="1" cols="50" >localhost</textarea>
<br>
<label for="dbname">mysql database name:</label><br>
<textarea class='tarea' name="dbname" id="dbname" rows="1" cols="50" >db_galleries</textarea>
<br>
<label for="dbuser">mysql user name:</label><br>
<textarea class='tarea' name="dbuser" id="dbuser" rows="1" cols="50" >myuser</textarea>
<br>
<label for="dbpass">mysql user password:</label><br>
<input class='tarea' type="password" name="dbpass" id="dbpass" value="mypass" size="50" />
<br>
<label for="user">Admin user name:</label><br>
<textarea class='tarea' name="user" id="user" rows="1" cols="50">admin</textarea>
<br>
<label for="user">Admin user password:</label><br>
<input class='tarea' type="password" name="pass" id="pass" value="admin" size="50" />
<br>
<input class='nbutton' type="submit"/>
</form>
</body>
</html>
<?php
break;
}
?>