Rev 800 | Rev 906 | 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 | |||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
||
21 | |||
22 | class OIDplusPageAdminSystemFileCheck extends OIDplusPagePluginAdmin { |
||
23 | |||
24 | public function init($html=true) { |
||
25 | } |
||
26 | |||
27 | public function action($actionID, $params) { |
||
28 | } |
||
29 | |||
30 | public function gui($id, &$out, &$handled) { |
||
31 | $parts = explode('.',$id,2); |
||
32 | if (!isset($parts[1])) $parts[1] = ''; |
||
33 | if ($parts[0] == 'oidplus:system_file_check') { |
||
34 | @set_time_limit(0); |
||
35 | |||
36 | $handled = true; |
||
37 | $out['title'] = _L('System file check'); |
||
801 | daniel-mar | 38 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 39 | |
40 | if (!OIDplus::authUtils()->isAdminLoggedIn()) { |
||
800 | daniel-mar | 41 | $out['icon'] = 'img/error.png'; |
635 | daniel-mar | 42 | $out['text'] = '<p>'._L('You need to <a %1>log in</a> as administrator.',OIDplus::gui()->link('oidplus:login$admin')).'</p>'; |
43 | return; |
||
44 | } |
||
45 | |||
645 | daniel-mar | 46 | $out['text'] = '<p>'._L('This tool compares the checksums of the files of your OIDplus installation with the checksums of the OIDplus original SVN version.').'<br>'; |
47 | $out['text'] .= _L('Differences could have various reasons, for example, a hotfix you have applied.').'<br>'; |
||
48 | $out['text'] .= _L('The folders "userdata" and "userdata_pub" as well as third-party-plugins (folder "plugins" excluding "viathinksoft") are not listed.').'</p>'; |
||
635 | daniel-mar | 49 | $out['text'] .= '<p>'._L('Please note: If you believe that you were hacked, you should not trust the output of this tool, because it might be compromised, too.').'</p>'; |
50 | |||
51 | $ver = OIDplus::getVersion(); |
||
52 | if (substr($ver,0,4) !== 'svn-') { |
||
53 | $out['text'] = '<p><font color="red">'.strtoupper(_L('Error')).': '._L('Cannot determine version of the system').'</font></p>'; |
||
54 | return; |
||
55 | } |
||
56 | $ver = substr($ver,strlen('svn-')); |
||
57 | |||
58 | |||
59 | $out['text'] .= '<h2>'._L('Result (comparison with SVN revision %1)', $ver).'</h2>'; |
||
60 | |||
61 | $out['text'] .= '<pre>'; |
||
62 | |||
63 | try { |
||
64 | $mine = self::getDirContents(OIDplus::localpath()); |
||
699 | daniel-mar | 65 | $theirs = self::checksumFileToArray(sprintf(OIDplus::getEditionInfo()['checksum_file'],$ver)); |
654 | daniel-mar | 66 | if ($theirs === false) { |
67 | throw new OIDplusException(_L("Cannot download checksum file. Please try again later.")); |
||
68 | } |
||
635 | daniel-mar | 69 | |
70 | $num = 0; |
||
71 | |||
72 | foreach ($mine as $filename_old => $hash_old) { |
||
645 | daniel-mar | 73 | $filename_old = str_replace('\\', '/', $filename_old); |
635 | daniel-mar | 74 | if (!isset($theirs[$filename_old])) { |
75 | if ( |
||
76 | (substr($filename_old, 0, strlen('userdata/')) !== 'userdata/') && |
||
77 | (substr($filename_old, 0, strlen('userdata_pub/')) !== 'userdata_pub/') && |
||
645 | daniel-mar | 78 | |
79 | // Don't list third-party plugins |
||
80 | (( |
||
81 | (substr($filename_old, 0, strlen('plugins/')) === 'plugins/') && |
||
82 | ( |
||
83 | (explode('/',$filename_old)[1] === 'viathinksoft') || |
||
84 | (explode('/',$filename_old)[1] === 'index.html') || |
||
85 | (substr(explode('/',$filename_old)[1],-4) === '.xsd') |
||
86 | ) |
||
87 | ) || (substr($filename_old, 0, strlen('plugins/')) !== 'plugins/')) && |
||
88 | |||
89 | ($filename_old !== 'oidplus_version.txt') && |
||
661 | daniel-mar | 90 | ($filename_old !== '.version.php') && |
645 | daniel-mar | 91 | ($filename_old !== 'composer.lock') |
635 | daniel-mar | 92 | ){ |
93 | $num++; |
||
646 | daniel-mar | 94 | if (is_dir(OIDplus::localpath().$filename_old)) { |
95 | $out['text'] .= "<b>"._L('Additional directory').":</b> $filename_old\n"; |
||
96 | } else { |
||
97 | $out['text'] .= "<b>"._L('Additional file').":</b> $filename_old\n"; |
||
98 | } |
||
635 | daniel-mar | 99 | } |
100 | } |
||
101 | } |
||
102 | |||
103 | foreach ($theirs as $filename_new => $hash_new) { |
||
104 | if (!isset($mine[$filename_new])) { |
||
105 | $num++; |
||
106 | $out['text'] .= "<b>"._L('Missing file').":</b> $filename_new\n"; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | foreach ($mine as $filename_old => $hash_old) { |
||
111 | if (isset($theirs[$filename_old])) { |
||
112 | $hash_new = $theirs[$filename_old]; |
||
113 | if ($hash_old != $hash_new) { |
||
114 | $num++; |
||
115 | $out['text'] .= "<b>"._L('Checksum mismatch').":</b> $filename_old (<a target=\"_blank\" href=\"https://svn.viathinksoft.com/cgi-bin/viewvc.cgi/oidplus/trunk/$filename_old?revision=$ver&view=co\">"._L('Expected file contents')."</a>)\n"; |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | |||
120 | if ($num == 0) { |
||
121 | $out['text'] .= _L('Everything OK!'); |
||
122 | } |
||
123 | } catch (Exception $e) { |
||
124 | $out['text'] .= strtoupper(_L('Error')).': '.htmlentities($e->getMessage()); |
||
125 | } |
||
126 | |||
127 | $out['text'] .= '</pre>'; |
||
128 | } else { |
||
129 | $handled = false; |
||
130 | } |
||
131 | } |
||
132 | |||
133 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
||
134 | if (!OIDplus::authUtils()->isAdminLoggedIn()) return false; |
||
135 | |||
800 | daniel-mar | 136 | if (file_exists(__DIR__.'/img/main_icon16.png')) { |
801 | daniel-mar | 137 | $tree_icon = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png'; |
635 | daniel-mar | 138 | } else { |
139 | $tree_icon = null; // default icon (folder) |
||
140 | } |
||
141 | |||
142 | $json[] = array( |
||
143 | 'id' => 'oidplus:system_file_check', |
||
144 | 'icon' => $tree_icon, |
||
145 | 'text' => _L('System file check') |
||
146 | ); |
||
147 | |||
148 | return true; |
||
149 | } |
||
150 | |||
151 | public function tree_search($request) { |
||
152 | return false; |
||
153 | } |
||
154 | |||
155 | private static function getDirContents($dir, $basepath = null, &$results = array()) { |
||
156 | if (is_null($basepath)) $basepath = $dir; |
||
157 | $basepath = realpath($basepath) . DIRECTORY_SEPARATOR; |
||
158 | $dir = realpath($dir) . DIRECTORY_SEPARATOR; |
||
159 | $files = scandir($dir); |
||
160 | foreach ($files as $file) { |
||
161 | $path = realpath($dir . DIRECTORY_SEPARATOR . $file); |
||
162 | if (!is_dir($path)) { |
||
163 | $xpath = substr($path, strlen($basepath)); |
||
164 | $xpath = str_replace('\\', '/', $xpath); |
||
165 | $results[$xpath] = hash_file('sha256', $path); |
||
166 | } else if ($file != "." && $file != ".." && $file != ".svn" && $file != ".git") { |
||
167 | self::getDirContents($path, $basepath, $results); |
||
168 | $xpath = substr($path, strlen($basepath)); |
||
169 | $xpath = str_replace('\\', '/', $xpath); |
||
170 | $results[$xpath] = hash('sha256', ''); |
||
171 | } |
||
172 | } |
||
173 | return $results; |
||
174 | } |
||
175 | |||
176 | private static function checksumFileToArray($checksumfile) { |
||
177 | $out = array(); |
||
654 | daniel-mar | 178 | |
179 | $cont = url_get_contents($checksumfile); |
||
180 | if ($cont === false) return false; |
||
181 | $lines = explode("\n", $cont); |
||
182 | |||
635 | daniel-mar | 183 | foreach ($lines as $line) { |
184 | $line = trim($line); |
||
185 | if ($line == '') continue; |
||
186 | list($hash, $filename) = explode("\t",$line); |
||
187 | if (substr($filename,0,strlen('trunk/')) == 'trunk/') { |
||
188 | $out[substr($filename,strlen('trunk/'))] = $hash; |
||
189 | } |
||
190 | } |
||
191 | return $out; |
||
192 | } |
||
193 | |||
661 | daniel-mar | 194 | } |