dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxInstall.class.php
Go to the documentation of this file.
1<?php
2namespace dbx\dbxSetup;
3
4
5class dbxInstall {
6
7 Public $oTPL;
8
9 public function __construct() {
10 $this->oTPL = dbx()->get_system_obj('dbxTPL');
11 }
12
13
14private function check_write_cfg() {
15return 1; // config nicht überschreiben - anders auf schreibar testen
16 $ok=0;
17 $test ='<?php'."\n".'$ok=1;'."\n?>";
18 $file_path=dbx_get_file_dir().'sys/cfg/config.php';
19 $file_path=dbx_os_path_file($file_path);
20 @file_put_contents($file_path,$test);
21 if (file_exists($file_path)) {
22 include $file_path; // $ok=1;
23 }
24 return $ok;
25}
26
27
28
29 private function install_db_config($config) {
30 return array(
31 'type' => $config['type'] ?? 'mysql',
32 'host' => $config['host'] ?? '',
33 'dbname' => $config['dbname'] ?? ($config['name'] ?? ''),
34 'user' => $config['user'] ?? '',
35 'pass' => $config['pass'] ?? ($config['password'] ?? ''),
36 'port' => $config['port'] ?? '',
37 );
38 }
39
40 private function check_db_connect($config) {
41 $db = dbx()->get_system_obj('dbxDB');
42 return is_object($db) ? $db->can_connect_database_config($this->install_db_config($config), false) : 0;
43 }
44
45
46 private function check_db_exist($config){
47 $db = dbx()->get_system_obj('dbxDB');
48 return is_object($db) ? $db->can_connect_database_config($this->install_db_config($config), true) : 0;
49 }
50
51 private function check_db_create($config) {
52 $dbConfig = $this->install_db_config($config);
53
54 $db = dbx()->get_system_obj('dbxDB');
55 return is_object($db) ? $db->ensure_database_exists('dbxInstall', $dbConfig) : 0;
56 }
57
58 private function write_cfg($config) {
59 $ok=dbx()->set_config('dbx',$config);
60 return $ok;
61 }
62
63
64
65 private function install_1() {
66
67 $content=''; $ok=false; $js='';
68 $config=dbx()->get_config('dbx');
69 $oForm =dbx()->get_system_obj('dbxForm');
70
71 $oForm->init('install-1','form-install',);
72 $oForm->_action='?dbx_modul=dbxSetup&dbx_run1=install&stepp=1';
73 $oForm->_data =$config;
74 $oForm->_fld_change_state='*'; // Importent write all flds to config
75 $oForm->_msg_info = 'Bitte geben Sie die Daten vom Datenbak Server ein.';
76 $oForm->_msg_err = 'Die Verbindung zum db-Server konnten nicht hergestellt werden';
77 $oForm->_msg_success= 'Verbindung zum db-Server ist erfolgreich';
78
79 $oForm->add_fld('host' ,'text-label' ,rules: '*|min=1',label: 'Datenbankserver' ,tooltip: 'Host Adresse der Datenbank IP oder Domain vom db-Server');
80 $oForm->add_fld('name' ,'text-label' ,rules: '*|min=1',label: 'Datenbank Name ' ,tooltip: 'Name der Datenbank');
81 $oForm->add_fld('user' ,'text-label' ,rules: '*|min=1',label: 'Benutzername Datenbank' ,tooltip: 'Benutzer Name der Datenbank');
82 $oForm->add_fld('password' ,'text-label' ,rules: '*' ,label: 'Passwort der Datenbank' ,tooltip: 'Passwort der Datenbank');
83 $oForm->add_fld('port' ,'text-label' ,label: 'Port der Datenbank' ,rules: 'int' ,data: '' ,options: 'leer=default' ,tooltip: 'Port des db-Server (leer=default)');
84
85 $oForm->add_obj('button','dbx|button-submit','label=Speichern und weiter');
86 $oForm->add_obj('progress','');
87
88 if ($oForm->submit()) {
89 $config=array_merge($config,$oForm->_post);
90 if ($oForm->errors()) {
91 dbx()->set_session_var('stepp',1,'dbxInstall');
92 }
93 if(!$oForm->errors()) { // submit && no errors
94 // 1. check write cfg
95 $ok=$this->check_write_cfg();
96 if (!$ok) $oForm->_msg_error='System Datei cfg/config.php konnte nicht erstellt werden';
97 // 2. check db connection
98 if ($ok) {
99 $host=$config['host'];
100 $name=$config['name'];
101 $db_connect= $this->check_db_connect($config);
102 if (!$db_connect) {
103 $oForm->add_fld_error('-host','!');
104 $oForm->_msg_error="System konnte keine Verbindung zum db-Server ($host) aufgebaut werden (db-Server / User / Passwort)";
105 }
106 if ($db_connect) {
107 // 3. check db exist/create
108 $db_exist=$this->check_db_exist($config);
109 if (!$db_exist) $db_exist=$this->check_db_create($config);
110 if (!$db_exist) {
111 $oForm->add_fld_error('-name','!');
112 $oForm->_msg_error="System konnte die Datenbank nicht erstellen.<br><br>Erstellen Sie bitte die auf Ihrem Datenbank-Server (<b>$host</b>) die Datenbank (<b>$name</b>) über die Administration Ihres SQL-Servers.<br><br>Das Anlegen einer Datenbank ist bei ihrem Server nur manuell möglich.<br><br>Nach dem Anlegen der Datenbank, oder Auswahl einer bestehenden Datenbank, wiederholen Sie bitte die Installation von dbXapp.";
113 }
114 }
115 if ($db_connect && $db_exist) {
116 $this->write_cfg($config);
117 return $this->install_2();
118 }
119 } // ok
120 } // !errors
121 } // submit
122 return $oForm->run();
123 } // install_1
124
125
126
127 public function install_2() {
128 //global dbxGlobalVar;
129 $content=''; $status=0;
130
131 $config =dbx()->get_config('dbx');
132 $db_exist =$this->check_db_exist($config);
133 if (!$db_exist) return $this->install_1();
134
135 $oForm=dbx()->get_system_obj('dbxForm');
136 $oForm->init('install-2','form-install',);
137 $oForm->_action='?dbx_modul=dbxSetup&dbx_run1=install&stepp=2';
138 $oForm->_data=$config;
139
140
141 $oForm->add_obj('progress',$this->oTPL->get_tpl('dbx','progressbar-1','msg=Sql Script'));
142 $oForm->add_obj('button','dbx|button-submit','label=SQL Script ausführen und Datenbank Tabellen erstellen');
143
144 $oForm->_msg_info = 'Verbindung zum Datenbankserver (' .$config['host']. ') Datenbank (' .$config['name'] .') erfolgreich hergestellt.';
145 $oForm->_msg_success = 'Verbindung zum Datenbankserver (' .$config['host']. ') Datenbank (' .$config['name'] .') Daten werden eingelesen.';
146 $oForm->_msg_err = 'Es ist ein Fehler bei der Installation aufgetreten.';
147
148 if($oForm->submit()) {
149 if(!$oForm->errors()) {
150 $install_file =dbx_get_file_dir().'sys/install/data/install.sql';
151 if (file_exists($install_file)) {
152 $oForm->_msg_success = 'Das install script ('.$install_file.') wird ausgeführt.';
153 $oImporter =dbx()->get_system_obj('dbxSQLreader');
154 $oImporter->set_property('filename',$install_file);
155 $status=$oImporter->run();
156 dbx()->debug("IMPORTER-Status=($status)");
157 if (!$status) {
158 $oForm->add_obj('import',$info.' Ein Fehler ist aufgetreten');// some error ??
159 }
160 if ($status == 1) { // continue
161
162 $filesize=$oImporter->get_property('filesize');
163 $done =$oImporter->get_property('done');
164 $percent =$oImporter->get_property('percent');
165 $querys =$oImporter->get_property('querys');
166
167 $progress=$this->oTPL->get_tpl('dbx','progressbar-1');
168 $msg="Querys=($querys) ($percent %)";
169
170 $pdata['msg'] = $msg;
171 $pdata['width'] = $percent;
172 $oForm->add_obj('progress',$progress,$pdata,'*');
173 $oForm->add_js_autosubmit('dbx_form_{i}',2);
174
175
176 }
177 if ($status == 2) { // finisch import and process data
178 $msg=$this->oTPL->get_tpl('dbx','alert-success','msg=Datenbank und Tabellen wurden erstellt');
179 $oForm->add_obj('import',$msg);
180 return $this->install_3();
181 }
182 } else {
183 $oForm->add_fld_error('x','!'); // make an error
184 $oForm->_msg_err = 'Das SQL install script ('.$install_file.') ist nicht vorhanden';
185 }
186 }
187 } // submit
188 return $oForm->run();
189 } // install_3
190
191
192
193
194
195
196
197 public function install_3() {
198 //global dbxGlobalVar;
199 $content=''; $status=0;
200
201 $config =dbx()->get_config('dbx');
202 $db_exist =$this->check_db_exist($config);
203 if (!$db_exist) return $this->install_1();
204
205
206 if (!isset($config['secure'])) $config['secure']=dbx()->new_password(32);
207 $oForm=dbx()->get_system_obj('dbxForm');
208 $oForm->init('install-3','form-install');
209 $oForm->_action='?dbx_modul=dbxSetup&dbx_run1=install&stepp=3';
210
211 $oForm->_data=$config;
212 $oForm->_fld_change_state='*';
213 $oForm->add_obj('progress','');
214 $oForm->add_obj('button','dbx|button-submit','label=Admin Daten eintragen und weiter.');
215
216
217 $oForm->add_fld('secure' ,'text-label' ,label: 'Key für Verschlüsselung' ,rules: '*|min=1' ,tooltip: 'Dieser Wert ist der Key für Verschlüsselungen');
218 $oForm->add_fld('page' ,'text-label' ,label: 'Name der Seite / App' ,rules: 'words|min=1' ,tooltip: 'Geben Sie bitte den Namen Ihrer Seite ein' );
219 $oForm->add_fld('email' ,'text-label' ,label: 'eMail von Benutzer admin' ,rules: 'email|min=1' ,tooltip: 'Geben Sie bitte ihre eMail Adresse ein' );
220
221 $oForm->add_fld('pass1' ,'password-label' ,label: 'Passwort für Benutzer admin' ,rules: 'password|min=1' ,tooltip: 'Geben Sie bitte ein gewünschtes Passwort ein' );
222 $oForm->add_fld('pass2' ,'password-label' ,label: 'Passwort wiederholt eingeben' ,rules: 'password|min=1' ,tooltip: 'Passwort wiederholt eingeben' );
223
224 $oForm->_msg_info = 'Datenbank Tabellen wurden erstellt und Daten eingelesen.';
225 $oForm->_msg_success = 'Passwort und eMail für den Benutzer admin eingetragen.';
226 $oForm->_msg_err = 'Es ist ein Fehler bei der Installation aufgetreten.';
227
228
229 if($oForm->submit()) {
230 $email=$oForm->_post['email'];
231 $pass1=$oForm->_post['pass1'];
232 $pass2=$oForm->_post['pass2'];
233 if(!$oForm->errors()) { // submit && no errors
234 $oForm->_msg_success = 'Datenbank Tabellen werden neu erstellt und Passwort für Benutzer <b>admin</b> eingetragen.';
235 if ($pass1 != $pass2 || $pass2 == '') {
236 $oForm->_msg_error = 'Das Passwort muss zweimal gleich eingegen werden';
237 $oForm->add_fld_error('x','');
238 }
239 }
240
241 if (!$oForm->errors()) {
242 $path=dbx_get_base_dir();
243 $to=$path.'.htaccess';
244 if ($this->is_intranet()) {
245 $from=$path.'xamp.htaccess';
246 } else {
247 $from=$path.'web.htaccess';
248 }
249 if (!copy($from, $to)) {
250 $oForm->add_fld_error('x','');
251 $oForm->_msg_error = 'Das System konnte die .htaccess Datei nicht kopieren !';
252 }
253 }
254
255 if(!$oForm->errors()) {
256 $data['pass']=md5($pass1);
257 $db=dbx()->get_system_obj('dbxDB');
258 $ok=$db->save('dbx_user',$data,'uname = "admin"',0);
259 if (!$ok) {
260 $oForm->add_fld_error('x','');
261 $oForm->_msg_error = 'Das System konnte den Benutzer admin nicht speichern.';
262 }
263 }
264
265 if(!$oForm->errors()) {
266 if (isset($config['install-1'])) unset($config['install-1']);
267 if (isset($config['dbxInstall-1'])) unset($config['dbxInstall-1']);
268 $config['page']=$oForm->_post['page'];
269 $config['ok'] =1; // system install success
270 $this->write_cfg($config);
271 $oForm->_action='?dbx_modul=dbxLogin&dbx_run1=run&dbx_design=default&dbx_page=default';
272 $oForm->_msg_success = 'System wurde erfolgreich installiert.';
273 $oForm->add_obj('button','dbx|button-submit','label=dbXapp System starten.');
274 }
275 } // submit
276 return $oForm->run();
277 } // install_3
278
279
280 private function is_intranet() {
281 $intranet=0;
282 if ($_SERVER['SERVER_NAME'] == 'localhost') $intranet=1;
283 if ($_SERVER['SERVER_ADDR'] == '127.0.0.1') $intranet=1;
284 return $intranet;
285 }
286
287
288
289
290
291
292 public function run() {
293 $stepp=dbx()->get_modul_var('stepp',1,'int');
294
295 switch ($stepp) {
296 case '1':
297 $content=$this->install_1();
298 break;
299 case '2':
300 $content=$this->install_2();
301 break;
302 case '3':
303 $content=$this->install_3();
304 break;
305 case '4':
306 $content=$this->install_4();
307 break;
308 default:
309 $content=$this->install_1();
310 }
311 return $content;
312 } // run()
313
314} // class
315
316?>
$config['version']
Definition config.php:2
dbx_os_path_file($path_file)
Definition index.php:164
dbx_get_file_dir()
Definition index.php:265
dbx_get_base_dir($cut_Data=0)
Definition index.php:157
$_SERVER['REQUEST_URI']