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']));
16 require_once("dba.php");
18 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
20 if(mysqli_connect_errno()) {
21 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
22 if(! mysql_connect_errno()) {
23 $r = q("CREATE DATABASE '%s'",
27 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, true);
29 if(mysqli_connect_errno()) {
30 notice( t('Could not create/connect to database.') . EOL);
35 notice( t('Connected to database.') . EOL);
37 $tpl = load_view_file('view/htconfig.tpl');
38 $txt = replace_macros($tpl,array(
43 '$timezone' => $timezone,
44 '$urlpath' => $urlpath,
47 $result = file_put_contents('.htconfig.php', $txt);
52 $errors = load_database($db);
54 // Our sessions normally are stored in the database. But as we have only managed
55 // to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so
56 // that you'll see the following important notice (which is stored in the session).
58 session_write_close();
60 require_once('session.php');
62 session_regenerate_id();
64 $_SESSION['sysmsg'] = '';
66 notice( t('Database import succeeded.') . EOL
67 . t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL
68 . t('Please see the file "INSTALL.txt".') . EOL );
69 goaway($a->get_baseurl() . '/register' );
72 $db = null; // start fresh
73 notice( t('Database import failed.') . EOL
74 . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
75 . t('Please see the file "INSTALL.txt".') . EOL );
80 function install_content(&$a) {
84 notice( t('Welcome to Friendika.') . EOL);
89 $o .= check_htconfig();
93 if(strlen($a->data)) {
94 $o .= manual_config($a);
98 $o .= check_php($phpath);
103 require_once('datetime.php');
105 $tpl = load_view_file('view/install_db.tpl');
106 $o .= replace_macros($tpl, array(
107 '$baseurl' => $a->get_baseurl(),
108 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
109 '$submit' => t('Submit'),
110 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
111 '$dbuser' => notags(trim($_POST['dbuser'])),
112 '$dbpass' => notags(trim($_POST['dbpass'])),
113 '$dbdata' => notags(trim($_POST['dbdata'])),
120 function check_php(&$phpath) {
122 $phpath = trim(shell_exec('which php'));
123 if(! strlen($phpath)) {
124 $o .= t('Could not find a command line version of PHP in the web server PATH.') . EOL;
125 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.') . EOL;
127 if(strlen($phpath)) {
129 $cmd = "$phpath testargs.php $str";
130 $result = trim(shell_exec($cmd));
131 if($result != $str) {
132 $o .= t('The command line version of PHP on your system does not have "register_argc_argv" enabled.') . EOL;
133 $o .= t('This is required for message delivery to work.') . EOL;
140 function check_keys() {
146 if(function_exists('openssl_pkey_new'))
147 $res=openssl_pkey_new(array(
148 'digest_alg' => 'sha1',
149 'private_key_bits' => 4096,
150 'encrypt_key' => false ));
155 $o .= t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys') . EOL;
156 $o .= t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".') . EOL;
163 function check_funcs() {
164 if((function_exists('apache_get_modules')) && (! in_array('mod_rewrite',apache_get_modules())))
165 notice( t('Error: Apache webserver mod-rewrite module is required but not installed.') . EOL);
166 if(! function_exists('curl_init'))
167 notice( t('Error: libCURL PHP module required but not installed.') . EOL);
168 if(! function_exists('imagecreatefromjpeg'))
169 notice( t('Error: GD graphics PHP module with JPEG support required but not installed.') . EOL);
170 if(! function_exists('openssl_public_encrypt'))
171 notice( t('Error: openssl PHP module required but not installed.') . EOL);
172 if(! function_exists('mysqli_connect'))
173 notice( t('Error: mysqli PHP module required but not installed.') . EOL);
174 if((x($_SESSION,'sysmsg')) && strlen($_SESSION['sysmsg']))
175 notice( t('Please see the file "INSTALL.txt".') . EOL);
179 function check_htconfig() {
181 if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
182 || (! is_writable('.'))) {
184 $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.');
185 $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.');
186 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
187 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL.txt" for instructions.');
194 function manual_config(&$a) {
195 $data = htmlentities($a->data);
196 $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.');
197 $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
202 function load_database($db) {
204 $str = file_get_contents('database.sql');
205 $arr = explode(';',$str);
207 foreach($arr as $a) {
208 if(strlen(trim($a))) {
209 $r = @$db->q(trim($a));
211 notice( t('Errors encountered creating database tables.') . $a . EOL);