Please contact your server administrator to install the missing modules.
';
+ }
+
+ // 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. ';
+ }
+
+ return($error);
+ }
+
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Performs the Nextcloud install.
+ * @return string with error messages
+ */
+ static public function install() {
+ $error = '';
+ $directory = trim($_GET['directory']);
+
+ // Test if folder already exists
+ if(file_exists('./'.$directory.'/status.php')) {
+ return 'The selected folder seems to already contain a Nextcloud installation. - You cannot use this script to update existing installations.';
+ }
+
+ // downloading latest release
+ if (!file_exists('nc.zip')) {
+ $error .= Setup::getFile('https://download.nextcloud.com/server/releases/'.NC_VERSION.'.zip','nc.zip');
+ }
+
+ // unpacking into nextcloud folder
+ $zip = new ZipArchive;
+ $res = $zip->open('nc.zip');
+ if ($res==true) {
+ // Extract it to the tmp dir
+ $nextcloud_tmp_dir = 'tmp-nextcloud'.time();
+ $zip->extractTo($nextcloud_tmp_dir);
+ $zip->close();
+
+ // Move it to the folder
+ if ($_GET['directory'] === '.') {
+ foreach (array_diff(scandir($nextcloud_tmp_dir.'/nextcloud'), array('..', '.')) as $item) {
+ rename($nextcloud_tmp_dir.'/nextcloud/'.$item, './'.$item);
+ }
+ rmdir($nextcloud_tmp_dir.'/nextcloud');
+ } else {
+ rename($nextcloud_tmp_dir.'/nextcloud', './'.$directory);
+ }
+ // Delete the tmp folder
+ rmdir($nextcloud_tmp_dir);
+ } else {
+ $error.='unzip of nextcloud source file failed. ';
+ }
+
+ // deleting zip file
+ $result=@unlink('nc.zip');
+ if($result==false) $error.='deleting of nc.zip failed. ';
+ return($error);
+ }
+
+
+ /**
+ * Downloads a file and stores it in the local filesystem
+ * @param string $url
+ * @param string$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 (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 Nextcloud source file failed. '.$curlError;
+ }
+ return($error.$curlError);
+
+ }
+
+
+ /**
+ * Shows the html header of the setup page
+ */
+ static public function showHeader() {
+ echo('
+
+
+
+ Nextcloud Setup
+
+
+
+
+
+
+
+
+
+ ');
+ }
+
+
+ /**
+ * Shows the html footer of the setup page
+ */
+ static public function showFooter() {
+ echo('
+
+
+
+ ');
+ }
+
+
+ /**
+ * Shows the html content part of the setup page
+ * @param string $title
+ * @param string $content
+ * @param string $nextpage
+ */
+ static public function showContent($title, $content, $nextpage=''){
+ echo('
+
+
+
+
+
+
+
+
+
'.$title.'
+
+
+
+
+ ');
+ }
+
+ /**
+ * JS function to check if user deleted this script
+ * N.B. We can't reload the page to check this with PHP:
+ * once script is deleted we end up with 404
+ */
+ static public function showJsValidation(){
+ echo '
+
+ ';
+ }
+
+
+ /**
+ * Shows the welcome screen of the setup wizard
+ */
+ static public function showWelcome() {
+ $txt='Welcome to the Setup Wizard for Nextcloud!
This wizard will: 1. Check the server dependencies 2. Download Nextcloud 3. Install Nextcloud in a few simple steps';
+ Setup::showContent('Setup Wizard',$txt,1);
+ }
+
+
+ /**
+ * Shows the check dependencies screen
+ */
+ static public function showCheckDependencies() {
+ $error=Setup::checkDependencies();
+ if($error=='') {
+ $txt='All Nextcloud dependencies found';
+ Setup::showContent('Dependency check',$txt,2);
+ }else{
+ $txt='Dependencies not found. '.$error;
+ Setup::showContent('Dependency check',$txt);
+ }
+ }
+
+
+ /**
+ * Shows the install screen
+ */
+ static public function showInstall() {
+ $error=Setup::install();
+
+ if($error=='') {
+ $txt='Nextcloud is now installed';
+ Setup::showContent('Success',$txt,3);
+ }else{
+ $txt='Nextcloud is NOT installed '.$error;
+ Setup::showContent('Error',$txt);
+ }
+ }
+
+ /**
+ * Shows the redirect screen
+ */
+ static public function showRedirect() {
+ // delete own file
+ @unlink(__FILE__);
+ clearstatcache();
+ if (file_exists(__FILE__)){
+ Setup::showJsValidation();
+ Setup::showContent(
+ 'Warning',
+ 'Failed to remove installer script. Please remove ' . __FILE__ . ' manually',
+ 3
+ );
+ } else {
+ // redirect to Nextcloud
+ header("Location: " . $_GET['directory']);
+ }
+ }
+
+}
+
+
+// read the step get variable
+$step = isset($_GET['step']) ? $_GET['step'] : 0;
+
+// show the header
+Setup::showHeader();
+
+// show the right step
+if ($step==0) Setup::showWelcome();
+elseif ($step==1) Setup::showCheckDependencies();
+elseif ($step==2) Setup::showInstall();
+elseif ($step==3) Setup::showRedirect();
+else echo('Internal error. Please try again.');
+
+// show the footer
+Setup::showFooter();