]> git.mxchange.org Git - friendica.git/blob - mod/install.php
DE translation of the BBCode reference, small stuff on the EN version
[friendica.git] / mod / install.php
1 <?php
2 require_once "include/Photo.php";
3
4 $install_wizard_pass=1;
5
6
7 function install_init(&$a){
8
9         // $baseurl/install/testrwrite to test if rewite in .htaccess is working
10         if ($a->argc==2 && $a->argv[1]=="testrewrite") {
11                 echo "ok";
12                 killme();
13         }
14         
15         // We overwrite current theme css, because during install we could not have a working mod_rewrite
16         // so we could not have a css at all. Here we set a static css file for the install procedure pages
17         $a->config['system']['theme'] = "../install";
18         $a->theme['stylesheet'] = $a->get_baseurl()."/view/install/style.css";
19         
20         
21         
22         global $install_wizard_pass;
23         if (x($_POST,'pass'))
24                 $install_wizard_pass = intval($_POST['pass']);
25
26 }
27
28 function install_post(&$a) {
29         global $install_wizard_pass, $db;
30
31         switch($install_wizard_pass) {
32                 case 1:
33                 case 2:
34                         return;
35                         break; // just in case return don't return :)
36                 case 3:
37                         $urlpath = $a->get_path();
38                         $dbhost = notags(trim($_POST['dbhost']));
39                         $dbuser = notags(trim($_POST['dbuser']));
40                         $dbpass = notags(trim($_POST['dbpass']));
41                         $dbdata = notags(trim($_POST['dbdata']));
42                         $phpath = notags(trim($_POST['phpath']));
43
44                         require_once("include/dba.php");
45                         unset($db);
46                         $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
47                         /*if(get_db_errno()) {
48                                 unset($db);
49                                 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
50
51                                 if(! get_db_errno()) {
52                                         $r = q("CREATE DATABASE '%s'",
53                                                         dbesc($dbdata)
54                                         );
55                                         if($r) {
56                                                 unset($db);
57                                                 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
58                                         } else {
59                                                 $a->data['db_create_failed']=true;
60                                         }
61                                 } else {
62                                         $a->data['db_conn_failed']=true;
63                                         return;
64                                 }
65                         }*/
66                         if(get_db_errno()) {
67                                 $a->data['db_conn_failed']=true;
68                         }
69
70                         return;
71                         break;
72                 case 4:
73                         $urlpath = $a->get_path();
74                         $dbhost = notags(trim($_POST['dbhost']));
75                         $dbuser = notags(trim($_POST['dbuser']));
76                         $dbpass = notags(trim($_POST['dbpass']));
77                         $dbdata = notags(trim($_POST['dbdata']));
78                         $phpath = notags(trim($_POST['phpath']));
79                         $timezone = notags(trim($_POST['timezone']));
80                         $language = notags(trim($_POST['language']));
81                         $adminmail = notags(trim($_POST['adminmail']));
82                         // In step 4 of the installer, we passed the  check for mcrypt
83                         // already, so we can activate RINO, make RINO2 the default
84                         // and only fall back if the mcrypt_create_iv function is
85                         // not available on the system.
86                         $rino = 2;
87                         if (! function_exists('mcrypt_create_iv')) {
88                                 $rino = 1;
89                         }
90
91                         // connect to db
92                         $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
93
94                         $tpl = get_markup_template('htconfig.tpl');
95                         $txt = replace_macros($tpl,array(
96                                 '$dbhost' => $dbhost,
97                                 '$dbuser' => $dbuser,
98                                 '$dbpass' => $dbpass,
99                                 '$dbdata' => $dbdata,
100                                 '$timezone' => $timezone,
101                                 '$language' => $language,
102                                 '$urlpath' => $urlpath,
103                                 '$phpath' => $phpath,
104                                 '$adminmail' => $adminmail,
105                                 '$rino' => $rino
106                         ));
107
108
109                         $result = file_put_contents('.htconfig.php', $txt);
110                         if(! $result) {
111                                 $a->data['txt'] = $txt;
112                         }
113
114                         $errors = load_database($db);
115
116
117                         if($errors)
118                                 $a->data['db_failed'] = $errors;
119                         else
120                                 $a->data['db_installed'] = true;
121
122                         return;
123                 break;
124         }
125 }
126
127 function get_db_errno() {
128         if(class_exists('mysqli'))
129                 return mysqli_connect_errno();
130         else
131                 return mysql_errno();
132 }
133
134 function install_content(&$a) {
135
136         global $install_wizard_pass, $db;
137         $o = '';
138         $wizard_status = "";
139         $install_title = t('Friendica Communications Server - Setup');
140
141
142
143         if(x($a->data,'db_conn_failed')) {
144                 $install_wizard_pass = 2;
145                 $wizard_status =  t('Could not connect to database.');
146         }
147         if(x($a->data,'db_create_failed')) {
148                 $install_wizard_pass = 2;
149                 $wizard_status =  t('Could not create table.');
150         }
151
152         $db_return_text="";
153         if(x($a->data,'db_installed')) {
154                 $txt = '<p style="font-size: 130%;">';
155                 $txt .= t('Your Friendica site database has been installed.') . EOL;
156                 $db_return_text .= $txt;
157         }
158
159         if(x($a->data,'db_failed')) {
160                 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
161                 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
162                 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
163                 $db_return_text .= $txt;
164         }
165
166         if($db && $db->connected) {
167                 $r = q("SELECT COUNT(*) as `total` FROM `user`");
168                 if($r && count($r) && $r[0]['total']) {
169                         $tpl = get_markup_template('install.tpl');
170                         return replace_macros($tpl, array(
171                                 '$title' => $install_title,
172                                 '$pass' => '',
173                                 '$status' => t('Database already in use.'),
174                                 '$text' => '',
175                         ));
176                 }
177         }
178
179         if(x($a->data,'txt') && strlen($a->data['txt'])) {
180                 $db_return_text .= manual_config($a);
181         }
182
183         if ($db_return_text!="") {
184                 $tpl = get_markup_template('install.tpl');
185                 return replace_macros($tpl, array(
186                         '$title' => $install_title,
187                         '$pass' => "",
188                         '$text' => $db_return_text . what_next(),
189                 ));
190         }
191
192         switch ($install_wizard_pass){
193                 case 1: { // System check
194
195
196                         $checks = array();
197
198                         check_funcs($checks);
199
200                         check_imagik($checks);
201
202                         check_htconfig($checks);
203
204                         check_smarty3($checks);
205
206                         check_keys($checks);
207
208                         if(x($_POST,'phpath'))
209                                 $phpath = notags(trim($_POST['phpath']));
210
211                         check_php($phpath, $checks);
212
213             check_htaccess($checks);
214
215                         function check_passed($v, $c){
216                                 if ($c['required'])
217                                         $v = $v && $c['status'];
218                                 return $v;
219                         }
220                         $checkspassed = array_reduce($checks, "check_passed", true);
221
222
223
224                         $tpl = get_markup_template('install_checks.tpl');
225                         $o .= replace_macros($tpl, array(
226                                 '$title' => $install_title,
227                                 '$pass' => t('System check'),
228                                 '$checks' => $checks,
229                                 '$passed' => $checkspassed,
230                                 '$see_install' => t('Please see the file "INSTALL.txt".'),
231                                 '$next' => t('Next'),
232                                 '$reload' => t('Check again'),
233                                 '$phpath' => $phpath,
234                                 '$baseurl' => $a->get_baseurl(),
235                         ));
236                         return $o;
237                 }; break;
238
239                 case 2: { // Database config
240
241                         $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
242                         $dbuser = notags(trim($_POST['dbuser']));
243                         $dbpass = notags(trim($_POST['dbpass']));
244                         $dbdata = notags(trim($_POST['dbdata']));
245                         $phpath = notags(trim($_POST['phpath']));
246
247
248                         $tpl = get_markup_template('install_db.tpl');
249                         $o .= replace_macros($tpl, array(
250                                 '$title' => $install_title,
251                                 '$pass' => t('Database connection'),
252                                 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
253                                 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
254                                 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
255
256                                 '$status' => $wizard_status,
257
258                                 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
259                                 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
260                                 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'),
261                                 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
262                                 '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'),
263
264
265
266                                 '$lbl_10' => t('Please select a default timezone for your website'),
267
268                                 '$baseurl' => $a->get_baseurl(),
269
270                                 '$phpath' => $phpath,
271
272                                 '$submit' => t('Submit'),
273
274                         ));
275                         return $o;
276                 }; break;
277                 case 3: { // Site settings
278                         require_once('include/datetime.php');
279                         $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
280                         $dbuser = notags(trim($_POST['dbuser']));
281                         $dbpass = notags(trim($_POST['dbpass']));
282                         $dbdata = notags(trim($_POST['dbdata']));
283                         $phpath = notags(trim($_POST['phpath']));
284
285                         $adminmail = notags(trim($_POST['adminmail']));
286                         $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
287                         /* Installed langs */
288                         $lang_choices = get_available_languages();
289
290                         $tpl = get_markup_template('install_settings.tpl');
291                         $o .= replace_macros($tpl, array(
292                                 '$title' => $install_title,
293                                 '$pass' => t('Site settings'),
294
295                                 '$status' => $wizard_status,
296
297                                 '$dbhost' => $dbhost,
298                                 '$dbuser' => $dbuser,
299                                 '$dbpass' => $dbpass,
300                                 '$dbdata' => $dbdata,
301                                 '$phpath' => $phpath,
302
303                                 '$adminmail' => array('adminmail', t('Site administrator email address'), $adminmail, t('Your account email address must match this in order to use the web admin panel.'), 'required', 'autofocus', 'email'),
304
305
306                                 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
307                                 '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
308                                 '$baseurl' => $a->get_baseurl(),
309
310
311
312                                 '$submit' => t('Submit'),
313
314                         ));
315                         return $o;
316                 }; break;
317
318         }
319 }
320
321 /**
322  * checks   : array passed to template
323  * title    : string
324  * status   : boolean
325  * required : boolean
326  * help         : string optional
327  */
328 function check_add(&$checks, $title, $status, $required, $help){
329         $checks[] = array(
330                 'title' => $title,
331                 'status' => $status,
332                 'required' => $required,
333                 'help'  => $help,
334         );
335 }
336
337 function check_php(&$phpath, &$checks) {
338         $passed = $passed2 = $passed3 = false;
339         if (strlen($phpath)){
340                 $passed = file_exists($phpath);
341         } else {
342                 $phpath = trim(shell_exec('which php'));
343                 $passed = strlen($phpath);
344         }
345         $help = "";
346         if(!$passed) {
347                 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
348                 $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run background polling via cron. See <a href='https://github.com/friendica/friendica/blob/master/doc/Install.md#set-up-the-poller'>'Setup the poller'</a>") . EOL ;
349                 $help .= EOL . EOL ;
350                 $tpl = get_markup_template('field_input.tpl');
351                 $help .= replace_macros($tpl, array(
352                         '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
353                 ));
354                 $phpath="";
355         }
356
357         check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
358
359         if($passed) {
360                 $cmd = "$phpath -v";
361                 $result = trim(shell_exec($cmd));
362                 $passed2 = ( strpos($result, "(cli)") !== false );
363                 list($result) = explode("\n", $result);
364                 $help = "";
365                 if(!$passed2) {
366                         $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
367                         $help .= t('Found PHP version: ')."<tt>$result</tt>";
368                 }
369                 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
370         }
371
372
373         if($passed2) {
374                 $str = autoname(8);
375                 $cmd = "$phpath testargs.php $str";
376                 $result = trim(shell_exec($cmd));
377                 $passed3 = $result == $str;
378                 $help = "";
379                 if(!$passed3) {
380                         $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
381                         $help .= t('This is required for message delivery to work.');
382                 }
383                 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
384         }
385
386
387 }
388
389 function check_keys(&$checks) {
390
391         $help = '';
392
393         $res = false;
394
395         if(function_exists('openssl_pkey_new'))
396                 $res=openssl_pkey_new(array(
397                 'digest_alg' => 'sha1',
398                 'private_key_bits' => 4096,
399                 'encrypt_key' => false ));
400
401         // Get private key
402
403         if(! $res) {
404                 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
405                 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
406         }
407         check_add($checks, t('Generate encryption keys'), $res, true, $help);
408
409 }
410
411
412 function check_funcs(&$checks) {
413         $ck_funcs = array();
414         check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
415         check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
416         check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
417         check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
418         check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
419         check_add($ck_funcs, t('mcrypt PHP module'), true, true, "");
420         check_add($ck_funcs, t('XML PHP module'), true, true, "");
421         check_add($ck_funcs, t('iconv module'), true, true, "");
422
423         if(function_exists('apache_get_modules')){
424                 if (! in_array('mod_rewrite',apache_get_modules())) {
425                         check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
426                 } else {
427                         check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
428                 }
429         }
430
431         if(! function_exists('curl_init')){
432                 $ck_funcs[0]['status']= false;
433                 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
434         }
435         if(! function_exists('imagecreatefromjpeg')){
436                 $ck_funcs[1]['status']= false;
437                 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
438         }
439         if(! function_exists('openssl_public_encrypt')) {
440                 $ck_funcs[2]['status']= false;
441                 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
442         }
443         if(! function_exists('mysqli_connect')){
444                 $ck_funcs[3]['status']= false;
445                 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
446         }
447         if(! function_exists('mb_strlen')){
448                 $ck_funcs[4]['status']= false;
449                 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
450         }
451         if(! function_exists('mcrypt_create_iv')){
452                 $ck_funcs[5]['status']= false;
453                 $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.');
454         }
455         if(! function_exists('iconv_strlen')){
456                 $ck_funcs[7]['status']= false;
457                 $ck_funcs[7]['help']= t('Error: iconv PHP module required but not installed.');
458         }
459
460         $checks = array_merge($checks, $ck_funcs);
461
462         // check for 'mcrypt_create_iv()', needed for RINO2
463         if ($ck_funcs[5]['status']) {
464                 if (function_exists('mcrypt_create_iv')) {
465                         $__status = true;
466                         $__help = t("If you are using php_cli, please make sure that mcrypt module is enabled in its config file");
467                 } else {
468                         $__status = false;
469                         $__help = t('Function mcrypt_create_iv() is not defined. This is needed to enable RINO2 encryption layer.');
470                 }
471                 check_add($checks, t('mcrypt_create_iv() function'), $__status, false, $__help);
472         }
473
474         // check for XML DOM Documents being able to be generated
475         try {
476                 $xml = new DOMDocument();
477         } catch (Exception $e) {
478                 $ck_funcs[6]['status'] = false;
479                 $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
480         }
481
482         /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
483                 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
484 }
485
486
487 function check_htconfig(&$checks) {
488         $status = true;
489         $help = "";
490         if(     (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
491                 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
492
493                 $status=false;
494                 $help = t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.') .EOL;
495                 $help .= t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.').EOL;
496                 $help .= t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica top folder.').EOL;
497                 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
498         }
499
500         check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
501
502 }
503
504 function check_smarty3(&$checks) {
505         $status = true;
506         $help = "";
507         if(     !is_writable('view/smarty3') ) {
508
509                 $status=false;
510                 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
511                 $help .= t('In order to store these compiled templates, the web server needs to have write access to the directory view/smarty3/ under the Friendica top level folder.').EOL;
512                 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
513                 $help .= t('Note: as a security measure, you should give the web server write access to view/smarty3/ only--not the template files (.tpl) that it contains.').EOL;
514         }
515
516         check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
517
518 }
519
520 function check_htaccess(&$checks) {
521         $a = get_app();
522         $status = true;
523         $help = "";
524         if (function_exists('curl_init')){
525                 $test = fetch_url($a->get_baseurl()."/install/testrewrite");
526
527                 if ($test!="ok")
528                         $test = fetch_url(normalise_link($a->get_baseurl()."/install/testrewrite"));
529
530                 if ($test!="ok") {
531                         $status = false;
532                         $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
533                 }
534                 check_add($checks, t('Url rewrite is working'), $status, true, $help);
535         } else {
536                 // cannot check modrewrite if libcurl is not installed
537         }
538 }
539
540 function check_imagik(&$checks) {
541         $imagick = false;
542         $gif = false;
543
544         if (class_exists('Imagick')) {
545                 $imagick = true;
546                 $supported = Photo::supportedTypes();
547                 if (array_key_exists('image/gif', $supported)) {
548                         $gif = true;
549                 }
550         }
551         check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
552         if ($imagick) {
553                 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
554         }
555 }
556
557
558
559 function manual_config(&$a) {
560         $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
561         $o = t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.');
562         $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
563         return $o;
564 }
565
566 function load_database_rem($v, $i){
567         $l = trim($i);
568         if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
569                 return $v;
570         } else  {
571                 return $v."\n".$i;
572         }
573 }
574
575
576 function load_database($db) {
577
578         require_once("include/dbstructure.php");
579         $errors = update_structure(false, true);
580
581 /*      $str = file_get_contents('database.sql');
582         $arr = explode(';',$str);
583         $errors = false;
584         foreach($arr as $a) {
585                 if(strlen(trim($a))) {
586                         $r = @$db->q(trim($a));
587                         if(false === $r) {
588                                 $errors .=  t('Errors encountered creating database tables.') . $a . EOL;
589                         }
590                 }
591         }*/
592
593         return $errors;
594 }
595
596 function what_next() {
597         $a = get_app();
598         $baseurl = $a->get_baseurl();
599         return
600                 t('<h1>What next</h1>')
601                 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
602                 .t('Please see the file "INSTALL.txt".')
603                 ."</p><p>"
604                 .t("Go to your new Friendica node <a href='$baseurl/register'>registration page</a> and register as new user. Remember to use the same email you have entered as administrator email. This will allow you to enter the site admin panel.")
605                 ."</p>";
606 }
607
608