3 $install_wizard_pass=1;
6 function install_init(&$a){
8 // $baseurl/install/testrwrite to test if rewite in .htaccess is working
9 if ($a->argc==2 && $a->argv[1]=="testrewrite") {
13 global $install_wizard_pass;
15 $install_wizard_pass = intval($_POST['pass']);
19 function install_post(&$a) {
20 global $install_wizard_pass, $db;
22 switch($install_wizard_pass) {
26 break; // just in case return don't return :)
28 $urlpath = $a->get_path();
29 $dbhost = notags(trim($_POST['dbhost']));
30 $dbuser = notags(trim($_POST['dbuser']));
31 $dbpass = notags(trim($_POST['dbpass']));
32 $dbdata = notags(trim($_POST['dbdata']));
33 $phpath = notags(trim($_POST['phpath']));
35 require_once("dba.php");
37 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
38 /*if(get_db_errno()) {
40 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
42 if(! get_db_errno()) {
43 $r = q("CREATE DATABASE '%s'",
48 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
50 $a->data['db_create_failed']=true;
53 $a->data['db_conn_failed']=true;
58 $a->data['db_conn_failed']=true;
64 $urlpath = $a->get_path();
65 $dbhost = notags(trim($_POST['dbhost']));
66 $dbuser = notags(trim($_POST['dbuser']));
67 $dbpass = notags(trim($_POST['dbpass']));
68 $dbdata = notags(trim($_POST['dbdata']));
69 $phpath = notags(trim($_POST['phpath']));
70 $timezone = notags(trim($_POST['timezone']));
71 $adminmail = notags(trim($_POST['adminmail']));
74 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
76 $tpl = get_intltext_template('htconfig.tpl');
77 $txt = replace_macros($tpl,array(
82 '$timezone' => $timezone,
83 '$urlpath' => $urlpath,
85 '$adminmail' => $adminmail
88 $result = file_put_contents('.htconfig.php', $txt);
90 $a->data['txt'] = $txt;
93 $errors = load_database($db);
96 $a->data['db_failed'] = $errors;
98 $a->data['db_installed'] = true;
105 function get_db_errno() {
106 if(class_exists('mysqli'))
107 return mysqli_connect_errno();
109 return mysql_errno();
112 function install_content(&$a) {
114 global $install_wizard_pass, $db;
117 $install_title = t('Friendica Social Communications Server - Setup');
121 if(x($a->data,'db_conn_failed')) {
122 $install_wizard_pass = 2;
123 $wizard_status = t('Could not connect to database.');
125 if(x($a->data,'db_create_failed')) {
126 $install_wizard_pass = 2;
127 $wizard_status = t('Could not create table.');
131 if(x($a->data,'db_installed')) {
132 $txt = '<p style="font-size: 130%;">';
133 $txt .= t('Your Friendica site database has been installed.') . EOL;
134 $db_return_text .= $txt;
137 if(x($a->data,'db_failed')) {
138 $txt = t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
139 $txt .= t('Please see the file "INSTALL.txt".') . EOL ."<hr>" ;
140 $txt .= "<pre>".$a->data['db_failed'] . "</pre>". EOL ;
141 $db_return_text .= $txt;
144 if($db && $db->connected) {
145 $r = q("SELECT COUNT(*) as `total` FROM `user`");
146 if($r && count($r) && $r[0]['total']) {
147 $tpl = get_markup_template('install.tpl');
148 return replace_macros($tpl, array(
149 '$title' => $install_title,
151 '$status' => t('Permission denied.'),
157 if(x($a->data,'txt') && strlen($a->data['txt'])) {
158 $db_return_text .= manual_config($a);
161 if ($db_return_text!="") {
162 $tpl = get_markup_template('install.tpl');
163 return replace_macros($tpl, array(
164 '$title' => $install_title,
166 '$text' => $db_return_text . what_next(),
170 switch ($install_wizard_pass){
171 case 1: { // System check
176 check_funcs($checks);
178 check_htconfig($checks);
182 if(x($_POST,'phpath'))
183 $phpath = notags(trim($_POST['phpath']));
185 check_php($phpath, $checks);
187 check_htaccess($checks);
189 function check_passed($v, $c){
191 $v = $v && $c['status'];
194 $checkspassed = array_reduce($checks, "check_passed", true);
198 $tpl = get_markup_template('install_checks.tpl');
199 $o .= replace_macros($tpl, array(
200 '$title' => $install_title,
201 '$pass' => t('System check'),
202 '$checks' => $checks,
203 '$passed' => $checkspassed,
204 '$see_install' => t('Please see the file "INSTALL.txt".'),
205 '$next' => t('Next'),
206 '$reload' => t('Check again'),
207 '$phpath' => $phpath,
208 '$baseurl' => $a->get_baseurl(),
213 case 2: { // Database config
215 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
216 $dbuser = notags(trim($_POST['dbuser']));
217 $dbpass = notags(trim($_POST['dbpass']));
218 $dbdata = notags(trim($_POST['dbdata']));
219 $phpath = notags(trim($_POST['phpath']));
222 $tpl = get_markup_template('install_db.tpl');
225 '$field_input' => 'field_input.tpl',
226 '$field_password' => 'field_password.tpl',
228 $includes = set_template_includes($a->theme['template_engine'], $includes);
230 $o .= replace_macros($tpl,$includes + array(
231 '$title' => $install_title,
232 '$pass' => t('Database connection'),
233 '$info_01' => t('In order to install Friendica we need to know how to connect to your database.'),
234 '$info_02' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
235 '$info_03' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
237 '$status' => $wizard_status,
239 '$dbhost' => array('dbhost', t('Database Server Name'), $dbhost, ''),
240 '$dbuser' => array('dbuser', t('Database Login Name'), $dbuser, ''),
241 '$dbpass' => array('dbpass', t('Database Login Password'), $dbpass, ''),
242 '$dbdata' => array('dbdata', t('Database Name'), $dbdata, ''),
243 '$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.')),
247 '$lbl_10' => t('Please select a default timezone for your website'),
249 '$baseurl' => $a->get_baseurl(),
251 '$phpath' => $phpath,
253 '$submit' => t('Submit'),
258 case 3: { // Site settings
259 require_once('datetime.php');
260 $dbhost = ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost');
261 $dbuser = notags(trim($_POST['dbuser']));
262 $dbpass = notags(trim($_POST['dbpass']));
263 $dbdata = notags(trim($_POST['dbdata']));
264 $phpath = notags(trim($_POST['phpath']));
266 $adminmail = notags(trim($_POST['adminmail']));
267 $timezone = ((x($_POST,'timezone')) ? ($_POST['timezone']) : 'America/Los_Angeles');
269 $tpl = get_markup_template('install_settings.tpl');
272 '$field_input' => 'field_input.tpl',
274 $includes = set_template_includes($a->theme['template_engine'], $includes);
276 $o .= replace_macros($tpl, $includes + array(
277 '$title' => $install_title,
278 '$pass' => t('Site settings'),
280 '$status' => $wizard_status,
282 '$dbhost' => $dbhost,
283 '$dbuser' => $dbuser,
284 '$dbpass' => $dbpass,
285 '$dbdata' => $dbdata,
286 '$phpath' => $phpath,
288 '$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.')),
291 '$timezone' => field_timezone('timezone', t('Please select a default timezone for your website'), $timezone, ''),
293 '$baseurl' => $a->get_baseurl(),
297 '$submit' => t('Submit'),
307 * checks : array passed to template
311 * help : string optional
313 function check_add(&$checks, $title, $status, $required, $help){
317 'required' => $required,
322 function check_php(&$phpath, &$checks) {
323 if (strlen($phpath)){
324 $passed = file_exists($phpath);
326 $phpath = trim(shell_exec('which php'));
327 $passed = strlen($phpath);
331 $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL;
332 $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='http://friendica.com/node/27'>'Activating scheduled tasks'</a>") . EOL ;
334 $tpl = get_markup_template('field_input.tpl');
335 $help .= replace_macros($tpl, array(
336 '$field' => array('phpath', t('PHP executable path'), $phpath, t('Enter full path to php executable. You can leave this blank to continue the installation.')),
341 check_add($checks, t('Command line PHP').($passed?" (<tt>$phpath</tt>)":""), $passed, false, $help);
345 $cmd = "$phpath testargs.php $str";
346 $result = trim(shell_exec($cmd));
347 $passed2 = $result == $str;
350 $help .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL;
351 $help .= t('This is required for message delivery to work.');
353 check_add($checks, t('PHP register_argc_argv'), $passed, true, $help);
359 function check_keys(&$checks) {
365 if(function_exists('openssl_pkey_new'))
366 $res=openssl_pkey_new(array(
367 'digest_alg' => 'sha1',
368 'private_key_bits' => 4096,
369 'encrypt_key' => false ));
374 $help .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL;
375 $help .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".');
377 check_add($checks, t('Generate encryption keys'), $res, true, $help);
382 function check_funcs(&$checks) {
384 check_add($ck_funcs, t('libCurl PHP module'), true, true, "");
385 check_add($ck_funcs, t('GD graphics PHP module'), true, true, "");
386 check_add($ck_funcs, t('OpenSSL PHP module'), true, true, "");
387 check_add($ck_funcs, t('mysqli PHP module'), true, true, "");
388 check_add($ck_funcs, t('mb_string PHP module'), true, true, "");
391 if(function_exists('apache_get_modules')){
392 if (! in_array('mod_rewrite',apache_get_modules())) {
393 check_add($ck_funcs, t('Apache mod_rewrite module'), false, true, t('Error: Apache webserver mod-rewrite module is required but not installed.'));
395 check_add($ck_funcs, t('Apache mod_rewrite module'), true, true, "");
399 if(! function_exists('curl_init')){
400 $ck_funcs[0]['status']= false;
401 $ck_funcs[0]['help']= t('Error: libCURL PHP module required but not installed.');
403 if(! function_exists('imagecreatefromjpeg')){
404 $ck_funcs[1]['status']= false;
405 $ck_funcs[1]['help']= t('Error: GD graphics PHP module with JPEG support required but not installed.');
407 if(! function_exists('openssl_public_encrypt')) {
408 $ck_funcs[2]['status']= false;
409 $ck_funcs[2]['help']= t('Error: openssl PHP module required but not installed.');
411 if(! function_exists('mysqli_connect')){
412 $ck_funcs[3]['status']= false;
413 $ck_funcs[3]['help']= t('Error: mysqli PHP module required but not installed.');
415 if(! function_exists('mb_strlen')){
416 $ck_funcs[4]['status']= false;
417 $ck_funcs[4]['help']= t('Error: mb_string PHP module required but not installed.');
420 $checks = array_merge($checks, $ck_funcs);
422 /*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
423 notice( t('Please see the file "INSTALL.txt".') . EOL);*/
427 function check_htconfig(&$checks) {
430 if( (file_exists('.htconfig.php') && !is_writable('.htconfig.php')) ||
431 (!file_exists('.htconfig.php') && !is_writable('.')) ) {
434 $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;
435 $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;
436 $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;
437 $help .= t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL;
440 check_add($checks, t('.htconfig.php is writable'), $status, false, $help);
444 function check_htaccess(&$checks) {
448 if (function_exists('curl_init')){
449 $test = fetch_url($a->get_baseurl()."/install/testrewrite");
452 $help = t('Url rewrite in .htaccess is not working. Check your server configuration.');
454 check_add($checks, t('Url rewrite is working'), $status, true, $help);
456 // cannot check modrewrite if libcurl is not installed
462 function manual_config(&$a) {
463 $data = htmlentities($a->data['txt'],ENT_COMPAT,'UTF-8');
464 $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.');
465 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
469 function load_database_rem($v, $i){
471 if (strlen($l)>1 && ($l[0]=="-" || ($l[0]=="/" && $l[1]=="*"))){
479 function load_database($db) {
481 $str = file_get_contents('database.sql');
482 $arr = explode(';',$str);
484 foreach($arr as $a) {
485 if(strlen(trim($a))) {
486 $r = @$db->q(trim($a));
488 $errors .= t('Errors encountered creating database tables.') . $a . EOL;
495 function what_next() {
497 $baseurl = $a->get_baseurl();
499 t('<h1>What next</h1>')
500 ."<p>".t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.')
501 .t('Please see the file "INSTALL.txt".')
503 .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.")