4 function install_post(&$a) {
8 $urlpath = $a->get_path();
9 $dbhost = notags(trim($_POST['dbhost']));
10 $dbuser = notags(trim($_POST['dbuser']));
11 $dbpass = notags(trim($_POST['dbpass']));
12 $dbdata = notags(trim($_POST['dbdata']));
13 $timezone = notags(trim($_POST['timezone']));
14 $phpath = notags(trim($_POST['phpath']));
15 $adminmail = notags(trim($_POST['adminmail']));
17 require_once("dba.php");
19 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
21 if(mysqli_connect_errno()) {
23 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
24 if(! mysqli_connect_errno()) {
25 $r = q("CREATE DATABASE '%s'",
30 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
33 if(mysqli_connect_errno()) {
34 notice( t('Could not create/connect to database.') . EOL);
39 info( t('Connected to database.') . EOL);
41 $tpl = get_intltext_template('htconfig.tpl');
42 $txt = replace_macros($tpl,array(
47 '$timezone' => $timezone,
48 '$urlpath' => $urlpath,
50 '$adminmail' => $adminmail
53 $result = file_put_contents('.htconfig.php', $txt);
58 $errors = load_database($db);
61 $a->data['db_failed'] = true;
63 $a->data['db_installed'] = true;
69 function install_content(&$a) {
74 if(x($a->data,'db_installed')) {
75 $o .= '<h2>' . t('Proceed with Installation') . '</h2>';
76 $o .= '<p style="font-size: 130%;">';
77 $o .= t('Your Friendika site database has been installed.') . EOL;
78 $o .= t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL ;
79 $o .= t('Please see the file "INSTALL.txt".') . EOL ;
81 $o .= '<a href="' . $a->get_baseurl() . '/register' . '">' . t('Proceed to registration') . '</a>' ;
86 if(x($a->data,'db_failed')) {
87 $o .= t('Database import failed.') . EOL;
88 $o .= t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
89 $o .= t('Please see the file "INSTALL.txt".') . EOL ;
93 if($db && $db->connected) {
94 $r = q("SELECT COUNT(*) as `total` FROM `user`");
95 if($r && count($r) && $r[0]['total']) {
96 notice( t('Permission denied.') . EOL);
101 info( t('Welcome to Friendika.') . EOL);
106 $o .= check_htconfig();
110 if(strlen($a->data)) {
111 $o .= manual_config($a);
115 $o .= check_php($phpath);
120 require_once('datetime.php');
122 $tpl = get_markup_template('install_db.tpl');
123 $o .= replace_macros($tpl, array(
124 '$lbl_01' => t('Friendika Social Network'),
125 '$lbl_02' => t('Installation'),
126 '$lbl_03' => t('In order to install Friendika we need to know how to connect to your database.'),
127 '$lbl_04' => t('Please contact your hosting provider or site administrator if you have questions about these settings.'),
128 '$lbl_05' => t('The database you specify below should already exist. If it does not, please create it before continuing.'),
129 '$lbl_06' => t('Database Server Name'),
130 '$lbl_07' => t('Database Login Name'),
131 '$lbl_08' => t('Database Login Password'),
132 '$lbl_09' => t('Database Name'),
133 '$lbl_10' => t('Please select a default timezone for your website'),
134 '$lbl_11' => t('Site administrator email address. Your account email address must match this in order to use the web admin panel.'),
135 '$baseurl' => $a->get_baseurl(),
136 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
137 '$submit' => t('Submit'),
138 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
139 '$dbuser' => notags(trim($_POST['dbuser'])),
140 '$dbpass' => notags(trim($_POST['dbpass'])),
141 '$dbdata' => notags(trim($_POST['dbdata'])),
142 '$phpath' => $phpath,
143 '$adminmail' => notags(trim($_POST['adminmail']))
149 function check_php(&$phpath) {
151 $phpath = trim(shell_exec('which php'));
152 if(! strlen($phpath)) {
153 $o .= t('Could not find a command line version of PHP in the web server PATH.') . EOL;
154 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.') . EOL;
156 if(strlen($phpath)) {
158 $cmd = "$phpath testargs.php $str";
159 $result = trim(shell_exec($cmd));
160 if($result != $str) {
161 $o .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL;
162 $o .= t('This is required for message delivery to work.') . EOL;
169 function check_keys() {
175 if(function_exists('openssl_pkey_new'))
176 $res=openssl_pkey_new(array(
177 'digest_alg' => 'sha1',
178 'private_key_bits' => 4096,
179 'encrypt_key' => false ));
184 $o .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys') . EOL;
185 $o .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".') . EOL;
192 function check_funcs() {
193 if((function_exists('apache_get_modules')) && (! in_array('mod_rewrite',apache_get_modules())))
194 notice( t('Error: Apache webserver mod-rewrite module is required but not installed.') . EOL);
195 if(! function_exists('curl_init'))
196 notice( t('Error: libCURL PHP module required but not installed.') . EOL);
197 if(! function_exists('imagecreatefromjpeg'))
198 notice( t('Error: GD graphics PHP module with JPEG support required but not installed.') . EOL);
199 if(! function_exists('openssl_public_encrypt'))
200 notice( t('Error: openssl PHP module required but not installed.') . EOL);
201 if(! function_exists('mysqli_connect'))
202 notice( t('Error: mysqli PHP module required but not installed.') . EOL);
203 if(! function_exists('mb_strlen'))
204 notice( t('Error: mb_string PHP module required but not installed.') . EOL);
206 if((x($_SESSION,'sysmsg')) && strlen($_SESSION['sysmsg']))
207 notice( t('Please see the file "INSTALL.txt".') . EOL);
211 function check_htconfig() {
213 if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
214 || (! is_writable('.'))) {
216 $o = 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.');
217 $o .= 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.');
218 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
219 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL.txt" for instructions.');
226 function manual_config(&$a) {
227 $data = htmlentities($a->data);
228 $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.');
229 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
234 function load_database($db) {
236 $str = file_get_contents('database.sql');
237 $arr = explode(';',$str);
239 foreach($arr as $a) {
240 if(strlen(trim($a))) {
241 $r = @$db->q(trim($a));
243 notice( t('Errors encountered creating database tables.') . $a . EOL);