]> git.mxchange.org Git - friendica.git/blob - mod/install.php
cbe3b2fc9b190995c2cbf0c611362bd49edbe551
[friendica.git] / mod / install.php
1 <?php
2
3
4 function install_post(&$a) {
5
6         global $db;
7
8         $dbhost = notags(trim($_POST['dbhost']));
9         $dbuser = notags(trim($_POST['dbuser']));
10         $dbpass = notags(trim($_POST['dbpass']));
11         $dbdata = notags(trim($_POST['dbdata']));
12         $timezone = notags(trim($_POST['timezone']));
13         $phpath = notags(trim($_POST['phpath']));
14
15         require_once("dba.php");
16
17         $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
18
19         if(mysqli_connect_errno()) {
20                 $db = new dba($dbhost, $dbuser, $dbpass, '', true);
21                 if(! mysql_connect_errno()) {
22                         $r = q("CREATE DATABASE '%s'",
23                                         dbesc($dbdata)
24                         );
25                         if($r) 
26                                 $db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
27                 }
28                 if(mysqli_connect_errno()) {
29                         notice( t('Could not create/connect to database.') . EOL);
30                         return;
31                 }
32         }
33
34         notice( t('Connected to database.') . EOL);
35
36         $tpl = load_view_file('view/htconfig.tpl');
37         $txt = replace_macros($tpl,array(
38                 '$dbhost' => $dbhost,
39                 '$dbuser' => $dbuser,
40                 '$dbpass' => $dbpass,
41                 '$dbdata' => $dbdata,
42                 '$timezone' => $timezone,
43                 '$phpath' => $phpath
44         ));
45         $result = file_put_contents('.htconfig.php', $txt);
46         if(! $result) {
47                 $a->data = $txt;
48         }
49
50         $errors = load_database($db);
51         if(! $errors) {
52                 // Our sessions normally are stored in the database. But as we have only managed 
53                 // to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so 
54                 // that you'll see the following important notice (which is stored in the session). 
55
56                 session_write_close();
57
58                 require_once('session.php');
59                 session_start();
60                 session_regenerate_id();
61
62                 $_SESSION['sysmsg'] = '';
63
64                 notice( t('Database import succeeded.') . EOL 
65                         . t('IMPORTANT: You will need to [manually] setup a scheduled task for the poller.') . EOL 
66                         . t('Please see the file INSTALL.') . EOL );
67                 goaway($a->get_baseurl() . '/register' );
68         }
69         else {
70                 $db = null; // start fresh
71                 notice( t('Database import failed.') . EOL
72                         . t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
73                         . t('Please see the file INSTALL.') . EOL );
74         }
75 }
76
77
78 function install_content(&$a) {
79
80         $o = '';
81
82         notice( t('Welcome to Friendika.') . EOL);
83
84
85         check_funcs();
86
87         $o .= check_htconfig();
88         if(strlen($o))
89                 return $o;
90
91         if(strlen($a->data)) {
92                 $o .= manual_config($a);
93                 return;
94         }
95
96         $o .= check_php($phpath);
97
98         require_once('datetime.php');
99
100         $tpl = load_view_file('view/install_db.tpl');
101         $o .= replace_macros($tpl, array(
102                 '$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
103                 '$submit' => t('Submit'),
104                 '$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
105                 '$dbuser' => notags(trim($_POST['dbuser'])),
106                 '$dbpass' => notags(trim($_POST['dbpass'])),
107                 '$dbdata' => notags(trim($_POST['dbdata'])),
108                 '$phpath' => $phpath
109         ));
110
111         return $o;
112 }
113
114 function check_php(&$phpath) {
115         $o = '';
116         $phpath = trim(shell_exec('which php'));
117         if(! strlen($phpath)) {
118                 $o .= t('Could not find a command line version of PHP in the web server PATH.');
119                 $o .= t('This is required. Please adjust the configuration file .htconfig.php accordingly.');
120         }
121         return $o;
122 }
123
124 function check_funcs() {
125         if((function_exists('apache_get_modules')) && (! in_array('mod_rewrite',apache_get_modules())))
126                 notice( t('Error: Apache webserver mod-rewrite module is required but not installed.') . EOL);
127         if(! function_exists('curl_init')) 
128                 notice( t('Error: libCURL PHP module required but not installed.') . EOL);
129         if(! function_exists('imagecreatefromjpeg')) 
130                 notice( t('Error: GD graphics PHP module with JPEG support required but not installed.') . EOL);
131         if(! function_exists('openssl_public_encrypt')) 
132                 notice( t('Error: openssl PHP module required but not installed.') . EOL);      
133         if(! function_exists('mysqli_connect')) 
134                 notice( t('Error: mysqli PHP module required but not installed.') . EOL);       
135         if((x($_SESSION,'sysmsg')) && strlen($_SESSION['sysmsg']))
136                 notice( t('Please see the file "INSTALL".') . EOL);
137 }
138
139
140 function check_htconfig() {
141
142         if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
143                 || (! is_writable('.'))) {
144
145                 $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.');
146                 $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.');
147                 $o .= t('Please check with your site documentation or support people to see if this situation can be corrected.');
148                 $o .= t('If not, you may be required to perform a manual installation. Please see the file "INSTALL" for instructions.'); 
149         }
150
151         return $o;
152 }
153
154         
155 function manual_config(&$a) {
156         $data = htmlentities($a->data);
157         $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.');
158         $o .= "<textarea rows=\"24\" cols=\"80\" >$data</textarea>";
159         return $o;
160 }
161
162
163 function load_database($db) {
164
165         $str = file_get_contents('database.sql');
166         $arr = explode(';',$str);
167         $errors = 0;
168         foreach($arr as $a) {
169                 if(strlen(trim($a))) {  
170                         $r = @$db->q(trim($a));
171                         if(! $r) {
172                                 notice( t('Errors encountered creating database tables.') . $a . EOL);
173                                 $errors ++;
174                         }
175                 }
176         }
177         return $errors;
178 }