Browse Source

Improving the installation process

Victor De la Rocha 16 years ago
parent
commit
ba02d0840f
3 changed files with 40 additions and 67 deletions
  1. 2 10
      admin/themes/admin/install.htm
  2. 28 51
      classes/install.class.php
  3. 10 6
      install.php

+ 2 - 10
admin/themes/admin/install.htm View File

29
 					<fieldset class="install">
29
 					<fieldset class="install">
30
 						<legend class="install">Database Settings</legend>
30
 						<legend class="install">Database Settings</legend>
31
 						<ul>
31
 						<ul>
32
-							<li><label for="login">User:</label>
33
-								<input type="text" name="db_login" id="db_login" value="{db_login}" class="txt"/>{error.10}</li>
34
-							<li><label for="password">Password:</label>
35
-								<input type="password" name="db_password" id="db_password" value="" class="txt"/></li>
36
-							<li><label for="password2">Re-type password:</label>
37
-								<input type="password" name="db_password2" id="db_password2" value="" class="txt"/>{error.9}</li>
38
-							<li><label for="email">Database Host:</label>
39
-								<input type="text" name="db_host" id="db_host" value="{db_host}" class="txt"/>{error.7}</li>
40
-							<li><label for="email">Database Name:</label>
41
-								<input type="text" name="db_name" id="db_name" value="{db_name}" class="txt"/>{error.8}</li>
32
+							<li><label for="login">Are you the admin? please write the database name User</label>
33
+								<input type="text" name="db_login" id="db_login" value="{db_login}" class="txt"/>{error.9}</li>
42
 						</ul>
34
 						</ul>
43
 					</fieldset><br  />
35
 					</fieldset><br  />
44
 					<fieldset class="install">
36
 					<fieldset class="install">

+ 28 - 51
classes/install.class.php View File

9
 	var $errors_d = array();
9
 	var $errors_d = array();
10
 
10
 
11
 	function Install(){
11
 	function Install(){
12
-		$this->errors_d[1]="The login field cannot be empty";
13
-		$this->errors_d[2]="The password field cannot be empty";
14
-		$this->errors_d[3]="Password does not match the confirm password";
15
-		$this->errors_d[4]="The e-mail field cannot be empty";
16
-		$this->errors_d[5]="The installation URL field cannot be empty";
17
-		$this->errors_d[6]="Error establishing a database connection";
18
-		$this->errors_d[7]="Please add a hostname for the database server";
19
-		$this->errors_d[8]="Please name the database";
20
-		$this->errors_d[9]="Password does not match the confirm password";
21
-		$this->errors_d[10]="The login field cannot be empty";
12
+		$this->errors_d[1]='The login field cannot be empty';
13
+		$this->errors_d[2]='The password field cannot be empty';
14
+		$this->errors_d[3]='Password does not match the confirm password';
15
+		$this->errors_d[4]='The e-mail field cannot be empty';
16
+		$this->errors_d[5]='The installation URL field cannot be empty';
17
+		$this->errors_d[6]='Error establishing a database connection';
18
+		$this->errors_d[9]='For security reasons this field is required. It is the same information that in the config.php file';
19
+		$this->errors_d[10]='The login field cannot be empty';
22
 	}
20
 	}
23
 
21
 
24
     function run() {
22
     function run() {
25
-
26
     	if (empty($this->data)) false;
23
     	if (empty($this->data)) false;
27
-
28
     	$this->create_db();
24
     	$this->create_db();
29
-
30
     	if (!$this->install_db()) return false;
25
     	if (!$this->install_db()) return false;
31
-
32
 		return true;
26
 		return true;
33
     }
27
     }
34
 
28
 
