-
Notifications
You must be signed in to change notification settings - Fork 24
/
postinstall.php
212 lines (195 loc) · 6.75 KB
/
postinstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
set_time_limit(0);
$rewrite_config=false;
include('config.php');
function row2text($row)
{
$text='';
$flag=0;
$i=0;
foreach ($row as $var=>$val)
{
if($flag==1)
$text.=", ";
elseif($flag==2)
$text.=",\n";
$flag=1;
//Variable
if(is_numeric($var))
if($var{0}=='0')
$text.="'$var'=>";
else
{
if($var!==$i)
$text.="$var=>";
$i=$var;
}
else
$text.="'$var'=>";
$i++;
//letter
if(is_array($val))
{
$text.="array(".row2text($val).")";
$flag=2;
}
else
$text.="\"$val\"";
}
return($text);
}
function display_message($msg)
{
global $contents;
$contents.=$msg;
echo $msg;
}
function check_cache()
{
if (file_exists('postinstall_results.res'))
if (time()-filemtime('postinstall_results.res')<120) { echo file_get_contents('postinstall_results.res'); exit; }
}
check_cache();
$contents='';
//Check username and private key
display_message("Checking username and private key... ");
if (empty($openinviter_settings['username']) OR empty($openinviter_settings['private_key']))
{
display_message("Username or private key missing.Get your own at <a href='http://openinviter.com/register.php'>OpenInviter</a><br>\n");
exit;
}
else display_message("*OK*<br>\n");
//Check PHP version
display_message("Checking PHP version... ");
if (version_compare(PHP_VERSION, '5.0.0', '<')) { display_message("*NOT OK* - OpenInviter requires PHP5, your server has PHP ".PHP_VERSION." installed");exit; }
else display_message("*OK*<br>\n");
//Check support for DOMDocument
display_message("Checking DOMDocument support... ");
if (!extension_loaded('dom') OR !class_exists('DOMDocument')) { display_message("*NOT OK* - OpenInviter will not run correctly on this system.");exit; }
else display_message("*OK*<br>\n");
//Check transport type
$transport='curl';
display_message("Checking transport method... ");
if (!extension_loaded('curl') OR !function_exists('curl_init'))
{
$transport='wget';
passthru("wget --version",$return_var);
if ($return_var!=0)
{
display_message("Neither <b>libcurl</b> nor <b>wget</b> is installed.<br>\nYou will not be able to use OpenInviter.");
exit;
}
else display_message("<b>wget</b> is installed. Using <b>Wget</b> to handle requests<br>\n");
}
else display_message("<b>libcurl</b> is installed. Using <b>cURL</b> to handle requests<br>\n");
if ($openinviter_settings['transport']!=$transport) { $rewrite_config=true;$openinviter_settings['transport']=$transport; }
//Check if stats are available
if (!extension_loaded('SQLite') OR !function_exists('sqlite_open'))
{
$stats=false;
display_message("<b>SQLite</b> is NOT installed. Unable to keep stats. This will not affect the OpenInviter modules since they will run without keeping any stats.<br>\n");
}
else
{
$stats=true;
display_message("<b>SQLite</b> is installed. Stats enabled. Please define a stats username and password in config.php<br>\n");
}
if ($openinviter_settings['stats']!=$stats) { $rewrite_config=true;$openinviter_settings['stats']=$stats; }
//Check permisions
$cookie_path='/tmp';
display_message("Checking write permisions... ");
if (!is_writable("{$cookie_path}"))
{
$cookie_path = session_save_path();
if (strpos ($cookie_path, ";") !== FALSE)
$cookie_path = substr ($cookie_path, strpos ($cookie_path, ";")+1);
if (empty($cookie_path)) $cookie_path='/tmp';
if (!is_writable("{$cookie_path}"))
{
display_message("The <b>{$cookie_path}</b> folder is not writable. You will have to manually define a location for logs and temporary files in <b>config.php</b><br>\n");
exit;
}
else display_message("<b>{$cookie_path}</b> is writable. Using <b>{$cookie_path}</b> to store cookie files and logs<br>\n");
}
else display_message("<b>{$cookie_path}</b> is writable. Using <b>{$cookie_path}</b> to store cookie files and logs<br>\n");
if ($openinviter_settings['cookie_path']!=$cookie_path) { $rewrite_config=true;$openinviter_settings['cookie_path']=$cookie_path; }
//Write new config file if required
if ($rewrite_config)
{
$file_contents="<?php\n";
$file_contents.="\$openinviter_settings=array(\n".row2text($openinviter_settings).");\n";
$file_contents.="?>";
file_put_contents('config.php',$file_contents);
}
//Instantiate OpenInviter
include('openinviter.php');
$inviter=new OpenInviter();
class PostInstall extends OpenInviter_Base
{
public function login($user,$pass)
{
return;
}
public function getMyContacts()
{
return;
}
public function logout()
{
return;
}
public function checkVersion()
{
$this->init();
$res=$this->get("http://update.openinviter.com/updater/check_version.php?key={$this->settings['private_key']}");
$this->stopPlugin();
return $res;
}
public function check($url)
{
$this->init();
$res=$this->get($url);
$this->stopPlugin();
if (empty($res)) return false; else return true;
}
}
$checker=new PostInstall();
$checker->settings=$inviter->settings;
$checker->service_user='postInstall';
$checker->service_pass='postInstall';
$checker->service='postInstall';
//Check version
display_message("Checking for new versions of OpenInviter... ");
$xml=$checker->checkVersion();
libxml_use_internal_errors(true);
$parsed_xml=simplexml_load_string($xml);
libxml_use_internal_errors(false);
if (!$parsed_xml)
display_message("Could not connect to server<br>\n");
else
{
$server_version=(string)$parsed_xml;
$version=$inviter->getVersion();
if (!$inviter->checkVersion($server_version)) display_message("You are using OpenInviter <b>{$version}</b> but version <b>{$server_version}</b> is available for download - <a href='http://openinviter.com/download.php'>Download newer version</a><br>\n");
else display_message("Your OpenInviter software is up-to-date<br>\n");
}
//Check plugins
if ($openinviter_settings['hosted'])
{
display_message("Running in `Hosted` mode...");
display_message("Checking OpenInviter Hosted Solution server...");
if ($checker->check('http://hosted.openinviter.com')) display_message("*OK*<br>\n"); else display_message("*NOT OK* - You might not be able to use the OpenInviter Hosted Solution");
}
else
{
$plugins=$inviter->getPlugins();
foreach ($plugins as $type=>$dummy)
foreach ($dummy as $plugin=>$details)
{
display_message("Checking {$details['name']}... ");
if ($checker->check($details['check_url'])) display_message("*OK*<br>\n"); else display_message("*NOT OK* - This plugin might not work correctly on your system<br>\n");
}
}
display_message("<br><b>WARNING:</b> Delete postinstall.php before running OpenInviter. Also please note that you cannot run postinstall.php again for 2 minutes.");
file_put_contents('postinstall_results.res',$contents);
?>