Subversion Repositories oidplus

Rev

Rev 661 | Rev 700 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
635 daniel-mar 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
 
648 daniel-mar 20
include __DIR__ . '/../../../../vendor/danielmarschall/vnag/framework/vnag_framework.inc.php';
21
include __DIR__ . '/../../../../includes/oidplus.inc.php';
635 daniel-mar 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;
661 daniel-mar 65
                $out_msg  = 'Multiple version files/directories (oidplus_version.txt, .version.php, .git and .svn) are existing! Therefore, the version is ambiguous!'; // do not translate
635 daniel-mar 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();
648 daniel-mar 71
                $newest_version = getLatestRevision();
635 daniel-mar 72
 
73
                $requireInfo = ($installType === 'svn-wc') ? 'shell access with svn/svnversion tool, or PDO/SQLite3 PHP extension' : 'shell access with Git client'; // do not translate
74
                $updateCommand = ($installType === 'svn-wc') ? 'svn update' : 'git pull';
75
 
76
                if (!$newest_version) {
77
                        $out_stat = VNag::STATUS_UNKNOWN;
78
                        $out_msg  = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate
79
                } else if (!$local_installation) {
80
                        $out_stat = VNag::STATUS_UNKNOWN;
81
                        $out_msg  = 'OIDplus could not determine its version (Required: ' . $requireInfo . '). Please update your system manually via the "' . $updateCommand . '" command regularly.'; // do not translate
82
                } else if ($local_installation == $newest_version) {
83
                        $out_stat = VNag::STATUS_OK;
84
                        $out_msg  = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
85
                } else {
86
                        $out_stat = VNag::STATUS_WARNING;
87
                        $out_msg  = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
88
                }
89
        } else if ($installType === 'svn-snapshot') {
90
                $local_installation = OIDplus::getVersion();
648 daniel-mar 91
                $newest_version = getLatestRevision();
635 daniel-mar 92
 
93
                if (!$newest_version) {
94
                        $out_stat = VNag::STATUS_UNKNOWN;
95
                        $out_msg  = 'OIDplus could not determine the latest version. Probably the ViaThinkSoft server could not be reached.'; // do not translate
96
                } else if ($local_installation == $newest_version) {
97
                        $out_stat = VNag::STATUS_OK;
98
                        $out_msg  = 'You are using the latest version of OIDplus (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
99
                } else {
100
                        $out_stat = VNag::STATUS_WARNING;
101
                        $out_msg  = 'OIDplus is outdated. (' . $local_installation . ' local / ' . $newest_version . ' remote)'; // do not translate
102
                }
103
        } else {
104
                assert(false);
105
                die();
106
        }
107
 
108
        @file_put_contents($cache_file, serialize(array($out_stat, $out_msg)));
109
}
110
 
111
$job = new VNagMonitorDummy($out_stat, $out_msg);
112
if (OIDplus::config()->getValue('vnag_version_check_password_protected','1') == '1') {
113
        $job->http_visual_output = VNag::OUTPUT_NEVER;
114
        $job->password_out = OIDplusPageAdminVNagVersionCheck::vnag_password();
115
        $job->outputHTML(_L('This page contains an encrypted VNag machine-readable status.'));
116
} else {
117
        $job->http_visual_output = VNag::OUTPUT_ALWAYS;
118
}
119
if (OIDplus::getPkiStatus()) {
120
        $job->privkey = OIDplus::config()->getValue('oidplus_private_key');
121
}
122
$job->run();
123
unset($job);
648 daniel-mar 124
 
125
# ---
126
 
127
function getLatestRevision() {
128
        try {
699 daniel-mar 129
                $url = OIDplus::getEditionInfo()['revisionlog'];
130
                OIDplus::getEditionInfo()
648 daniel-mar 131
                $cont = @file_get_contents($url);
132
                if ($cont === false) return false;
133
                $ary = @unserialize($cont);
134
                if ($ary === false) return false;
135
                krsort($ary);
136
                $max_rev = array_keys($ary)[0];
137
                return 'svn-' . $max_rev;
138
        } catch (Exception $e) {
139
                return false;
140
        }
141
}
142