OpenSencillo  2016.106
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
core_installer.php
1 <?php
11 error_reporting(E_ERROR|E_PARSE);
13 {
14  public function __construct($DBHost=null,$DBName=null,$DBUser=null,$DBPass=null)
15  {
16  if(!empty($DBHost))
17  {
18  $this->DBHost = $DBHost;
19  $this->DBName = $DBName;
20  $this->DBUser = $DBUser;
21  $this->DBPass = $DBPass;
22 
23  if(($this->DBHost!='')&&($this->DBUser!='')&&($this->DBPass!='')&&($this->DBName!=''))
24  {
25  $this->checksum=md5($this->DBHost.$this->DBUser.$this->DBPass.$this->DBName);
26  }
27  $this->con = mysql_connect($this->DBHost, $this->DBUser, $this->DBPass);
28  if(! $this->con)
29  {
30  die("<b>core_installer: MySQL connection failed!</b> ".mysql_error());
31  }
32  mysql_select_db($this->DBName, $this->con);
33  }
34  }
35 }
36 
37 $ini = parse_ini_file('../fw_headers/install.ini',true);
38 foreach($ini['bootstrap_paths']['require'] as $val)
39 {
40  require_once("$val");
41 }
42 
43 $inc=new library;
44 $inc->install($ini['extensions']['ignored']);
45 $paths = $inc->installerPath();
46 $realPath = array();
47 foreach($paths as $val)
48 {
49  if(file_exists($val))
50  {
51  require_once("$val");
52  $realPath[] = $val;
53  }
54 }
55 unset($paths);
56 
57 $i=0;
58 $afterBootUp=array();
59 $afterBootUp[$i++]=new coreSencillo;
60 $seo=new headerSeo;
61 $seo->encode();
62 $seo->title($afterBootUp[0]->info['FWK'].' - '.$ini['installer']['name']);
63 $seo->owner($ini['installer']['author']);
64 $seo->bootstrapDefs();
65 $seo->save();
66 echo $seo->seo;
67 $PHPversion=explode(".",phpversion());
68 if(($_GET['install']==$ini['installer']['initialize'])&&((floatval($PHPversion[0].'.'.$PHPversion[1]))>=floatval($ini['installer']['minimalphp'])))
69 {
70  chmod("../fw_headers/", 0777);
71  if((($_POST['host']!="")&&($_POST['user']!="")&&($_POST['name']!="")&&($_POST['pass']!=""))||((defined('DB_USER'))&&(defined('DB_NAME'))&&(defined('DB_PASS'))&&(defined('DB_HOST'))))
72  {
73  $hash = md5($_SERVER['SERVER_NAME'].$_SERVER['SERVER_ADDR'].$_POST['host'].$_POST['user'].$_POST['type']);
74  $mysqlTest = new testingMysql((isset($_POST['host'])?$_POST['host']:DB_HOST),(isset($_POST['name'])?$_POST['name']:DB_NAME),(isset($_POST['user'])?$_POST['user']:DB_USER),(isset($_POST['pass'])?$_POST['pass']:DB_PASS));
75  $file = new fileSystem($ini['new_file_paths']['mysqlconfig']);
76  $file->write('<?php
77 /*~ mysql-config.php
78 .---------------------------------------------------------------------------.
79 | Software: '.$afterBootUp[0]->info['NME'].' SQL Config |
80 | Version: '.$afterBootUp[0]->info['VSN'].' |
81 | Contact: mail@phorvath.com |
82 | ------------------------------------------------------------------------- |
83 | Author: Bc. Peter Horváth (original founder) |
84 | Copyright (c) 2011-'.date("Y").', Bc. Peter Horváth. All Rights Reserved. |
85 | ------------------------------------------------------------------------- |
86 | License: Distributed under the General Public License (GPL) |
87 | http://www.gnu.org/licenses/gpl-3.0.html |
88 | This program is distributed in the hope that it will be useful - WITHOUT |
89 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
90 | FITNESS FOR A PARTICULAR PURPOSE. |
91 ´---------------------------------------------------------------------------´
92 ~*/
93 //changable settings
94 class database
95 {
96  const host = "'.(isset($_POST['host'])?$_POST['host']:DB_HOST).'";
97  const name = "'.(isset($_POST['name'])?$_POST['name']:DB_NAME).'";
98  const user = "'.(isset($_POST['user'])?$_POST['user']:DB_USER).'";
99  const pass = "'.(isset($_POST['pass'])?$_POST['pass']:DB_PASS).'";
100  const type = "'.(isset($_POST['type'])?$_POST['type']:"sams").'";
101  const hash = "'.$hash.'";
102  const cache= "'.(isset($_POST['cache'])?$_POST['cache']:"0").'";
103 }
104 //depecrated variables
105 //DB Server
106 $DBHost = database::host;
107 //SQL access
108 $DBUser = database::user;
109 $DBName = database::name;
110 $DBPass = database::pass;
111 //SQL type
112 $DBType = database::type;
113 //Hash
114 define("SENCILLO_CONFIG",database::hash);
115 //Cache
116 $QUICKCACHE_ON = database::cache;
117 ?>');
118  }
119  chmod("../", 0777);
120  if(!file_exists($ini['new_file_paths']['yourcode']))
121  {
122  $file = new fileSystem($ini['new_file_paths']['yourcode']);
123 
124  $file->write('<?php
125  $seo = new headerSeo;
126  $seo->encode();
127  $seo->title($core->coreSencillo->info["FWK"]." - Example page");
128  $seo->owner("'.$_POST['user-new-name'].', '.$_POST['user-new-mail'].'");
129  $seo->bootstrapDefs();
130  echo $seo->save();
131 
132  $translate = new translate("translate.json","en");
133  require_once("./fw_templates/system/welcome.default.screen.php");
134 ?>');
135 
136  $file = new fileSystem($ini['new_file_paths']['firststart']);
137  $json = json_encode(array( 'time'=>date("H:i:s"),
138  'date'=>date("Y-m-d"),
139  'email'=>$_POST['user-new-mail'],
140  'PHP' =>phpversion(),
141  'SYSTEM'=>$afterBootUp[0]->info['FWK'],
142  'hash'=>$hash
143  ));
144  $file->write($json);
145  }
146  if(!defined('DB_USER'))
147  {
148  foreach($ini['htaccess']['cache'] as $key=>$val)
149  {
150  $expiresbytype.='ExpiresByType '.$val.' "access plus '.$ini['htaccess']['cache_size'].' '.$ini['htaccess']['cache_unit'].'"'.PHP_EOL;
151  }
152  if($ini['htaccess']['protocol']=="http")
153  {
154  $protocolinhtaccess='# HTTPS to HTTP
155 <IfModule mod_rewrite.c>
156  RewriteCond %{SERVER_PORT} ^443$
157  RewriteCond %{HTTPS} =on
158  RewriteRule ^(.*)$ http://'.$_SERVER['SERVER_NAME'].'/$1 [L,R=301]
159 </IfModule>';
160  }
161  else
162  {
163  $protocolinhtaccess='# HTTP to HTTPS
164 <IfModule mod_rewrite.c>
165  RewriteCond %{SERVER_PORT} !^443$
166  RewriteCond %{HTTPS} off
167  RewriteRule ^(.*)$ https://'.$_SERVER['SERVER_NAME'].'/$1 [R=301,L]
168 </IfModule>';
169  }
170  $file = new fileSystem($ini['new_file_paths']['htaccess']);
171  $file->write('# Create with '.$afterBootUp[0]->info['FWK'].'.
172 # Secure ini files
173 <Files ~ "\.ini">
174 Order allow,deny
175 Deny from all
176 </Files>
177 
178 # Image cache
179 <IfModule mod_expires.c>
180  ExpiresActive on
181  '.$expiresbytype.'
182 </IfModule>
183 
184 '.$protocolinhtaccess.'
185 
186 # Rewrite URLs
187 <IfModule mod_rewrite.c>
188  RewriteEngine on
189  RewriteBase /
190 </IfModule>
191 
192 # Pretty URLs
193 <IfModule mod_rewrite.c>
194  RewriteCond %{REQUEST_FILENAME} !-f
195  RewriteCond %{REQUEST_FILENAME} !-d
196  RewriteCond %{REQUEST_FILENAME} !-l
197  RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
198 </IfModule>
199 
200 # '.$_SERVER['SERVER_NAME'].' -> www.'.$_SERVER['SERVER_NAME'].'
201 <IfModule mod_rewrite.c>
202  RewriteCond %{HTTP_HOST} !^'.$_SERVER['SERVER_NAME'].'$ [NC]
203  RewriteRule ^(.*)$ http://'.$_SERVER['SERVER_NAME'].'/$1 [L,R=301]
204 </IfModule>');
205  }
206 
207  chmod("../fw_core/", 0700);
208  chmod("../fw_cache/", 0700);
209  chmod("../fw_headers/", 0700);
210  chmod("../fw_modules/", 0700);
211  chmod("../fw_libraries/", 0700);
212  chmod("../fw_script/", 0700);
213  chmod("../", 0700);
214  try{
215  foreach($ini['bootstrap_middle_paths']['require'] as $val)
216  {
217  require_once("$val");
218  }
219  }catch(Exception $e){
220  echo 'ERR: '.$e->getMessage().PHP_EOL;
221  die('core_installer: Permission error - FATAL ERROR!');
222  }
223 
224 
225 
226  if(!defined('DB_USER'))
227  {
228  $delinsql='
229  SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
230  ';
231  $mysql->write($delinsql);
232  $delinsql='
233  SET time_zone = "'.$ini['sql_driver_config']['timezone'].'";
234  ';
235  $mysql->write($delinsql);
236  }
237  $delinsql='
238  CREATE TABLE IF NOT EXISTS `console` (
239  `id` bigint(20) NOT NULL AUTO_INCREMENT,
240  `time` datetime NOT NULL,
241  `title` varchar(25) NOT NULL,
242  `data` varchar(255) NOT NULL,
243  PRIMARY KEY (`id`)
244  ) ENGINE=MEMORY DEFAULT CHARSET=utf8 MAX_ROWS='.$ini['sql_driver_config']['consolesize'].' AUTO_INCREMENT=0;
245  ';
246  $mysql->write($delinsql);
247 
248  $delinsql='
249  CREATE TABLE IF NOT EXISTS `country` (
250  `id` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
251  `id2` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
252  `name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
253  PRIMARY KEY (`id`)
254  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
255  ';
256  $mysql->write($delinsql);
257  $clist = new clist;
258  $clist = $clist->countryList();
259 
260  $delinsql='
261  CREATE TABLE IF NOT EXISTS `login` (
262  `id` bigint(20) NOT NULL AUTO_INCREMENT,
263  `userid` bigint(20) NOT NULL,
264  `sessionid` longtext NOT NULL,
265  `expiration` int(11) NOT NULL,
266  `perm` int(11) NOT NULL,
267  PRIMARY KEY (`id`)
268  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;
269  ';
270  $mysql->write($delinsql);
271 
272  $delinsql='
273  CREATE TABLE sencillo_cache (
274  CACHEKEY varchar(255) NOT NULL,
275  CACHEEXPIRATION int(11) NOT NULL,
276  GZDATA blob,
277  DATASIZE int(11),
278  DATACRC int(11),
279  PRIMARY KEY (CACHEKEY)
280  );
281  ';
282  $mysql->write($delinsql);
283 
284  $delinsql='
285  CREATE TABLE IF NOT EXISTS `virtual_system_config` (
286  `id` int(11) NOT NULL AUTO_INCREMENT,
287  `function` varchar(25) NOT NULL,
288  `command` varchar(25) NOT NULL,
289  `commander` int(11) NOT NULL,
290  PRIMARY KEY (`id`)
291  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
292  ';
293  $mysql->write($delinsql);
294  $mysql->close();
295 
296  $logman=new logMan;
297  $mysql=new mysqlInterface;
298  $mysql->config();
299  $mysql->connect();
300  foreach($clist as $key=>$val)
301  {
302  $delinsql=array(
303  'country'=>array(
304  'id'=>$key,
305  'id2'=>'',
306  'name'=>$val
307  ));
308  $mysql->insert($delinsql);
309  }
310 
311  if(!defined('DB_USER'))
312  {
313  $delinsql=array(
314  'virtual_system_config'=>array(
315  'id'=>"''",
316  'function'=>'superuser',
317  'command'=>$_POST['user-new-name'],
318  'commander'=>0
319  ));
320  $mysql->insert($delinsql);
321 
322  $delinsql=array(
323  'virtual_system_config'=>array(
324  'id'=>"''",
325  'function'=>'superpass',
326  'command'=>md5($_POST['user-new-pass']),
327  'commander'=>0
328  ));
329  $mysql->insert($delinsql);
330 
331  $delinsql=array(
332  'virtual_system_config'=>array(
333  'id'=>"''",
334  'function'=>'supermail',
335  'command'=>$_POST['user-new-mail'],
336  'commander'=>0
337  ));
338  $mysql->insert($delinsql);
339 
340  $delinsql=array(
341  'virtual_system_config'=>array(
342  'id'=>"''",
343  'function'=>'systemhash',
344  'command'=>$hash,
345  'commander'=>0
346  ));
347  $mysql->insert($delinsql);
348 
349  $delinsql=array(
350  'virtual_system_config'=>array(
351  'id'=>"''",
352  'function'=>'servername',
353  'command'=>$_SERVER['SERVER_NAME'],
354  'commander'=>0
355  ));
356  $mysql->insert($delinsql);
357 
358  $delinsql=array(
359  'virtual_system_config'=>array(
360  'id'=>"''",
361  'function'=>'htaccess_config',
362  'command'=>'default',
363  'commander'=>0
364  ));
365  $mysql->insert($delinsql);
366  }
367  else
368  {
369  $delinsql=array(
370  'virtual_system_config'=>array(
371  'id'=>"''",
372  'function'=>'htaccess_config',
373  'command'=>'sams',
374  'commander'=>0
375  ));
376  $mysql->insert($delinsql);
377  }
378  $mysql->execute();
379 
380  $delinsql=array(
381  'virtual_system_config'=>array(
382  'id'=>"''",
383  'function'=>'phpversion',
384  'command'=>phpversion(),
385  'commander'=>0
386  ));
387  $mysql->insert($delinsql);
388  $mysql->execute();
389 
390  $dir = '../fw_libraries';
391  $scan = array_diff(scandir($dir),array('..', '.'));
392  $json = json_encode($scan);
393  $hash = md5($json);
394  foreach($scan as $key=>$val)
395  {
396  $delinsql=array(
397  'virtual_system_config'=>array(
398  'id'=>"''",
399  'function'=>"lib:$key",
400  'command'=>"$val",
401  'commander'=>0
402  ));
403  $mysql->insert($delinsql);
404  }
405  $mysql->execute();
406 
407  $delinsql=array(
408  'virtual_system_config'=>array(
409  'id'=>"''",
410  'function'=>"lib_count",
411  'command'=>sizeof($scan),
412  'commander'=>0
413  ));
414  $mysql->insert($delinsql);
415  $mysql->execute();
416 
417  $delinsql=array(
418  'users'=>array(
419  'id'=>"''",
420  'sign'=>"'first_use'",
421  'active'=>0,
422  'login'=>"'".$_POST['user-new-name']."'",
423  'pass'=>"'".md5($_POST['user-new-pass'])."'",
424  'email'=>"'".$_POST['user-new-mail']."'",
425  'fname'=>"''",
426  'lname'=>"''",
427  'perm'=>1111,
428  'ip'=>"'".$_SERVER['REMOTE_ADDR']."'",
429  'agent'=>"'".$_SERVER['HTTP_USER_AGENT']."'",
430  'date'=>'DATE(NOW())',
431  'time'=>'TIME(NOW())',
432  ));
433  $mysql->insert($delinsql,false);
434  $mysql->execute();
435 }
436 foreach($ini['bootstrap_end_paths']['require'] as $val)
437 {
438  require_once("$val");
439 }
440 ?>