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']));
84 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
86 $tpl = get_markup_template('htconfig.tpl');
87 $txt = replace_macros($tpl,array(
92 '$timezone' => $timezone,
93 '$language' => $language,
94 '$urlpath' => $urlpath,
96 '$adminmail' => $adminmail,
101 $result = file_put_contents('.htconfig.php', $txt);
103 $a->data['txt'] = $txt;
106 $errors = load_database($db);
110 $a->data['db_failed'] = $errors;
112 $a->data['db_installed'] = true;
120 function get_db_errno() {
121 if (class_exists('mysqli')) {
122 return mysqli_connect_errno();
124 return mysql_errno();
128 function install_content(App $a) {
130 global $install_wizard_pass, $db;
133 $install_title = t('Friendica Communications Server - Setup');
137 if (x($a->data,'db_conn_failed')) {
138 $install_wizard_pass = 2;
139 $wizard_status = t('Could not connect to database.');
141 if (x($a->data,'db_create_failed')) {
142 $install_wizard_pass = 2;
143 $wizard_status = t('Could not create table.');
147 if (x($a->data,'db_installed')) {
148 $txt = '<p style="font-size: 130%;">';
149 $txt .= t('Your Friendica site database has been installed.') . EOL;
150 $db_return_text .= $txt;
153 if (x($a->data,'db_failed')) {
154 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
155 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
156 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
157 $db_return_text .= $txt;
160 if($db && $db->connected) {
161 $r = q("SELECT COUNT(*) as `total` FROM `user`");
162 if (dbm::is_result($r) && $r[0]['total']) {
163 $tpl = get_markup_template('install.tpl');
164 return replace_macros($tpl, array(
165 '$title' => $install_title,
167 '$status' => t('Database already in use.'),
173 if (x($a->data,'txt') && strlen($a->data['txt'])) {
174 $db_return_text .= manual_config($a);
177 if ($db_return_text!="") {
178 $tpl = get_markup_template('install.tpl');
179 return replace_macros($tpl, array(
180 '$title' => $install_title,
182 '$text' => $db_return_text . what_next(),
186 switch ($install_wizard_pass){
187 case 1: { // System check
192 check_funcs($checks);
194 check_imagik($checks);
196 check_htconfig($checks);
198 check_smarty3($checks);
202 if (x($_POST,'phpath')) {
203 $phpath = notags(trim($_POST['phpath']));
206 check_php($phpath, $checks);
208 check_htaccess($checks);
210 /// @TODO Maybe move this out?
211 function check_passed($v, $c){
212 if ($c['required']) {
213 $v = $v && $c['status'];
217 $checkspassed = array_reduce($checks, "check_passed", true);
221 $tpl = get_markup_template('install_checks.tpl');
222 $o .= replace_macros($tpl, array(
223 '$title' => $install_title,
224 '$pass' => t('System check'),
225 '$checks' => $checks,
226 '$passed' => $checkspassed,
227 '$see_install' => t('Please see the file "INSTALL.txt".'),
228 '$next' => t('Next'),
229 '$reload' => t('Check again'),
230 '$phpath' => $phpath,
231 '$baseurl' => App::get_baseurl(),
236 case 2: { // Database config
238 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
239 $dbuser = notags(trim($_POST['dbuser']));
240 $dbpass = notags(trim($_POST['dbpass']));
241 $dbdata = notags(trim($_POST['dbdata']));
242 $phpath = notags(trim($_POST['phpath']));
245 $tpl = get_markup_template('install_db.tpl');
246 $o .= replace_macros($tpl, array(
247 '$title' => $install_title,
248 '$pass' => t('Database connection'),
249 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
250 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
251 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
253 '$status' => $wizard_status,
255 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
256 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
257 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, t("For security reasons the password must not be empty"), 'required'),
258 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
259 '$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 '$lbl_10' => t('Please select a default timezone for your website'),
265 '$baseurl' => App::get_baseurl(),
267 '$phpath' => $phpath,
269 '$submit' => t('Submit'),
274 case 3: { // Site settings
275 require_once('include/datetime.php');
276 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
277 $dbuser = notags(trim($_POST['dbuser']));
278 $dbpass = notags(trim($_POST['dbpass']));
279 $dbdata = notags(trim($_POST['dbdata']));
280 $phpath = notags(trim($_POST['phpath']));
282 $adminmail = notags(trim($_POST['adminmail']));
283 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
284 /* Installed langs */
285 $lang_choices = get_available_languages();
287 $tpl = get_markup_template('install_settings.tpl');
288 $o .= replace_macros($tpl, array(
289 '$title' => $install_title,
290 '$pass' => t('Site settings'),
292 '$status' => $wizard_status,
294 '$dbhost' => $dbhost,
295 '$dbuser' => $dbuser,
296 '$dbpass' => $dbpass,
297 '$dbdata' => $dbdata,
298 '$phpath' => $phpath,
300 '$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'),
303 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
304 '$language' => array('language', t('System Language:'), 'en', t('Set the default language for your Friendica installation interface and to send emails.'), $lang_choices),
305 '$baseurl' => App::get_baseurl(),
309 '$submit' => t('Submit'),
319 * checks : array passed to template
323 * help : string optional
325 function check_add(&$checks, $title, $status, $required, $help){
329 'required' => $required,
334 function check_php(&$phpath, &$checks) {
335 $passed = $passed2 = $passed3 = false;
336 if (strlen($phpath)){
337 $passed = file_exists($phpath);
339 $phpath = trim(shell_exec('which php'));
340 $passed = strlen($phpath);
344 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
345 $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 ;
347 $tpl = get_markup_template('field_input.tpl');
348 $help .= replace_macros($tpl, array(
349 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
354 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
358 $result = trim(shell_exec($cmd));
359 $passed2 = ( strpos($result, "(cli)") !== false );
360 list($result) = explode("\n", $result);
363 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
364 $help .= t('Found PHP version: ')."<tt>$result</tt>";
366 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
372 $cmd = "$phpath testargs.php $str";
373 $result = trim(shell_exec($cmd));
374 $passed3 = $result == $str;
377 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
378 $help .= t('This is required for message delivery to work.');
380 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
386 function check_keys(&$checks) {
392 if (function_exists('openssl_pkey_new')) {
393 $res = openssl_pkey_new(array(
394 'digest_alg' => 'sha1',
395 'private_key_bits' => 4096,
396 'encrypt_key' => false
403 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
404 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
406 check_add($checks, t('Generate encryption keys'), $res, true, $help);
411 function check_funcs(&$checks) {
413 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
414 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
415 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
416 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
417 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
418 check_add($ck_funcs, t('XML PHP module'), true, true, "");
419 check_add($ck_funcs, t('iconv module'), true, true, "");
421 if (function_exists('apache_get_modules')){
422 if (! in_array('mod_rewrite',apache_get_modules())) {
423 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
425 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
429 if (! function_exists('curl_init')){
430 $ck_funcs[0]['status']= false;
431 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
433 if (! function_exists('imagecreatefromjpeg')){
434 $ck_funcs[1]['status']= false;
435 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
437 if (! function_exists('openssl_public_encrypt')) {
438 $ck_funcs[2]['status']= false;
439 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
441 if (! function_exists('mysqli_connect')){
442 $ck_funcs[3]['status']= false;
443 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
445 if (! function_exists('mb_strlen')){
446 $ck_funcs[4]['status']= false;
447 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
449 if (! function_exists('iconv_strlen')){
450 $ck_funcs[7]['status']= false;
451 $ck_funcs[7]['help']= t('Error: iconv PHP module required but not installed.');
454 $checks = array_merge($checks, $ck_funcs);
456 // check for XML DOM Documents being able to be generated
458 $xml = new DOMDocument();
459 } catch (Exception $e) {
460 $ck_funcs[6]['status'] = false;
461 $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
464 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
465 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
469 function check_htconfig(&$checks) {
472 if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
473 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
476 $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;
477 $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;
478 $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;
479 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
482 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
486 function check_smarty3(&$checks) {
489 if (!is_writable('view/smarty3') ) {
492 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
493 $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;
494 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
495 $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;
498 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
502 function check_htaccess(&$checks) {
505 if (function_exists('curl_init')) {
506 $test = fetch_url(App::get_baseurl()."/install/testrewrite");
509 $test = fetch_url(normalise_link(App::get_baseurl()."/install/testrewrite"));
514 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
516 check_add($checks, t('Url rewrite is working'), $status, true, $help);
518 // cannot check modrewrite if libcurl is not installed
519 /// @TODO Maybe issue warning here?
523 function check_imagik(&$checks) {
527 if (class_exists('Imagick')) {
529 $supported = Photo::supportedTypes();
530 if (array_key_exists('image/gif', $supported)) {
534 if ($imagick == false) {
535 check_add($checks, t('ImageMagick PHP extension is not installed'), $imagick, false, "");
537 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
539 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
544 function manual_config(App $a) {
545 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
546 $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.');
547 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
551 function load_database_rem($v, $i){
553 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
560 function load_database($db) {
562 require_once("include/dbstructure.php");
563 $errors = update_structure(false, true);
565 /* $str = file_get_contents('database.sql');
566 $arr = explode(';',$str);
568 foreach($arr as $a) {
569 if(strlen(trim($a))) {
570 $r = @$db->q(trim($a));
572 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
580 function what_next() {
581 $baseurl = App::get_baseurl();
583 t('<h1>What next</h1>')
584 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
585 .t('Please see the file "INSTALL.txt".')
587 .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.")