-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-owncloud.php
290 lines (235 loc) · 7.74 KB
/
setup-owncloud.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
/**
* ownCloud setup wizard
*
* @author Frank Karlitschek
* @copyright 2012 Frank Karlitschek [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Please copy this file into your webserver root and open it with a browser. The setup wizard checks the dependency, downloads the newest ownCloud version, unpacks it and redirects to the ownCloud first run wizard.
*/
// init
ob_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set('display_errors', 1);
@set_time_limit(0);
/**
* @brief Setup class with a few helper functions
*
*/
class oc_setup {
/**
* @brief Checks if all the ownCloud dependencies are installed
* @return string with error messages
*/
static public function checkdependencies() {
$error='';
// do we have PHP 5.3.2 or newer?
if(version_compare(PHP_VERSION, '5.3.2', '<')) {
$error.='PHP 5.3.2 is required. Please ask your server administrator to update PHP to version 5.3.2 or higher. PHP 5.2 is no longer supported by ownCloud and the PHP community.';
}
// do we have the zip module?
if(!class_exists('ZipArchive')){
$error.='PHP module zip not installed. Please ask your server administrator to install the module.';
}
// do we have the curl module?
if(!function_exists('curl_exec')){
$error.='PHP module curl not installed. Please ask your server administrator to install the module.';
}
// do we have write permission?
if(!is_writable('.')) {
$error.='Can\'t write to the current directory. Please fix this by giving the webserver user write access to the directory.';
}
// is safe_mode enabled?
if(ini_get('safe_mode')) {
$error.='PHP Safe Mode is enabled. ownCloud requires that it is disabled to work properly.';
}
return($error);
}
/**
* @brief Check the cURL version
* @return bool status of CURLOPT_CERTINFO implementation
*/
static public function iscertinfoavailable(){
$curlDetails = curl_version();
return version_compare($curlDetails['version'], '7.19.1') != -1;
}
/**
* @brief Performs the ownCloud install.
* @return string with error messages
*/
static public function install() {
$error='';
// downloading latest release
$error.=oc_setup::getfile('https://download.owncloud.org/download/community/owncloud-latest.zip','oc.zip');
// unpacking into owncloud folder
$zip = new ZipArchive;
$res = $zip->open('oc.zip');
if ($res==true) {
// Extract it to the tmp dir
$owncloud_tmp_dir = 'tmp-owncloud'.time();
$zip->extractTo($owncloud_tmp_dir);
$zip->close();
// Move it to the folder
rename($owncloud_tmp_dir.'/owncloud', "./".$_GET['directory']);
// Delete the tmp folder
rmdir($owncloud_tmp_dir);
} else {
$error.='unzip of owncloud source file failed.<br />';
}
// deleting zip file
$result=@unlink('oc.zip');
if($result==false) $error.='deleting of oc.zip failed.<br />';
return($error);
}
/**
* @brief Downloads a file and stores it in the local filesystem
* @param url $url
* @param path $path
* @return string with error messages
*/
static public function getfile($url,$path) {
$error='';
$fp = fopen ($path, 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if (oc_setup::iscertinfoavailable()){
curl_setopt($ch, CURLOPT_CERTINFO, TRUE);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
$data=curl_exec($ch);
$curlerror=curl_error($ch);
curl_close($ch);
fclose($fp);
if($data==false){
$error.='download of ownCloud source file failed.<br />'.$curlerror;
}
return($error.$curlerror);
}
/**
* @brief Shows the html header of the setup page
*/
static public function showheader(){
echo('
<!DOCTYPE html>
<html>
<head>
<title>ownCloud Setup</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/png" href="http://owncloud.org/setupwizard/favicon.png" />
<link rel="stylesheet" href="http://owncloud.org/setupwizard/styles.css" type="text/css" media="screen" />
</head>
<body id="body-login">
');
}
/**
* @brief Shows the html footer of the setup page
*/
static public function showfooter(){
echo('
<footer><p class="info"><a href="http://owncloud.org/">ownCloud</a> – web services under your control</p></footer>
</body>
</html>
');
}
/**
* @brief Shows the html content part of the setup page
* @param title $title
* @param content $content
* @param nextpage $nextpage
*/
static public function showcontent($title,$content,$nextpage=''){
echo('
<div id="login">
<header><div id="header">
<img src="http://owncloud.org/setupwizard/logo.png" alt="ownCloud" />
</div></header><br />
<p style="text-align:center; font-size:28px; color:#444; font-weight:bold;">'.$title.'</p><br />
<p style="text-align:center; font-size:13px; color:#666; font-weight:bold; ">'.$content.'</p>
<form method="get">
<input type="hidden" name="step" value="'.$nextpage.'" />
');
if($nextpage === 2) {
echo ('Install in subdirectory: <input type="text" name="directory" value="owncloud" required="required"/>');
}
if($nextpage === 3) {
echo ('<input type="hidden" value="'.$_GET['directory'].'" name="directory" />');
}
if($nextpage<>'') echo('<input type="submit" id="submit" class="login" style="margin-right:100px;" value="Next" />');
echo('
</form>
</div>
');
}
/**
* @brief Shows the wecome screen of the setup wizard
*/
static public function showwelcome(){
$txt='Welcome to the ownCloud Setup Wizard.<br />This wizard will check the ownCloud dependencies, download the newest version of ownCloud and install it in a few simple steps.';
oc_setup::showcontent('Setup Wizard',$txt,1);
}
/**
* @brief Shows the check dependencies screen
*/
static public function showcheckdependencies(){
$error=oc_setup::checkdependencies();
if($error=='') {
$txt='All ownCloud dependencies found';
oc_setup::showcontent('Dependency check',$txt,2);
}else{
$txt='Dependencies not found.<br />'.$error;
oc_setup::showcontent('Dependency check',$txt);
}
}
/**
* @brief Shows the install screen
*/
static public function showinstall(){
$error=oc_setup::install();
if($error=='') {
$txt='ownCloud is now installed';
oc_setup::showcontent('Success',$txt,3);
}else{
$txt='ownCloud is NOT installed<br />'.$error;
oc_setup::showcontent('Error',$txt);
}
}
/**
* @brief Shows the redirect screen
*/
static public function showredirect(){
// delete own file
@unlink($_SERVER['SCRIPT_FILENAME']);
// redirect to ownCloud
header("Location: ".$_GET['directory']);
}
}
// read the step get variable
if(isset($_GET['step'])) $step=$_GET['step']; else $step=0;
// show the header
oc_setup::showheader();
// show the right step
if ($step==0) oc_setup::showwelcome();
elseif ($step==1) oc_setup::showcheckdependencies();
elseif ($step==2) oc_setup::showinstall();
elseif ($step==3) oc_setup::showredirect();
else echo('Internal error. Please try again.');
// show the footer
oc_setup::showfooter();
?>