2 require_once "include/Photo.php";
4 $install_wizard_pass=1;
7 function install_init(App &$a){
9 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
10 if ($a->argc==2 && $a->argv[1]=="testrewrite") {
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'] = App::get_baseurl()."/view/install/style.css";
20 global $install_wizard_pass;
21 if (x($_POST,'pass')) {
22 $install_wizard_pass = intval($_POST['pass']);
27 function install_post(App &$a) {
28 global $install_wizard_pass, $db;
30 switch($install_wizard_pass) {
34 break; // just in case return don't return :)
36 $urlpath = $a->get_path();
37 $dbhost = notags(trim($_POST['dbhost']));
38 $dbuser = notags(trim($_POST['dbuser']));
39 $dbpass = notags(trim($_POST['dbpass']));
40 $dbdata = notags(trim($_POST['dbdata']));
41 $phpath = notags(trim($_POST['phpath']));
43 require_once("include/dba.php");
45 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
46 /*if(get_db_errno()) {
48 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
50 if(! get_db_errno()) {
51 $r = q("CREATE DATABASE '%s'",
56 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
58 $a->data['db_create_failed']=true;
61 $a->data['db_conn_failed']=true;
66 $a->data['db_conn_failed']=true;
72 $urlpath = $a->get_path();
73 $dbhost = notags(trim($_POST['dbhost']));
74 $dbuser = notags(trim($_POST['dbuser']));
75 $dbpass = notags(trim($_POST['dbpass']));
76 $dbdata = notags(trim($_POST['dbdata']));
77 $phpath = notags(trim($_POST['phpath']));
78 $timezone = notags(trim($_POST['timezone']));
79 $language = notags(trim($_POST['language']));
80 $adminmail = notags(trim($_POST['adminmail']));
81 // In step 4 of the installer, we passed the check for mcrypt
82 // already, so we can activate RINO, make RINO2 the default
83 // and only fall back if the mcrypt_create_iv function is
84 // not available on the system.
86 if (! function_exists('mcrypt_create_iv')) {
91 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
93 $tpl = get_markup_template('htconfig.tpl');
94 $txt = replace_macros($tpl,array(
99 '$timezone' => $timezone,
100 '$language' => $language,
101 '$urlpath' => $urlpath,
102 '$phpath' => $phpath,
103 '$adminmail' => $adminmail,
108 $result = file_put_contents('.htconfig.php', $txt);
110 $a->data['txt'] = $txt;
113 $errors = load_database($db);
117 $a->data['db_failed'] = $errors;
119 $a->data['db_installed'] = true;
127 function get_db_errno() {
128 if (class_exists('mysqli')) {
129 return mysqli_connect_errno();
131 return mysql_errno();
135 function install_content(App &$a) {
137 global $install_wizard_pass, $db;
140 $install_title = t('Friendica Communications Server - Setup');
144 if (x($a->data,'db_conn_failed')) {
145 $install_wizard_pass = 2;
146 $wizard_status = t('Could not connect to database.');
148 if (x($a->data,'db_create_failed')) {
149 $install_wizard_pass = 2;
150 $wizard_status = t('Could not create table.');
154 if (x($a->data,'db_installed')) {
155 $txt = '<p style="font-size: 130%;">';
156 $txt .= t('Your Friendica site database has been installed.') . EOL;
157 $db_return_text .= $txt;
160 if (x($a->data,'db_failed')) {
161 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
162 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
163 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
164 $db_return_text .= $txt;
167 if($db && $db->connected) {
168 $r = q("SELECT COUNT(*) as `total` FROM `user`");
169 if (dbm::is_result($r) && $r[0]['total']) {
170 $tpl = get_markup_template('install.tpl');
171 return replace_macros($tpl, array(
172 '$title' => $install_title,
174 '$status' => t('Database already in use.'),
180 if (x($a->data,'txt') && strlen($a->data['txt'])) {
181 $db_return_text .= manual_config($a);
184 if ($db_return_text!="") {
185 $tpl = get_markup_template('install.tpl');
186 return replace_macros($tpl, array(
187 '$title' => $install_title,
189 '$text' => $db_return_text . what_next(),
193 switch ($install_wizard_pass){
194 case 1: { // System check
199 check_funcs($checks);
201 check_imagik($checks);
203 check_htconfig($checks);
205 check_smarty3($checks);
209 if (x($_POST,'phpath')) {
210 $phpath = notags(trim($_POST['phpath']));
213 check_php($phpath, $checks);
215 check_htaccess($checks);
217 /// @TODO Maybe move this out?
218 function check_passed($v, $c){
219 if ($c['required']) {
220 $v = $v && $c['status'];
224 $checkspassed = array_reduce($checks, "check_passed", true);
228 $tpl = get_markup_template('install_checks.tpl');
229 $o .= replace_macros($tpl, array(
230 '$title' => $install_title,
231 '$pass' => t('System check'),
232 '$checks' => $checks,
233 '$passed' => $checkspassed,
234 '$see_install' => t('Please see the file "INSTALL.txt".'),
235 '$next' => t('Next'),
236 '$reload' => t('Check again'),
237 '$phpath' => $phpath,
238 '$baseurl' => App::get_baseurl(),
243 case 2: { // Database config
245 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
246 $dbuser = notags(trim($_POST['dbuser']));
247 $dbpass = notags(trim($_POST['dbpass']));
248 $dbdata = notags(trim($_POST['dbdata']));
249 $phpath = notags(trim($_POST['phpath']));
252 $tpl = get_markup_template('install_db.tpl');
253 $o .= replace_macros($tpl, array(
254 '$title' => $install_title,
255 '$pass' => t('Database connection'),
256 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
257 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
258 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
260 '$status' => $wizard_status,
262 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
263 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
264 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'),
265 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
266 '$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'),
270 '$lbl_10' => t('Please select a default timezone for your website'),
272 '$baseurl' => App::get_baseurl(),
274 '$phpath' => $phpath,
276 '$submit' => t('Submit'),
281 case 3: { // Site settings
282 require_once('include/datetime.php');
283 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
284 $dbuser = notags(trim($_POST['dbuser']));
285 $dbpass = notags(trim($_POST['dbpass']));
286 $dbdata = notags(trim($_POST['dbdata']));
287 $phpath = notags(trim($_POST['phpath']));
289 $adminmail = notags(trim($_POST['adminmail']));
290 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
291 /* Installed langs */
292 $lang_choices = get_available_languages();
294 $tpl = get_markup_template('install_settings.tpl');
295 $o .= replace_macros($tpl, array(
296 '$title' => $install_title,
297 '$pass' => t('Site settings'),
299 '$status' => $wizard_status,
301 '$dbhost' => $dbhost,
302 '$dbuser' => $dbuser,
303 '$dbpass' => $dbpass,
304 '$dbdata' => $dbdata,
305 '$phpath' => $phpath,
307 '$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'),
310 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
311 '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
312 '$baseurl' => App::get_baseurl(),
316 '$submit' => t('Submit'),
326 * checks : array passed to template
330 * help : string optional
332 function check_add(&$checks, $title, $status, $required, $help){
336 'required' => $required,
341 function check_php(&$phpath, &$checks) {
342 $passed = $passed2 = $passed3 = false;
343 if (strlen($phpath)){
344 $passed = file_exists($phpath);
346 $phpath = trim(shell_exec('which php'));
347 $passed = strlen($phpath);
351 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
352 $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 ;
354 $tpl = get_markup_template('field_input.tpl');
355 $help .= replace_macros($tpl, array(
356 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
361 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
365 $result = trim(shell_exec($cmd));
366 $passed2 = ( strpos($result, "(cli)") !== false );
367 list($result) = explode("\n", $result);
370 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
371 $help .= t('Found PHP version: ')."<tt>$result</tt>";
373 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
379 $cmd = "$phpath testargs.php $str";
380 $result = trim(shell_exec($cmd));
381 $passed3 = $result == $str;
384 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
385 $help .= t('This is required for message delivery to work.');
387 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
393 function check_keys(&$checks) {
399 if (function_exists('openssl_pkey_new')) {
400 $res = openssl_pkey_new(array(
401 'digest_alg' => 'sha1',
402 'private_key_bits' => 4096,
403 'encrypt_key' => false
410 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
411 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
413 check_add($checks, t('Generate encryption keys'), $res, true, $help);
418 function check_funcs(&$checks) {
420 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
421 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
422 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
423 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
424 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
425 check_add($ck_funcs, t('mcrypt PHP module'), true, true, "");
426 check_add($ck_funcs, t('XML PHP module'), true, true, "");
427 check_add($ck_funcs, t('iconv module'), true, true, "");
429 if (function_exists('apache_get_modules')){
430 if (! in_array('mod_rewrite',apache_get_modules())) {
431 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
433 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
437 if (! function_exists('curl_init')){
438 $ck_funcs[0]['status']= false;
439 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
441 if (! function_exists('imagecreatefromjpeg')){
442 $ck_funcs[1]['status']= false;
443 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
445 if (! function_exists('openssl_public_encrypt')) {
446 $ck_funcs[2]['status']= false;
447 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
449 if (! function_exists('mysqli_connect')){
450 $ck_funcs[3]['status']= false;
451 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
453 if (! function_exists('mb_strlen')){
454 $ck_funcs[4]['status']= false;
455 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
457 if (! function_exists('mcrypt_create_iv')){
458 $ck_funcs[5]['status']= false;
459 $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.');
461 if (! function_exists('iconv_strlen')){
462 $ck_funcs[7]['status']= false;
463 $ck_funcs[7]['help']= t('Error: iconv PHP module required but not installed.');
466 $checks = array_merge($checks, $ck_funcs);
468 // check for 'mcrypt_create_iv()', needed for RINO2
469 if ($ck_funcs[5]['status']) {
470 if (function_exists('mcrypt_create_iv')) {
472 $__help = t("If you are using php_cli, please make sure that mcrypt module is enabled in its config file");
475 $__help = t('Function mcrypt_create_iv() is not defined. This is needed to enable RINO2 encryption layer.');
477 check_add($checks, t('mcrypt_create_iv() function'), $__status, false, $__help);
480 // check for XML DOM Documents being able to be generated
482 $xml = new DOMDocument();
483 } catch (Exception $e) {
484 $ck_funcs[6]['status'] = false;
485 $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
488 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
489 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
493 function check_htconfig(&$checks) {
496 if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
497 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
500 $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;
501 $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;
502 $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;
503 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
506 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
510 function check_smarty3(&$checks) {
513 if (!is_writable('view/smarty3') ) {
516 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
517 $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;
518 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
519 $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;
522 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
526 function check_htaccess(&$checks) {
529 if (function_exists('curl_init')) {
530 $test = fetch_url(App::get_baseurl()."/install/testrewrite");
533 $test = fetch_url(normalise_link(App::get_baseurl()."/install/testrewrite"));
538 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
540 check_add($checks, t('Url rewrite is working'), $status, true, $help);
542 // cannot check modrewrite if libcurl is not installed
543 /// @TODO Maybe issue warning here?
547 function check_imagik(&$checks) {
551 if (class_exists('Imagick')) {
553 $supported = Photo::supportedTypes();
554 if (array_key_exists('image/gif', $supported)) {
558 if ($imagick == false) {
559 check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, "");
561 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
563 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
569 function manual_config(App &$a) {
570 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
571 $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.');
572 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
576 function load_database_rem($v, $i){
578 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
586 function load_database($db) {
588 require_once("include/dbstructure.php");
589 $errors = update_structure(false, true);
591 /* $str = file_get_contents('database.sql');
592 $arr = explode(';',$str);
594 foreach($arr as $a) {
595 if(strlen(trim($a))) {
596 $r = @$db->q(trim($a));
598 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
606 function what_next() {
607 $baseurl = App::get_baseurl();
609 t('<h1>What next</h1>')
610 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
611 .t('Please see the file "INSTALL.txt".')
613 .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.")