2 require_once "include/Photo.php";
4 $install_wizard_pass=1;
7 function install_init(&$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'] = $a->get_baseurl()."/view/install/style.css";
22 global $install_wizard_pass;
24 $install_wizard_pass = intval($_POST['pass']);
28 function install_post(&$a) {
29 global $install_wizard_pass, $db;
31 switch($install_wizard_pass) {
35 break; // just in case return don't return :)
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']));
44 require_once("include/dba.php");
46 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
47 /*if(get_db_errno()) {
49 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
51 if(! get_db_errno()) {
52 $r = q("CREATE DATABASE '%s'",
57 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
59 $a->data['db_create_failed']=true;
62 $a->data['db_conn_failed']=true;
67 $a->data['db_conn_failed']=true;
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 $adminmail = notags(trim($_POST['adminmail']));
83 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
85 $tpl = get_markup_template('htconfig.tpl');
86 $txt = replace_macros($tpl,array(
91 '$timezone' => $timezone,
92 '$urlpath' => $urlpath,
94 '$adminmail' => $adminmail
98 $result = file_put_contents('.htconfig.php', $txt);
100 $a->data['txt'] = $txt;
103 $errors = load_database($db);
107 $a->data['db_failed'] = $errors;
109 $a->data['db_installed'] = true;
116 function get_db_errno() {
117 if(class_exists('mysqli'))
118 return mysqli_connect_errno();
120 return mysql_errno();
123 function install_content(&$a) {
125 global $install_wizard_pass, $db;
128 $install_title = t('Friendica Communications Server - Setup');
132 if(x($a->data,'db_conn_failed')) {
133 $install_wizard_pass = 2;
134 $wizard_status = t('Could not connect to database.');
136 if(x($a->data,'db_create_failed')) {
137 $install_wizard_pass = 2;
138 $wizard_status = t('Could not create table.');
142 if(x($a->data,'db_installed')) {
143 $txt = '<p style="font-size: 130%;">';
144 $txt .= t('Your Friendica site database has been installed.') . EOL;
145 $db_return_text .= $txt;
148 if(x($a->data,'db_failed')) {
149 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
150 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
151 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
152 $db_return_text .= $txt;
155 if($db && $db->connected) {
156 $r = q("SELECT COUNT(*) as `total` FROM `user`");
157 if($r && count($r) && $r[0]['total']) {
158 $tpl = get_markup_template('install.tpl');
159 return replace_macros($tpl, array(
160 '$title' => $install_title,
162 '$status' => t('Database already in use.'),
168 if(x($a->data,'txt') && strlen($a->data['txt'])) {
169 $db_return_text .= manual_config($a);
172 if ($db_return_text!="") {
173 $tpl = get_markup_template('install.tpl');
174 return replace_macros($tpl, array(
175 '$title' => $install_title,
177 '$text' => $db_return_text . what_next(),
181 switch ($install_wizard_pass){
182 case 1: { // System check
187 check_funcs($checks);
189 check_imagik($checks);
191 check_htconfig($checks);
193 check_smarty3($checks);
197 if(x($_POST,'phpath'))
198 $phpath = notags(trim($_POST['phpath']));
200 check_php($phpath, $checks);
202 check_htaccess($checks);
204 function check_passed($v, $c){
206 $v = $v && $c['status'];
209 $checkspassed = array_reduce($checks, "check_passed", true);
213 $tpl = get_markup_template('install_checks.tpl');
214 $o .= replace_macros($tpl, array(
215 '$title' => $install_title,
216 '$pass' => t('System check'),
217 '$checks' => $checks,
218 '$passed' => $checkspassed,
219 '$see_install' => t('Please see the file "INSTALL.txt".'),
220 '$next' => t('Next'),
221 '$reload' => t('Check again'),
222 '$phpath' => $phpath,
223 '$baseurl' => $a->get_baseurl(),
228 case 2: { // Database config
230 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
231 $dbuser = notags(trim($_POST['dbuser']));
232 $dbpass = notags(trim($_POST['dbpass']));
233 $dbdata = notags(trim($_POST['dbdata']));
234 $phpath = notags(trim($_POST['phpath']));
237 $tpl = get_markup_template('install_db.tpl');
238 $o .= replace_macros($tpl, array(
239 '$title' => $install_title,
240 '$pass' => t('Database connection'),
241 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
242 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
243 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
245 '$status' => $wizard_status,
247 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
248 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
249 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'),
250 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
251 '$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'),
255 '$lbl_10' => t('Please select a default timezone for your website'),
257 '$baseurl' => $a->get_baseurl(),
259 '$phpath' => $phpath,
261 '$submit' => t('Submit'),
266 case 3: { // Site settings
267 require_once('include/datetime.php');
268 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
269 $dbuser = notags(trim($_POST['dbuser']));
270 $dbpass = notags(trim($_POST['dbpass']));
271 $dbdata = notags(trim($_POST['dbdata']));
272 $phpath = notags(trim($_POST['phpath']));
274 $adminmail = notags(trim($_POST['adminmail']));
275 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
277 $tpl = get_markup_template('install_settings.tpl');
278 $o .= replace_macros($tpl, array(
279 '$title' => $install_title,
280 '$pass' => t('Site settings'),
282 '$status' => $wizard_status,
284 '$dbhost' => $dbhost,
285 '$dbuser' => $dbuser,
286 '$dbpass' => $dbpass,
287 '$dbdata' => $dbdata,
288 '$phpath' => $phpath,
290 '$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'),
293 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
295 '$baseurl' => $a->get_baseurl(),
299 '$submit' => t('Submit'),
309 * checks : array passed to template
313 * help : string optional
315 function check_add(&$checks, $title, $status, $required, $help){
319 'required' => $required,
324 function check_php(&$phpath, &$checks) {
325 $passed = $passed2 = $passed3 = false;
326 if (strlen($phpath)){
327 $passed = file_exists($phpath);
329 $phpath = trim(shell_exec('which php'));
330 $passed = strlen($phpath);
334 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
335 $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 ;
337 $tpl = get_markup_template('field_input.tpl');
338 $help .= replace_macros($tpl, array(
339 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
344 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
348 $result = trim(shell_exec($cmd));
349 $passed2 = ( strpos($result, "(cli)") !== false );
350 list($result) = explode("\n", $result);
353 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
354 $help .= t('Found PHP version: ')."<tt>$result</tt>";
356 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
362 $cmd = "$phpath testargs.php $str";
363 $result = trim(shell_exec($cmd));
364 $passed3 = $result == $str;
367 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
368 $help .= t('This is required for message delivery to work.');
370 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
376 function check_keys(&$checks) {
382 if(function_exists('openssl_pkey_new'))
383 $res=openssl_pkey_new(array(
384 'digest_alg' => 'sha1',
385 'private_key_bits' => 4096,
386 'encrypt_key' => false ));
391 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
392 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
394 check_add($checks, t('Generate encryption keys'), $res, true, $help);
399 function check_funcs(&$checks) {
401 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
402 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
403 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
404 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
405 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
406 check_add($ck_funcs, t('mcrypt PHP module'), true, true, "");
409 if(function_exists('apache_get_modules')){
410 if (! in_array('mod_rewrite',apache_get_modules())) {
411 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
413 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
417 if(! function_exists('curl_init')){
418 $ck_funcs[0]['status']= false;
419 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
421 if(! function_exists('imagecreatefromjpeg')){
422 $ck_funcs[1]['status']= false;
423 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
425 if(! function_exists('openssl_public_encrypt')) {
426 $ck_funcs[2]['status']= false;
427 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
429 if(! function_exists('mysqli_connect')){
430 $ck_funcs[3]['status']= false;
431 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
433 if(! function_exists('mb_strlen')){
434 $ck_funcs[4]['status']= false;
435 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
437 if(! function_exists('mcrypt_create_iv')){
438 $ck_funcs[5]['status']= false;
439 $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.');
442 $checks = array_merge($checks, $ck_funcs);
444 // check for 'mcrypt_create_iv()', needed for RINO2
445 if ($ck_funcs[5]['status']) {
446 if (function_exists('mcrypt_create_iv')) {
448 $__help = "If you are using php_cli, please make sure that mcrypt module is enabled in its config file";
451 $__help = t('Function mcrypt_create_iv() is not defined. This is needed to enable RINO2 encryption layer.');
453 check_add($checks, t('mcrypt_create_iv() function'), $__status, false, $__help);
457 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
458 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
462 function check_htconfig(&$checks) {
465 if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
466 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
469 $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;
470 $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;
471 $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;
472 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
475 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
479 function check_smarty3(&$checks) {
482 if( !is_writable('view/smarty3') ) {
485 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
486 $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;
487 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
488 $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;
491 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
495 function check_htaccess(&$checks) {
499 if (function_exists('curl_init')){
500 $test = fetch_url($a->get_baseurl()."/install/testrewrite");
503 $test = fetch_url(normalise_link($a->get_baseurl()."/install/testrewrite"));
507 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
509 check_add($checks, t('Url rewrite is working'), $status, true, $help);
511 // cannot check modrewrite if libcurl is not installed
515 function check_imagik(&$checks) {
519 if (class_exists('Imagick')) {
521 $supported = Photo::supportedTypes();
522 if (array_key_exists('image/gif', $supported)) {
526 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
528 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
534 function manual_config(&$a) {
535 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
536 $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.');
537 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
541 function load_database_rem($v, $i){
543 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
551 function load_database($db) {
553 require_once("include/dbstructure.php");
554 $errors = update_structure(false, true);
556 /* $str = file_get_contents('database.sql');
557 $arr = explode(';',$str);
559 foreach($arr as $a) {
560 if(strlen(trim($a))) {
561 $r = @$db->q(trim($a));
563 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
571 function what_next() {
573 $baseurl = $a->get_baseurl();
575 t('<h1>What next</h1>')
576 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
577 .t('Please see the file "INSTALL.txt".')
579 .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.")