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