1 | <?php |
||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * Upgrader from 2.4.0 to 2.4.1 |
||
14 | * |
||
15 | * See the enclosed file license.txt for licensing information. |
||
16 | * If you did not receive this file, get it at https://www.gnu.org/licenses/gpl-2.0.html |
||
17 | * |
||
18 | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
||
19 | * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
20 | * @package upgrader |
||
21 | * @since 2.4.0 |
||
22 | * @author Taiwen Jiang <[email protected]> |
||
23 | * @author trabis <[email protected]> |
||
24 | */ |
||
25 | class Upgrade_241 extends XoopsUpgrade |
||
26 | { |
||
27 | /** |
||
28 | * @return bool |
||
29 | */ |
||
30 | public function check_license() |
||
31 | { |
||
32 | if (defined('XOOPS_LICENSE_KEY')) { |
||
33 | return true; // skip setup if license.php was included |
||
34 | } |
||
35 | if (defined('XOOPS_LICENSE_KEY') == false) { |
||
0 ignored issues
–
show
|
|||
36 | if (substr(XOOPS_LICENSE_KEY, 0, 13) != $this->xoops_getPublicLicenceKey()) { |
||
37 | return false; |
||
38 | } else { |
||
39 | return true; |
||
40 | } |
||
41 | } elseif (XOOPS_LICENSE_KEY == '000000-000000-000000-000000-000000') { |
||
42 | return false; |
||
43 | } else { |
||
44 | return true; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @return bool|string |
||
50 | */ |
||
51 | public function apply_license() |
||
52 | { |
||
53 | set_time_limit(120); |
||
54 | chmod('../include/license.php', 0777); |
||
55 | if (!is_writable('../include/license.php')) { |
||
56 | echo "<p><span style='color:#ff0000;'> include/license.php - is not writeable</span> - Windows Read Only (Off) / UNIX chmod 0777</p>"; |
||
57 | |||
58 | return false; |
||
59 | } |
||
60 | if (XOOPS_LICENSE_KEY == '000000-000000-000000-000000-000000') { |
||
61 | return @$this->xoops_putLicenseKey($this->xoops_buildLicenceKey(), XOOPS_ROOT_PATH . '/include/license.php', __DIR__ . '/license.dist.php'); |
||
62 | } else { |
||
63 | return @$this->xoops_upgradeLicenseKey($this->xoops_getPublicLicenceKey(), XOOPS_ROOT_PATH . '/include/license.php', __DIR__ . '/license.dist.php'); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * *#@+ |
||
69 | * Xoops Write Licence System Key |
||
70 | */ |
||
71 | public function xoops_upgradeLicenseKey($public_key, $licensefile, $license_file_dist = 'license.dist.php') |
||
72 | { |
||
73 | chmod($licensefile, 0777); |
||
74 | $fver = fopen($licensefile, 'w'); |
||
75 | $fver_buf = file($license_file_dist); |
||
76 | $license_key = $public_key . substr(XOOPS_LICENSE_KEY, 13, strlen(XOOPS_LICENSE_KEY) - 13); |
||
77 | foreach ($fver_buf as $line => $value) { |
||
78 | if (strpos($value, 'XOOPS_LICENSE_KEY') > 0) { |
||
79 | $ret = 'define(\'XOOPS_LICENSE_KEY\', \'' . $license_key . "');"; |
||
80 | } else { |
||
81 | $ret = $value; |
||
82 | } |
||
83 | fwrite($fver, $ret, strlen($ret)); |
||
84 | } |
||
85 | fclose($fver); |
||
86 | chmod($licensefile, 0444); |
||
87 | |||
88 | return 'Written License Key: ' . $license_key; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * *#@+ |
||
93 | * Xoops Write Licence System Key |
||
94 | */ |
||
95 | public function xoops_putLicenseKey($system_key, $licensefile, $license_file_dist = 'license.dist.php') |
||
96 | { |
||
97 | chmod($licensefile, 0777); |
||
98 | $fver = fopen($licensefile, 'w'); |
||
99 | $fver_buf = file($license_file_dist); |
||
100 | foreach ($fver_buf as $line => $value) { |
||
101 | if (strpos($value, 'XOOPS_LICENSE_KEY') > 0) { |
||
102 | $ret = 'define(\'XOOPS_LICENSE_KEY\', \'' . $system_key . "');"; |
||
103 | } else { |
||
104 | $ret = $value; |
||
105 | } |
||
106 | fwrite($fver, $ret, strlen($ret)); |
||
107 | } |
||
108 | fclose($fver); |
||
109 | chmod($licensefile, 0444); |
||
110 | |||
111 | return 'Written License Key: ' . $system_key; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * *#@+ |
||
116 | * Xoops Get Public Checkbit from Licence System Key |
||
117 | */ |
||
118 | public function xoops_getPublicLicenceKey() |
||
119 | { |
||
120 | $xoops_key = ''; |
||
121 | $xoops_serdat = array(); |
||
122 | $checksums = array(1 => 'md5', 2 => 'sha1'); |
||
123 | |||
124 | // Remember to upgrade versions string with each release there after. |
||
125 | $versions = array('XOOPS 2.4.0', 'XOOPS 2.4.1'); |
||
126 | |||
127 | error_reporting(E_ALL); |
||
128 | foreach ($checksums as $funcid => $func) { |
||
129 | foreach ($versions as $versionid => $version) { |
||
130 | if ($xoops_serdat['version'] = $func($version) && substr(XOOPS_LICENSE_KEY, 0, 6) === substr($func($version), 0, 6)) { |
||
131 | $xoops_serdat['version'] = substr($xoops_serdat['version'], 0, 6); |
||
132 | $checkbit = $func; |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | if (isset($checkbit)) { |
||
137 | if ($xoops_serdat['licence'] = $checkbit(XOOPS_LICENSE_CODE)) { |
||
138 | $xoops_serdat['licence'] = substr($xoops_serdat['licence'], 0, 2); |
||
139 | } |
||
140 | if ($xoops_serdat['license_text'] = $checkbit(XOOPS_LICENSE_TEXT)) { |
||
141 | $xoops_serdat['license_text'] = substr($xoops_serdat['license_text'], 0, 2); |
||
142 | } |
||
143 | |||
144 | if ($xoops_serdat['domain_host'] = $checkbit($_SERVER['HTTP_HOST'])) { |
||
145 | $xoops_serdat['domain_host'] = substr($xoops_serdat['domain_host'], 0, 2); |
||
146 | } |
||
147 | } |
||
148 | foreach ($xoops_serdat as $key => $data) { |
||
149 | $xoops_key .= $data; |
||
150 | } |
||
151 | |||
152 | return $this->xoops_stripeKey($xoops_key, 6, 13, 0); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * *#@+ |
||
157 | * Xoops Build Licence System Key |
||
158 | */ |
||
159 | public function xoops_buildLicenceKey() |
||
160 | { |
||
161 | $xoops_serdat = array(); |
||
162 | $checksums = array(1 => 'md5', 2 => 'sha1'); |
||
163 | $type = mt_rand(1, 2); |
||
164 | $func = $checksums[$type]; |
||
165 | $xoops_key = ''; |
||
166 | |||
167 | error_reporting(E_ALL); |
||
168 | |||
169 | // Public Key |
||
170 | if ($xoops_serdat['version'] = $func(XOOPS_VERSION)) { |
||
171 | $xoops_serdat['version'] = substr($xoops_serdat['version'], 0, 6); |
||
172 | } |
||
173 | if ($xoops_serdat['licence'] = $func(XOOPS_LICENSE_CODE)) { |
||
174 | $xoops_serdat['licence'] = substr($xoops_serdat['licence'], 0, 2); |
||
175 | } |
||
176 | if ($xoops_serdat['license_text'] = $func(XOOPS_LICENSE_TEXT)) { |
||
177 | $xoops_serdat['license_text'] = substr($xoops_serdat['license_text'], 0, 2); |
||
178 | } |
||
179 | |||
180 | if ($xoops_serdat['domain_host'] = $func($_SERVER['HTTP_HOST'])) { |
||
181 | $xoops_serdat['domain_host'] = substr($xoops_serdat['domain_host'], 0, 2); |
||
182 | } |
||
183 | |||
184 | // Private Key |
||
185 | $xoops_serdat['file'] = $func(__FILE__); |
||
186 | $xoops_serdat['basename'] = $func(basename(__FILE__)); |
||
187 | $xoops_serdat['path'] = $func(__DIR__); |
||
188 | |||
189 | foreach ($_SERVER as $key => $data) { |
||
190 | $xoops_serdat[$key] = substr($func(serialize($data)), 0, 4); |
||
191 | } |
||
192 | |||
193 | foreach ($xoops_serdat as $key => $data) { |
||
194 | $xoops_key .= $data; |
||
195 | } |
||
196 | while (strlen($xoops_key) > 40) { |
||
197 | $lpos = mt_rand(18, strlen($xoops_key)); |
||
198 | $xoops_key = substr($xoops_key, 0, $lpos) . substr($xoops_key, $lpos + 1, strlen($xoops_key) - ($lpos + 1)); |
||
199 | } |
||
200 | |||
201 | return $this->xoops_stripeKey($xoops_key); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * *#@+ |
||
206 | * Xoops Stripe Licence System Key |
||
207 | */ |
||
208 | public function xoops_stripeKey($xoops_key, $num = 6, $length = 30, $uu = 0) |
||
209 | { |
||
210 | $strip = floor(strlen($xoops_key) / 6); |
||
211 | $ret = 0; |
||
212 | for ($i = 0; $i < strlen($xoops_key); ++$i) { |
||
213 | if ($i < $length) { |
||
214 | ++$uu; |
||
215 | if ($uu == $strip) { |
||
216 | $ret .= substr($xoops_key, $i, 1) . '-'; |
||
217 | $uu = 0; |
||
218 | } else { |
||
219 | if (substr($xoops_key, $i, 1) != '-') { |
||
220 | $ret .= substr($xoops_key, $i, 1); |
||
221 | } else { |
||
222 | $uu--; |
||
223 | } |
||
224 | } |
||
225 | } |
||
226 | } |
||
227 | $ret = str_replace('--', '-', $ret); |
||
228 | if (substr($ret, 0, 1) == '-') { |
||
229 | $ret = substr($ret, 2, strlen($ret)); |
||
230 | } |
||
231 | if (substr($ret, strlen($ret) - 1, 1) == '-') { |
||
232 | $ret = substr($ret, 0, strlen($ret) - 1); |
||
233 | } |
||
234 | |||
235 | return $ret; |
||
236 | } |
||
237 | |||
238 | public function __construct() |
||
239 | { |
||
240 | parent::__construct(basename(__DIR__)); |
||
241 | $this->tasks = array('license'); |
||
242 | } |
||
243 | } |
||
244 | |||
245 | $upg = new Upgrade_241(); |
||
246 | return $upg; |
||
247 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.