Subversion Repositories oidplus

Rev

Rev 493 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 Daniel Marschall, ViaThinkSoft
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  *
  11.  *     http://www.apache.org/licenses/LICENSE-2.0
  12.  *
  13.  * Unless required by applicable law or agreed to in writing, software
  14.  * distributed under the License is distributed on an "AS IS" BASIS,
  15.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16.  * See the License for the specific language governing permissions and
  17.  * limitations under the License.
  18.  */
  19.  
  20. declare(ticks=1);
  21.  
  22. @set_time_limit(0);
  23.  
  24. require_once __DIR__ . '/../includes/oidplus.inc.php';
  25.  
  26. // Note: we don't want to use OIDplus::init() in this updater (it should be independent as much as possible)
  27. OIDplus::baseConfig(); // This call will redirect to setup if userdata/baseconfig/config.inc.php is missing
  28.  
  29. define('OIDPLUS_REPO', 'https://svn.viathinksoft.com/svn/oidplus');
  30.  
  31. ?><!DOCTYPE html>
  32. <html lang="en">
  33.  
  34. <head>
  35.         <title><?php echo _L('OIDplus Update'); ?></title>
  36.         <meta name="robots" content="noindex">
  37.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  38.         <link rel="stylesheet" href="../setup/setup.min.css.php">
  39.         <?php
  40.         if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
  41.         ?>
  42.         <script src="https://www.google.com/recaptcha/api.js"></script>
  43.         <?php
  44.         }
  45.         ?>
  46. </head>
  47.  
  48. <body>
  49.  
  50. <?php
  51.  
  52. echo '<h1>'._L('Update OIDplus').'</h1>';
  53.  
  54. if (isset($_REQUEST['update_now'])) {
  55.         if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
  56.                 $secret = OIDplus::baseConfig()->getValue('RECAPTCHA_PRIVATE', '');
  57.                 $response = $_POST["g-recaptcha-response"];
  58.                 $verify = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$secret}&response={$response}");
  59.                 $captcha_success = json_decode($verify);
  60.         }
  61.         if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false) && ($captcha_success->success==false)) {
  62.                 echo '<p><font color="red"><b>'._L('CAPTCHA not successfully verified').'</b></font></p>';
  63.                 echo '<p><a href="index.php">'._L('Try again').'</a></p>';
  64.         } else {
  65.                 if (!OIDplus::authUtils()->adminCheckPassword($_REQUEST['admin_password'])) {
  66.                         echo '<p><font color="red"><b>'._L('Wrong password').'</b></font></p>';
  67.                         echo '<p><a href="index.php">'._L('Try again').'</a></p>';
  68.                 } else {
  69.                         echo '<h2>'._L('Updating ...').'</h2>';
  70.  
  71.                         ob_start();
  72.                         try {
  73.                                 $svn = new phpsvnclient(OIDPLUS_REPO);
  74.                                 $svn->versionFile = 'oidplus_version.txt';
  75.                                 $svn->updateWorkingCopy(realpath(__DIR__.'/../oidplus_version.txt'), '/trunk', dirname(__DIR__), false);
  76.  
  77.                                 $cont = ob_get_contents();
  78.                                 $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
  79.                         } catch (Exception $e) {
  80.                                 $cont = _L('Error: %1',$e->getMessage());
  81.                         }
  82.                         ob_end_clean();
  83.  
  84.                         echo '<pre>'.$cont.'</pre>';
  85.  
  86.                         echo '<p><a href="index.php">'._L('Back to update page').'</a></p>';
  87.                         echo '<hr>';
  88.                 }
  89.         }
  90.  
  91. } else {
  92.  
  93.         class VNagMonitorDummy extends VNag {
  94.                 private $status;
  95.                 private $content;
  96.  
  97.                 public function __construct($status, $content) {
  98.                         parent::__construct();
  99.                         $this->status = $status;
  100.                         $this->content = $content;
  101.                 }
  102.  
  103.                 protected function cbRun($optional_args=array()) {
  104.                         $this->setStatus($this->status);
  105.                         $this->setHeadline($this->content);
  106.                 }
  107.         }
  108.  
  109.         echo '<p><u>'._L('There are three possibilities how to keep OIDplus up-to-date').':</u></p>';
  110.  
  111.         echo '<p><b>'._L('Method A').'</b>: '._L('Install OIDplus using the subversion tool in your SSH/Linux shell using the command <code>svn co %1</code> and update it regularly with the command <code>svn update</code> . This will automatically download the latest version and check for conflicts. Highly recommended if you have a Shell/SSH access to your webspace!',htmlentities(OIDPLUS_REPO).'/trunk').'</p>';
  112.  
  113.         echo '<p><b>'._L('Method B').'</b>: '._L('Install OIDplus using the Git client in your SSH/Linux shell using the command <code>git clone %1</code> and update it regularly with the command <code>git pull</code> . This will automatically download the latest version and check for conflicts. Highly recommended if you have a Shell/SSH access to your webspace!','https://github.com/danielmarschall/oidplus.git').'</p>';
  114.  
  115.         echo '<p><b>'._L('Method C').':</b> '._L('Install OIDplus by downloading a ZIP file from www.viathinksoft.com, which contains an SVN snapshot, and extract it to your webspace. The ZIP file contains a file named "oidplus_version.txt" which contains the SVN revision of the snapshot. This update-tool will then try to update your files on-the-fly by downloading them from the ViaThinkSoft SVN repository directly into your webspace directory. A change conflict detection is NOT implemented. It is required that the files on your webspace have create/write/delete permissions. Only recommended if you have no access to the SSH/Linux shell.').'</p>';
  116.  
  117.         echo '<hr>';
  118.  
  119.         $installType = OIDplus::getInstallType();
  120.  
  121.         if ($installType === 'ambigous') {
  122.                 echo '<font color="red">'.strtoupper(_L('Error')).': '._L('Multiple version files/directories (oidplus_version.txt, .git and .svn) are existing! Therefore, the version is ambiguous!').'</font>';
  123.                 $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, 'Multiple version files/directories (oidplus_version.txt, .git and .svn) are existing! Therefore, the version is ambiguous!'); // do not translate
  124.                 $job->http_visual_output = VNag::OUTPUT_NEVER;
  125.                 $job->run();
  126.                 unset($job);
  127.         } else if ($installType === 'unknown') {
  128.                 echo '<font color="red">'.strtoupper(_L('Error')).': '._L('The version cannot be determined, and the update needs to be applied manually!').'</font>';
  129.                 $job = new VNagMonitorDummy(VNag::STATUS_CRITICAL, 'The version cannot be determined, and the update needs to be applied manually!'); // do not translate
  130.                 $job->http_visual_output = VNag::OUTPUT_NEVER;
  131.                 $job->run();
  132.                 unset($job);
  133.         } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
  134.                 if ($installType === 'svn-wc') {
  135.                         echo '<p>'._L('You are using <b>method A</b> (SVN working copy).').'</p>';
  136.                 } else {
  137.                         echo '<p>'._L('You are using <b>method B</b> (Git working copy).').'</p>';
  138.                 }
  139.  
  140.                 $local_installation = OIDplus::getVersion();
  141.                 try {
  142.                         $svn = new phpsvnclient(OIDPLUS_REPO);
  143.                         $newest_version = 'svn-'.$svn->getVersion();
  144.                 } catch (Exception $e) {
  145.                         $newest_version = false;
  146.                 }
  147.  
  148.                 echo _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
  149.                 echo _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
  150.  
  151.                 $requireInfo = ($installType === 'svn-wc') ? _L('shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension') : _L('shell access with Git client');
  152.                 $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
  153.  
  154.                 if (!$newest_version) {
  155.                         echo '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
  156.                 }
  157.                 else if (!$local_installation) {
  158.                         echo '<p><font color="red">'._L('OIDplus could not determine its version. (Required: %1). Please update your system manually via the "%2" command regularly.',$requireInfo,$updateCommand).'</font></p>';
  159.  
  160.                         $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus could not determine its version. Please update your system manually via the "'.$updateCommand.'" command regularly.'); // do not translate
  161.                         $job->http_visual_output = VNag::OUTPUT_NEVER;
  162.                         $job->run();
  163.                         unset($job);
  164.                 } else if ($local_installation == $newest_version) {
  165.                         echo '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
  166.  
  167.                         $job = new VNagMonitorDummy(VNag::STATUS_OK, 'You are using the latest version of OIDplus ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
  168.                         $job->http_visual_output = VNag::OUTPUT_NEVER;
  169.                         $job->run();
  170.                         unset($job);
  171.                 } else {
  172.                         echo '<p><font color="blue">'._L('Please enter %1 into the SSH shell to update OIDplus to the latest version.','<code>'.$updateCommand.'</code>').'</font></p>';
  173.  
  174.                         echo '<h2>'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
  175.  
  176.                         ob_start();
  177.                         try {
  178.                                 $svn = new phpsvnclient(OIDPLUS_REPO);
  179.                                 $svn->updateWorkingCopy(str_replace('svn-', '', $local_installation), '/trunk', realpath(__DIR__.'/../'), true);
  180.                                 $cont = ob_get_contents();
  181.                                 $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
  182.                         } catch (Exception $e) {
  183.                                 $cont = _L('Error: %1',$e->getMessage());
  184.                         }
  185.                         ob_end_clean();
  186.  
  187.                         echo '<pre>'.$cont.'</pre>';
  188.  
  189.                         $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus is outdated. ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
  190.                         $job->http_visual_output = VNag::OUTPUT_NEVER;
  191.                         $job->run();
  192.                         unset($job);
  193.                 }
  194.         } else if ($installType === 'svn-snapshot') {
  195.                 echo '<p>'._L('You are using <b>method C</b> (Snapshot ZIP file with oidplus_version.txt file).').'</p>';
  196.  
  197.                 $local_installation = OIDplus::getVersion();
  198.                 try {
  199.                         $svn = new phpsvnclient(OIDPLUS_REPO);
  200.                         $newest_version = 'svn-'.$svn->getVersion();
  201.                 } catch (Exception $e) {
  202.                         $newest_version = false;
  203.                 }
  204.  
  205.                 echo _L('Local installation: %1',($local_installation ? $local_installation : _L('unknown'))).'<br>';
  206.                 echo _L('Latest published version: %1',($newest_version ? $newest_version : _L('unknown'))).'<br>';
  207.  
  208.                 if (!$newest_version) {
  209.                         echo '<p><font color="red">'._L('OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.').'</font></p>';
  210.                 }
  211.                 else if ($local_installation == $newest_version) {
  212.                         echo '<p><font color="green">'._L('You are already using the latest version of OIDplus.').'</font></p>';
  213.  
  214.                         $job = new VNagMonitorDummy(VNag::STATUS_OK, 'You are using the latest version of OIDplus ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
  215.                         $job->http_visual_output = VNag::OUTPUT_NEVER;
  216.                         $job->run();
  217.                         unset($job);
  218.                 } else {
  219.                         echo '<p><font color="blue">'._L('To update your OIDplus system, please enter the administrator password and click the button "Update NOW".').'</font></p>';
  220.                         echo '<p><font color="red">'.strtoupper(_L('Warning')).': '._L('Please make a backup of your files before updating. In case of an error, the OIDplus system (including this update-assistant) might become unavailable. Also, since the web-update does not contain collision-detection, changes you have applied (like adding, removing or modified files) might get reverted/lost! In case the update fails, you can download and extract the complete <a href="https://www.viathinksoft.com/projects/oidplus">SVN-Snapshot ZIP file</a> again. Since all your data should lay inside the folder "userdata", this should be safe.').'</font></p>';
  221.                         echo '<form method="POST" action="index.php">';
  222.  
  223.                         if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
  224.                                 echo '<noscript>';
  225.                                 echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>';
  226.                                 echo '</noscript>';
  227.                                 echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
  228.                                 echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
  229.                         }
  230.  
  231.                         echo '<input type="hidden" name="update_now" value="1">';
  232.                         echo '<input type="password" name="admin_password">';
  233.                         echo '<input type="submit" value="'._L('Update NOW').'">';
  234.                         echo '</form>';
  235.  
  236.                         echo '<h2>'._L('Preview of update %1 &rarr; %2',$local_installation,$newest_version).'</h2>';
  237.  
  238.                         ob_start();
  239.                         try {
  240.                                 $svn = new phpsvnclient(OIDPLUS_REPO);
  241.                                 $svn->updateWorkingCopy(realpath(__DIR__.'/../oidplus_version.txt'), '/trunk', realpath(__DIR__.'/../'), true);
  242.                                 $cont = ob_get_contents();
  243.                                 $cont = str_replace(realpath(__DIR__.'/../'), '...', $cont);
  244.                         } catch (Exception $e) {
  245.                                 $cont = _L('Error: %1',$e->getMessage());
  246.                         }
  247.                         ob_end_clean();
  248.  
  249.                         echo '<pre>'.$cont.'</pre>';
  250.  
  251.                         $job = new VNagMonitorDummy(VNag::STATUS_WARNING, 'OIDplus is outdated. ('.$local_installation.' local / '.$newest_version.' remote)'); // do not translate
  252.                         $job->http_visual_output = VNag::OUTPUT_NEVER;
  253.                         $job->run();
  254.                         unset($job);
  255.                 }
  256.         }
  257.  
  258.         echo '<hr>';
  259.  
  260.         echo '<p><input type="button" onclick="document.location=\'../\'" value="'._L('Go back to OIDplus').'"></p>';
  261.  
  262.         echo '<br><h2>'._L('File Completeness Check').'</h2>';
  263.  
  264.         echo '<p>'._L('With this optional tool, you can check if your OIDplus installation is complete and no files are missing.').'</p>';
  265.  
  266.         echo '<p>'._L('Please enter your administrator password to run the tool.').'</p>';
  267.  
  268.         echo '<form method="POST" action="check.php">';
  269.         if (OIDplus::baseConfig()->getValue('RECAPTCHA_ENABLED', false)) {
  270.                 echo '<noscript>';
  271.                 echo '<p><font color="red">'._L('You need to enable JavaScript to solve the CAPTCHA.').'</font></p>';
  272.                 echo '</noscript>';
  273.                 echo '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'" }); </script>';
  274.                 echo '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.OIDplus::baseConfig()->getValue('RECAPTCHA_PUBLIC', '').'"></div>';
  275.         }
  276.         if (!isset($local_installation)) $local_installation = 'svn-';
  277.         echo '<input type="hidden" name="svn_version" value="'.(substr($local_installation,strlen('svn-'))).'">';
  278.         echo '<input type="password" name="admin_password">';
  279.         echo '<input type="submit" value="'._L('Check').'">';
  280.         echo '<p>'._L('Attention: This will take some time!').'</p>';
  281.         echo '</form>';
  282.  
  283.         echo '<h2>'._L('VNag integration').'</h2>';
  284.  
  285.         echo '<p>'._L('Did you know that this page contains an invisible VNag tag? You can watch this page using the "webreader" plugin of VNag, and then monitor it with any Nagios compatible software! <a href="https://www.viathinksoft.com/projects/vnag">More information</a>.').'</p>';
  286. }
  287.  
  288. ?>
  289.  
  290. </body>
  291. </html>
  292.