2 require_once "include/Photo.php";
4 $install_wizard_pass=1;
6 if(! function_exists('install_init')) {
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 if(! function_exists('install_post')) {
29 function install_post(&$a) {
30 global $install_wizard_pass, $db;
32 switch($install_wizard_pass) {
36 break; // just in case return don't return :)
38 $urlpath = $a->get_path();
39 $dbhost = notags(trim($_POST['dbhost']));
40 $dbuser = notags(trim($_POST['dbuser']));
41 $dbpass = notags(trim($_POST['dbpass']));
42 $dbdata = notags(trim($_POST['dbdata']));
43 $phpath = notags(trim($_POST['phpath']));
45 require_once("include/dba.php");
47 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
48 /*if(get_db_errno()) {
50 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
52 if(! get_db_errno()) {
53 $r = q("CREATE DATABASE '%s'",
58 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
60 $a->data['db_create_failed']=true;
63 $a->data['db_conn_failed']=true;
68 $a->data['db_conn_failed']=true;
74 $urlpath = $a->get_path();
75 $dbhost = notags(trim($_POST['dbhost']));
76 $dbuser = notags(trim($_POST['dbuser']));
77 $dbpass = notags(trim($_POST['dbpass']));
78 $dbdata = notags(trim($_POST['dbdata']));
79 $phpath = notags(trim($_POST['phpath']));
80 $timezone = notags(trim($_POST['timezone']));
81 $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 '$urlpath' => $urlpath,
95 '$adminmail' => $adminmail
99 $result = file_put_contents('.htconfig.php', $txt);
101 $a->data['txt'] = $txt;
104 $errors = load_database($db);
108 $a->data['db_failed'] = $errors;
110 $a->data['db_installed'] = true;
118 if(! function_exists('get_db_errno')) {
119 function get_db_errno() {
120 if(class_exists('mysqli'))
121 return mysqli_connect_errno();
123 return mysql_errno();
127 if(! function_exists('install_content')) {
128 function install_content(&$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($r && count($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']));
205 check_php($phpath, $checks);
207 check_htaccess($checks);
209 function check_passed($v, $c){
211 $v = $v && $c['status'];
214 $checkspassed = array_reduce($checks, "check_passed", true);
218 $tpl = get_markup_template('install_checks.tpl');
219 $o .= replace_macros($tpl, array(
220 '$title' => $install_title,
221 '$pass' => t('System check'),
222 '$checks' => $checks,
223 '$passed' => $checkspassed,
224 '$see_install' => t('Please see the file "INSTALL.txt".'),
225 '$next' => t('Next'),
226 '$reload' => t('Check again'),
227 '$phpath' => $phpath,
228 '$baseurl' => $a->get_baseurl(),
233 case 2: { // Database config
235 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
236 $dbuser = notags(trim($_POST['dbuser']));
237 $dbpass = notags(trim($_POST['dbpass']));
238 $dbdata = notags(trim($_POST['dbdata']));
239 $phpath = notags(trim($_POST['phpath']));
242 $tpl = get_markup_template('install_db.tpl');
243 $o .= replace_macros($tpl, array(
244 '$title' => $install_title,
245 '$pass' => t('Database connection'),
246 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
247 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
248 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
250 '$status' => $wizard_status,
252 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, '', 'required'),
253 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, '', 'required', 'autofocus'),
254 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, '', 'required'),
255 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, '', 'required'),
256 '$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'),
260 '$lbl_10' => t('Please select a default timezone for your website'),
262 '$baseurl' => $a->get_baseurl(),
264 '$phpath' => $phpath,
266 '$submit' => t('Submit'),
271 case 3: { // Site settings
272 require_once('include/datetime.php');
273 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
274 $dbuser = notags(trim($_POST['dbuser']));
275 $dbpass = notags(trim($_POST['dbpass']));
276 $dbdata = notags(trim($_POST['dbdata']));
277 $phpath = notags(trim($_POST['phpath']));
279 $adminmail = notags(trim($_POST['adminmail']));
280 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
282 $tpl = get_markup_template('install_settings.tpl');
283 $o .= replace_macros($tpl, array(
284 '$title' => $install_title,
285 '$pass' => t('Site settings'),
287 '$status' => $wizard_status,
289 '$dbhost' => $dbhost,
290 '$dbuser' => $dbuser,
291 '$dbpass' => $dbpass,
292 '$dbdata' => $dbdata,
293 '$phpath' => $phpath,
295 '$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'),
298 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
300 '$baseurl' => $a->get_baseurl(),
304 '$submit' => t('Submit'),
315 * checks : array passed to template
319 * help : string optional
321 if(! function_exists('check_add')) {
322 function check_add(&$checks, $title, $status, $required, $help) {
326 'required' => $required,
332 if(! function_exists('check_php')) {
333 function check_php(&$phpath, &$checks) {
334 $passed = $passed2 = $passed3 = false;
335 if (strlen($phpath)){
336 $passed = file_exists($phpath);
338 $phpath = trim(shell_exec('which php'));
339 $passed = strlen($phpath);
343 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
344 $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 ;
346 $tpl = get_markup_template('field_input.tpl');
347 $help .= replace_macros($tpl, array(
348 '$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 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
357 $result = trim(shell_exec($cmd));
358 $passed2 = ( strpos($result, "(cli)") !== false );
359 list($result) = explode("\n", $result);
362 $help .= t('PHP executable is not the php cli binary (could be cgi-fgci version)'). EOL;
363 $help .= t('Found PHP version: ')."<tt>$result</tt>";
365 check_add($checks, t('PHP cli binary'), $passed2, true, $help);
371 $cmd = "$phpath testargs.php $str";
372 $result = trim(shell_exec($cmd));
373 $passed3 = $result == $str;
376 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
377 $help .= t('This is required for message delivery to work.');
379 check_add($checks, t('PHP register_argc_argv'), $passed3, true, $help);
385 if(! function_exists('check_keys')) {
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 ));
401 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
402 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
404 check_add($checks, t('Generate encryption keys'), $res, true, $help);
408 if(! function_exists('check_funcs')) {
409 function check_funcs(&$checks) {
411 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
412 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
413 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
414 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
415 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
416 check_add($ck_funcs, t('mcrypt PHP module'), true, true, "");
419 if(function_exists('apache_get_modules')){
420 if (! in_array('mod_rewrite',apache_get_modules())) {
421 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
423 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
427 if(! function_exists('curl_init')){
428 $ck_funcs[0]['status']= false;
429 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
431 if(! function_exists('imagecreatefromjpeg')){
432 $ck_funcs[1]['status']= false;
433 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
435 if(! function_exists('openssl_public_encrypt')) {
436 $ck_funcs[2]['status']= false;
437 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
439 if(! function_exists('mysqli_connect')){
440 $ck_funcs[3]['status']= false;
441 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
443 if(! function_exists('mb_strlen')){
444 $ck_funcs[4]['status']= false;
445 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
447 if(! function_exists('mcrypt_create_iv')){
448 $ck_funcs[5]['status']= false;
449 $ck_funcs[5]['help']= t('Error: mcrypt PHP module required but not installed.');
452 $checks = array_merge($checks, $ck_funcs);
454 // check for 'mcrypt_create_iv()', needed for RINO2
455 if ($ck_funcs[5]['status']) {
456 if (function_exists('mcrypt_create_iv')) {
458 $__help = "If you are using php_cli, please make sure that mcrypt module is enabled in its config file";
461 $__help = t('Function mcrypt_create_iv() is not defined. This is needed to enable RINO2 encryption layer.');
463 check_add($checks, t('mcrypt_create_iv() function'), $__status, false, $__help);
467 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
468 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
472 if(! function_exists('check_htconfig')) {
473 function check_htconfig(&$checks) {
476 if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
477 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
480 $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;
481 $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;
482 $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;
483 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
486 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
490 if(! function_exists('check_smarty3')) {
491 function check_smarty3(&$checks) {
494 if( !is_writable('view/smarty3') ) {
497 $help = t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL;
498 $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;
499 $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL;
500 $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;
503 check_add($checks, t('view/smarty3 is writable'), $status, true, $help);
507 if(! function_exists('check_htaccess')) {
508 function check_htaccess(&$checks) {
512 if (function_exists('curl_init')){
513 $test = fetch_url($a->get_baseurl()."/install/testrewrite");
516 $test = fetch_url(normalise_link($a->get_baseurl()."/install/testrewrite"));
520 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
522 check_add($checks, t('Url rewrite is working'), $status, true, $help);
524 // cannot check modrewrite if libcurl is not installed
529 if(! function_exists('check_imagik')) {
530 function check_imagik(&$checks) {
534 if (class_exists('Imagick')) {
536 $supported = Photo::supportedTypes();
537 if (array_key_exists('image/gif', $supported)) {
541 check_add($checks, t('ImageMagick PHP extension is installed'), $imagick, false, "");
543 check_add($checks, t('ImageMagick supports GIF'), $gif, false, "");
548 if(! function_exists('manual_config')) {
549 function manual_config(&$a) {
550 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
551 $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.');
552 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
557 if(! function_exists('load_database_rem')) {
558 function load_database_rem($v, $i){
560 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
568 if(! function_exists('load_database')) {
569 function load_database($db) {
571 require_once("include/dbstructure.php");
572 $errors = update_structure(false, true);
574 /* $str = file_get_contents('database.sql');
575 $arr = explode(';',$str);
577 foreach($arr as $a) {
578 if(strlen(trim($a))) {
579 $r = @$db->q(trim($a));
581 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
590 if(! function_exists('what_next')) {
591 function what_next() {
593 $baseurl = $a->get_baseurl();
595 t('<h1>What next</h1>')
596 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
597 .t('Please see the file "INSTALL.txt".')
599 .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.")