35
-    function create_db(){
36
-
37
-	    $link =  mysql_connect($this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
38
-		if (!$link) {
39
-		    die('Could not connect: ' . mysql_error());
40
-		}
29
+	function create_db(){
30
+		$link =  mysql_connect(DB_Server, DB_User, DB_Password);
31
+		if(!$link)
32
+			die('Could not connect: '.mysql_error());
33
+
34
+		$sql = 'CREATE DATABASE '.DB_name;
41
 
35
 
42
-		$sql = 'CREATE DATABASE ' . $this->data['db_name'];
43
-		if (!mysql_query($sql, $link)) {
36
+		if(!mysql_query($sql, $link)){
44
 			$link = mysql_close($link);
37
 			$link = mysql_close($link);
45
 			return false;
38
 			return false;
46
-		}
47
-
39
+		}

48
 		return true;
40
 		return true;
49
-    }
41
+	}
50
 
42
 
51
 	function install_db(){
43
 	function install_db(){
52
 		require_once(Absolute_Path.'config.php');
44
 		require_once(Absolute_Path.'config.php');
191
 	}
183
 	}
192
 
184
 
193
 	function check_form(){
185
 	function check_form(){
194
-
195
 		$action="";
186
 		$action="";
196
 
187
 
197
 		if (isset($this->data['action'])){
188
 		if (isset($this->data['action'])){
207
 				$sep_err="";
198
 				$sep_err="";
208
 				$this->errors = false;
199
 				$this->errors = false;
209
 
200
 
210
-				if (!$this->data['login']) {
211
-					$this->errors =$this->errors.$sep_err."1";
201
+				if (!isset($this->data['db_login']) or $this->data['db_login']!=DB_User) {
202
+					$this->errors =$this->errors.$sep_err."9"; //7,8
212
 					$sep_err="|";
203
 					$sep_err="|";
213
-				}
214
-				if (!$this->data['db_login']) {
215
-					$this->errors =$this->errors.$sep_err."10";
204
+				}
205
+				if (!$this->data['login']) { 
206
+					$this->errors =$this->errors.$sep_err."1";
216
 					$sep_err="|";
207
 					$sep_err="|";
217
-				}
208
+				}
218
 				if (!$this->data['password']) {
209
 				if (!$this->data['password']) {
219
 					$this->errors=$this->errors.$sep_err."2";
210
 					$this->errors=$this->errors.$sep_err."2";
220
 					$sep_err="|";
211
 					$sep_err="|";
227
 					$this->errors=$this->errors.$sep_err."5";
218
 					$this->errors=$this->errors.$sep_err."5";
228
 					$sep_err="|";
219
 					$sep_err="|";
229
 				}
220
 				}
230
-				if (!$this->data['db_host'] ) {
231
-					$this->errors=$this->errors.$sep_err."7";
232
-					$sep_err="|";
233
-				}
234
-				if (!$this->data['db_name'] ) {
235
-					$this->errors=$this->errors.$sep_err."8";
236
-					$sep_err="|";
237
-				}
238
 				if ($this->data['password']!=$_POST['password2']) {
221
 				if ($this->data['password']!=$_POST['password2']) {
239
 					$this->errors=$this->errors.$sep_err."3";
222
 					$this->errors=$this->errors.$sep_err."3";
240
 					$sep_err="|";
223
 					$sep_err="|";
241
 				}
224
 				}
242
-				if ( $_POST['db_password']!=$_POST['db_password2']) {
243
-					$this->errors=$this->errors.$sep_err."9";
244
-					$sep_err="|";
245
-				}
246
 
225
 
247
 				$off_r= split("," , $this->data['time_offsets']);
226
 				$off_r= split("," , $this->data['time_offsets']);
248
 				$this->data['offset_time'] = $off_r[0];
227
 				$this->data['offset_time'] = $off_r[0];
249
 				$this->data['offset_city'] = $off_r[1];
228
 				$this->data['offset_city'] = $off_r[1];
250
 				unset($this->data['time_offsets']);
229
 				unset($this->data['time_offsets']);
251
 
230
 
252
-				if (!$this->errors) {
253
-
254
-					if ($this->run($this->data)) {
231
+				if(!$this->errors){
232
+					if($this->run($this->data))
255
 						$this->showForm=false;
233
 						$this->showForm=false;
256
-					} else {
234
+					else{
257
 						$this->errors=$this->errors.$sep_err."6";
235
 						$this->errors=$this->errors.$sep_err."6";
258
 						$sep_err="|";
236
 						$sep_err="|";
259
 						$this->showForm=true;
237
 						$this->showForm=true;
260
 					}
238
 					}
261
-				} else {
239
+				}else
262
 					$this->showForm=true;
240
 					$this->showForm=true;
263
-				}
264
 			}
241
 			}
265
 		}
242
 		}
266
 	}
243
 	}
267
 }
244
 }
268
-?>
245
+?>

+ 10 - 6
install.php View File

27
 	header("location: index.php");
27
 	header("location: index.php");
28
 	exit;
28
 	exit;
29
 }
29
 }
30
-$install->data = $_POST;
30
+$install->data = $_POST;
31
+
31
 $install->check_form();
32
 $install->check_form();
32
 $theme = new themes;
33
 $theme = new themes;
33
 $theme->set('version',util::version());
34
 $theme->set('version',util::version());
34
 $theme->set('showForm',$install->showForm);
35
 $theme->set('showForm',$install->showForm);
35
-
36
+
37
+#db_password
38
+#db_password2
36
 $theme->set('db_login',isset($install->data['db_login'])? $install->data['db_login'] : '');
39
 $theme->set('db_login',isset($install->data['db_login'])? $install->data['db_login'] : '');
37
-$theme->set('db_host',(!empty($install->data['db_host']))? $install->data['db_host'] : 'localhost');
38
-$theme->set('db_name',(!empty($install->data['db_name']))?  $install->data['db_name'] : 'gelatocms');
40
+#$theme->set('db_host',(!empty($install->data['db_host']))? $install->data['db_host'] : 'localhost');
41
+#$theme->set('db_name',(!empty($install->data['db_name']))?  $install->data['db_name'] : 'gelatocms');
39
 $theme->set('login',isset($install->data['login'])?$install->data['login']:'');
42
 $theme->set('login',isset($install->data['login'])?$install->data['login']:'');
40
 $theme->set('email',isset($install->data['email'])?$install->data['email']:'');
43
 $theme->set('email',isset($install->data['email'])?$install->data['email']:'');
41
 $theme->set('title',isset($install->data['title'])?$install->data['title']:'');
44
 $theme->set('title',isset($install->data['title'])?$install->data['title']:'');
42
 $theme->set('description',isset($install->data['description'])?$install->data['description']:'');
45
 $theme->set('description',isset($install->data['description'])?$install->data['description']:'');
43
-$theme->set('url_installation',isset($_SERVER['SCRIPT_URI'])?substr($_SERVER["SCRIPT_URI"], 0, -12):'');
46
+
47
+$theme->set('url_installation',(isset($install->data['url_installation']) and $install->data['url_installation'])?$install->data['url_installation']:(isset($_SERVER['SCRIPT_URI'])?substr($_SERVER["SCRIPT_URI"], 0, -12):''));
44
 $theme->set('themes',util::getThemes());
48
 $theme->set('themes',util::getThemes());
45
 
49
 
46
 for($c=1;$c<=10;$c++)$errores[$c] = $install->mostrarerror($c);
50
 for($c=1;$c<=10;$c++)$errores[$c] = $install->mostrarerror($c);
47
 $theme->set('error',$errores);
51
 $theme->set('error',$errores);
48
 
52
 
49
 $theme->display(Absolute_Path.'admin/themes/admin/install.htm');
53
 $theme->display(Absolute_Path.'admin/themes/admin/install.htm');
50
-?>
54
+?>