Browse Source

Improving the installation process

Victor De la Rocha 15 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,16 +29,8 @@
29 29
 					<fieldset class="install">
30 30
 						<legend class="install">Database Settings</legend>
31 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 34
 						</ul>
43 35
 					</fieldset><br  />
44 36
 					<fieldset class="install">

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

@@ -9,44 +9,36 @@ class Install {
9 9
 	var $errors_d = array();
10 10
 
11 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 22
     function run() {
25
-
26 23
     	if (empty($this->data)) false;
27
-
28 24
     	$this->create_db();
29
-
30 25
     	if (!$this->install_db()) return false;
31
-
32 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 37
 			$link = mysql_close($link);
45 38
 			return false;
46
-		}
47
-
39
+		}

48 40
 		return true;
49
-    }
41
+	}
50 42
 
51 43
 	function install_db(){
52 44
 		require_once(Absolute_Path.'config.php');
@@ -191,7 +183,6 @@ class Install {
191 183
 	}
192 184
 
193 185
 	function check_form(){
194
-
195 186
 		$action="";
196 187
 
197 188
 		if (isset($this->data['action'])){
@@ -207,14 +198,14 @@ class Install {
207 198
 				$sep_err="";
208 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 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 207
 					$sep_err="|";
217
-				}
208
+				}
218 209
 				if (!$this->data['password']) {
219 210
 					$this->errors=$this->errors.$sep_err."2";
220 211
 					$sep_err="|";
@@ -227,42 +218,28 @@ class Install {
227 218
 					$this->errors=$this->errors.$sep_err."5";
228 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 221
 				if ($this->data['password']!=$_POST['password2']) {
239 222
 					$this->errors=$this->errors.$sep_err."3";
240 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 226
 				$off_r= split("," , $this->data['time_offsets']);
248 227
 				$this->data['offset_time'] = $off_r[0];
249 228
 				$this->data['offset_city'] = $off_r[1];
250 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 233
 						$this->showForm=false;
256
-					} else {
234
+					else{
257 235
 						$this->errors=$this->errors.$sep_err."6";
258 236
 						$sep_err="|";
259 237
 						$this->showForm=true;
260 238
 					}
261
-				} else {
239
+				}else
262 240
 					$this->showForm=true;
263
-				}
264 241
 			}
265 242
 		}
266 243
 	}
267 244
 }
268
-?>
245
+?>

+ 10 - 6
install.php View File

@@ -27,24 +27,28 @@ if($install->is_gelato_installed()){
27 27
 	header("location: index.php");
28 28
 	exit;
29 29
 }
30
-$install->data = $_POST;
30
+$install->data = $_POST;
31
+
31 32
 $install->check_form();
32 33
 $theme = new themes;
33 34
 $theme->set('version',util::version());
34 35
 $theme->set('showForm',$install->showForm);
35
-
36
+
37
+#db_password
38
+#db_password2
36 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 42
 $theme->set('login',isset($install->data['login'])?$install->data['login']:'');
40 43
 $theme->set('email',isset($install->data['email'])?$install->data['email']:'');
41 44
 $theme->set('title',isset($install->data['title'])?$install->data['title']:'');
42 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 48
 $theme->set('themes',util::getThemes());
45 49
 
46 50
 for($c=1;$c<=10;$c++)$errores[$c] = $install->mostrarerror($c);
47 51
 $theme->set('error',$errores);
48 52
 
49 53
 $theme->display(Absolute_Path.'admin/themes/admin/install.htm');
50
-?>
54
+?>