Subversion Repositories oidplus

Rev

Rev 648 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. /*
  4.  * OIDplus 2.0
  5.  * Copyright 2019 - 2021 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. include '../../../../vendor/danielmarschall/vnag/framework/vnag_framework.inc.php';
  21. include '../../../../includes/oidplus.inc.php';
  22.  
  23. define('OIDPLUS_VNAG_MAX_CACHE_AGE', 60); // seconds (TODO: in base config?)
  24.  
  25. OIDplus::init(false);
  26.  
  27. if (OIDplus::baseConfig()->getValue('DISABLE_PLUGIN_OIDplusPageAdminVNagVersionCheck', false)) {
  28.         throw new OIDplusException(_L('This plugin was disabled by the system administrator!'));
  29. }
  30.  
  31. class VNagMonitorDummy extends VNag {
  32.  
  33.         private $status;
  34.  
  35.         private $content;
  36.  
  37.         public function __construct($status, $content) {
  38.                 parent::__construct();
  39.                 $this->status = $status;
  40.                 $this->content = $content;
  41.         }
  42.  
  43.         protected function cbRun($optional_args = array()) {
  44.                 $this->setStatus($this->status);
  45.                 $this->setHeadline($this->content);
  46.         }
  47. }
  48.  
  49. $cache_file = OIDplus::localpath() . 'userdata/cache/vnag_version_check.ser';
  50.  
  51. if ((file_exists($cache_file)) && (time()-filemtime($cache_file) <= OIDPLUS_VNAG_MAX_CACHE_AGE)) {
  52.         // Anti DoS
  53.  
  54.         // TODO: There is a small flaw: If the admin fails to secure the "cache/" folder
  55.         //       from the public, then people can read the version file, even if the
  56.         //       VNag script is intended to be protected by a vnag_password.
  57.         list($out_stat, $out_msg) = unserialize(file_get_contents($cache_file));
  58.  
  59. } else {
  60.  
  61.         $installType = OIDplus::getInstallType();
  62.  
  63.         if ($installType === 'ambigous') {
  64.                 $out_stat = VNag::STATUS_UNKNOWN;
  65.                 $out_msg  = 'Multiple version files/directories (oidplus_version.txt, .git and .svn) are existing! Therefore, the version is ambiguous!'; // do not translate
  66.         } else if ($installType === 'unknown') {
  67.                 $out_stat = VNag::STATUS_UNKNOWN;
  68.                 $out_msg  = 'The version cannot be determined, and the update needs to be applied manually!'; // do not translate
  69.         } else if (($installType === 'svn-wc') || ($installType === 'git-wc')) {
  70.                 $local_installation = OIDplus::getVersion();
  71.                 try {
  72.                         $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
  73.                         $newest_version = 'svn-' . $svn->getVersion();
  74.                 } catch (Exception $e) {
  75.                         $newest_version = false;
  76.                 }
  77.  
  78.                 $requireInfo = ($installType === 'svn-wc') ? 'shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension' : 'shell access with Git client'; // do not translate
  79.                 $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
  80.  
  81.                 if (!$newest_version) {
  82.                         $out_stat = VNag::STATUS_UNKNOWN;
  83.                         $out_msg  = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate
  84.                 } else if (!$local_installation) {
  85.                         $out_stat = VNag::STATUS_UNKNOWN;
  86.                         $out_msg  = 'OIDplus could not determine its version (Required: ' . $requireInfo . '). Please update your system manually via the "' . $updateCommand . '" command regularly.'; // do not translate
  87.                 } else if ($local_installation == $newest_version) {
  88.                         $out_stat = VNag::STATUS_OK;
  89.                         $out_msg  = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  90.                 } else {
  91.                         $out_stat = VNag::STATUS_WARNING;
  92.                         $out_msg  = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  93.                 }
  94.         } else if ($installType === 'svn-snapshot') {
  95.                 $local_installation = OIDplus::getVersion();
  96.                 try {
  97.                         $svn = new phpsvnclient(parse_ini_file(__DIR__.'/consts.ini')['svn']);
  98.                         $newest_version = 'svn-' . $svn->getVersion();
  99.                 } catch (Exception $e) {
  100.                         $newest_version = false;
  101.                 }
  102.  
  103.                 if (!$newest_version) {
  104.                         $out_stat = VNag::STATUS_UNKNOWN;
  105.                         $out_msg  = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate
  106.                 } else if ($local_installation == $newest_version) {
  107.                         $out_stat = VNag::STATUS_OK;
  108.                         $out_msg  = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  109.                 } else {
  110.                         $out_stat = VNag::STATUS_WARNING;
  111.                         $out_msg  = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
  112.                 }
  113.         } else {
  114.                 assert(false);
  115.                 die();
  116.         }
  117.  
  118.         @file_put_contents($cache_file, serialize(array($out_stat, $out_msg)));
  119. }
  120.  
  121. $job = new VNagMonitorDummy($out_stat, $out_msg);
  122. if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') {
  123.         $job->http_visual_output = VNag::OUTPUT_NEVER;
  124.         $job->password_out = OIDplusPageAdminVNagVersionCheck::vnag_password();
  125.         $job->outputHTML(_L('This page contains an encrypted VNag machine-readable status.'));
  126. } else {
  127.         $job->http_visual_output = VNag::OUTPUT_ALWAYS;
  128. }
  129. if (OIDplus::getPkiStatus()) {
  130.         $job->privkey = OIDplus::config()->getValue('oidplus_private_key');
  131. }
  132. $job->run();
  133. unset($job);
  134.