1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: |
|
18: |
|
19: | |
20: | |
21: | |
22: | |
23: |
|
24: | function installerHtmlSpecialChars($value = '')
|
25: | {
|
26: | return htmlspecialchars($value, ENT_QUOTES, _INSTALL_CHARSET, true);
|
27: | }
|
28: |
|
29: | function install_acceptUser($hash = '')
|
30: | {
|
31: | $GLOBALS['xoopsUser'] = null;
|
32: | $assertClaims = array(
|
33: | 'sub' => 'xoopsinstall',
|
34: | );
|
35: | $claims = \Xmf\Jwt\TokenReader::fromCookie('install', 'xo_install_user', $assertClaims);
|
36: | if (false === $claims || empty($claims->uname)) {
|
37: | return false;
|
38: | }
|
39: | $uname = $claims->uname;
|
40: |
|
41: | $memberHandler = xoops_getHandler('member');
|
42: | $users = $memberHandler->getUsers(new Criteria('uname', $uname));
|
43: | $user = array_pop($users);
|
44: |
|
45: | if (is_object($GLOBALS['xoops']) && method_exists($GLOBALS['xoops'], 'acceptUser')) {
|
46: | $res = $GLOBALS['xoops']->acceptUser($uname, true, '');
|
47: |
|
48: | return $res;
|
49: | }
|
50: |
|
51: | $GLOBALS['xoopsUser'] = $user;
|
52: | $_SESSION['xoopsUserId'] = $GLOBALS['xoopsUser']->getVar('uid');
|
53: | $_SESSION['xoopsUserGroups'] = $GLOBALS['xoopsUser']->getGroups();
|
54: |
|
55: | return true;
|
56: | }
|
57: |
|
58: | |
59: | |
60: |
|
61: | function install_finalize($installer_modified)
|
62: | {
|
63: |
|
64: | @chmod(XOOPS_ROOT_PATH . '/mainfile.php', 0444);
|
65: |
|
66: | @chmod(XOOPS_VAR_PATH . '/data/secure.php', 0444);
|
67: |
|
68: | @rename(XOOPS_ROOT_PATH . '/install', XOOPS_ROOT_PATH . '/' . $installer_modified);
|
69: | }
|
70: |
|
71: | |
72: | |
73: | |
74: | |
75: | |
76: |
|
77: | function xoFormField($name, $value, $label, $help = '')
|
78: | {
|
79: | $label = installerHtmlSpecialChars($label);
|
80: | $name = installerHtmlSpecialChars($name);
|
81: | $value = installerHtmlSpecialChars($value);
|
82: | echo '<div class="form-group">';
|
83: | echo '<label class="xolabel" for="' . $name . '">' . $label . '</label>';
|
84: | if ($help) {
|
85: | echo '<div class="xoform-help alert alert-info">' . $help . '</div>';
|
86: | }
|
87: | echo '<input type="text" class="form-control" name="'.$name.'" id="'.$name.'" value="'.$value.'">';
|
88: | echo '</div>';
|
89: | }
|
90: |
|
91: | |
92: | |
93: | |
94: | |
95: | |
96: |
|
97: | function xoPassField($name, $value, $label, $help = '')
|
98: | {
|
99: | $label = installerHtmlSpecialChars($label);
|
100: | $name = installerHtmlSpecialChars($name);
|
101: | $value = installerHtmlSpecialChars($value);
|
102: | echo '<div class="form-group">';
|
103: | echo '<label class="xolabel" for="' . $name . '">' . $label . '</label>';
|
104: | if ($help) {
|
105: | echo '<div class="xoform-help alert alert-info">' . $help . '</div>';
|
106: | }
|
107: | if ($name === 'adminpass') {
|
108: | echo '<input type="password" class="form-control" name="'.$name.'" id="'.$name.'" value="'.$value.'" onkeyup="passwordStrength(this.value)">';
|
109: | } else {
|
110: | echo '<input type="password" class="form-control" name="'.$name.'" id="'.$name.'" value="'.$value.'">';
|
111: | }
|
112: | echo '</div>';
|
113: | }
|
114: |
|
115: | |
116: | |
117: | |
118: | |
119: | |
120: | |
121: | |
122: |
|
123: | function xoFormSelect($name, $value, $label, $options, $help = '', $extra='')
|
124: | {
|
125: | $label = installerHtmlSpecialChars($label);
|
126: | $name = installerHtmlSpecialChars($name);
|
127: | $value = installerHtmlSpecialChars($value);
|
128: | echo '<div class="form-group">';
|
129: | echo '<label class="xolabel" for="' . $name . '">' . $label . '</label>';
|
130: | if ($help) {
|
131: | echo '<div class="xoform-help alert alert-info">' . $help . '</div>';
|
132: | }
|
133: | echo '<select class="form-control" name="'.$name.'" id="'.$name.'" value="'.$value.'" '.$extra.'>';
|
134: | foreach ($options as $optionValue => $optionReadable) {
|
135: | $selected = ($value === $optionValue) ? ' selected' : '';
|
136: | echo '<option value="'.$optionValue . '"' . $selected . '>' . $optionReadable . '</option>';
|
137: | }
|
138: | echo '</select>';
|
139: | echo '</div>';
|
140: | }
|
141: |
|
142: | |
143: | |
144: |
|
145: | |
146: | |
147: | |
148: | |
149: |
|
150: | function getDirList($dirname)
|
151: | {
|
152: | $dirlist = array();
|
153: | if ($handle = opendir($dirname)) {
|
154: | while ($file = readdir($handle)) {
|
155: | if ($file[0] !== '.' && is_dir($dirname . $file)) {
|
156: | $dirlist[] = $file;
|
157: | }
|
158: | }
|
159: | closedir($handle);
|
160: | asort($dirlist);
|
161: | reset($dirlist);
|
162: | }
|
163: |
|
164: | return $dirlist;
|
165: | }
|
166: |
|
167: | |
168: | |
169: | |
170: | |
171: | |
172: |
|
173: | function xoDiag($status = -1, $str = '')
|
174: | {
|
175: | if ($status == -1) {
|
176: | $GLOBALS['error'] = true;
|
177: | }
|
178: | $classes = array(-1 => 'fa fa-fw fa-ban text-danger', 0 => 'fa fa-fw fa-square-o text-warning', 1 => 'fa fa-fw fa-check text-success');
|
179: | $strings = array(-1 => FAILED, 0 => WARNING, 1 => SUCCESS);
|
180: | if (empty($str)) {
|
181: | $str = $strings[$status];
|
182: | }
|
183: |
|
184: | return '<span class="' . $classes[$status] . '"></span>' . $str;
|
185: | }
|
186: |
|
187: | |
188: | |
189: | |
190: | |
191: | |
192: | |
193: |
|
194: | function xoDiagBoolSetting($name, $wanted = false, $severe = false)
|
195: | {
|
196: | $setting = (bool) ini_get($name);
|
197: | if ($setting === (bool) $wanted) {
|
198: | return xoDiag(1, $setting ? 'ON' : 'OFF');
|
199: | } else {
|
200: | return xoDiag($severe ? -1 : 0, $setting ? 'ON' : 'OFF');
|
201: | }
|
202: | }
|
203: |
|
204: | |
205: | |
206: | |
207: | |
208: | |
209: |
|
210: | function xoDiagIfWritable($path)
|
211: | {
|
212: | $path = '../' . $path;
|
213: | $error = true;
|
214: | if (!is_dir($path)) {
|
215: | if (file_exists($path) && !is_writable($path)) {
|
216: | @chmod($path, 0664);
|
217: | $error = !is_writable($path);
|
218: | }
|
219: | } else {
|
220: | if (!is_writable($path)) {
|
221: | @chmod($path, 0775);
|
222: | $error = !is_writable($path);
|
223: | }
|
224: | }
|
225: |
|
226: | return xoDiag($error ? -1 : 1, $error ? ' ' : ' ');
|
227: | }
|
228: |
|
229: | |
230: | |
231: |
|
232: | function xoPhpVersion()
|
233: | {
|
234: | if (version_compare(phpversion(), '5.6.0', '>=')) {
|
235: | return xoDiag(1, phpversion());
|
236: | } else {
|
237: | return xoDiag(-1, phpversion());
|
238: | }
|
239: | }
|
240: |
|
241: | |
242: | |
243: | |
244: | |
245: | |
246: |
|
247: | function genPathCheckHtml($path, $valid)
|
248: | {
|
249: | if ($valid) {
|
250: | switch ($path) {
|
251: | case 'root':
|
252: | $msg = sprintf(XOOPS_FOUND, XOOPS_VERSION);
|
253: | break;
|
254: |
|
255: | case 'lib':
|
256: | case 'data':
|
257: | default:
|
258: | $msg = XOOPS_PATH_FOUND;
|
259: | break;
|
260: | }
|
261: |
|
262: | return '<span class="pathmessage"><span class="fa fa-fw fa-check text-success"></span> ' . $msg . '</span>';
|
263: | } else {
|
264: | switch ($path) {
|
265: | case 'root':
|
266: | $msg = ERR_NO_XOOPS_FOUND;
|
267: | break;
|
268: |
|
269: | case 'lib':
|
270: | case 'data':
|
271: | default:
|
272: | $msg = ERR_COULD_NOT_ACCESS;
|
273: | break;
|
274: | }
|
275: | $GLOBALS['error'] = true;
|
276: | return '<div class="alert alert-danger"><span class="fa fa-fw fa-ban text-danger"></span> ' . $msg . '</div>';
|
277: | }
|
278: | }
|
279: |
|
280: | |
281: | |
282: | |
283: | |
284: |
|
285: | function getDbCharsets($link)
|
286: | {
|
287: | static $charsets = array();
|
288: | if ($charsets) {
|
289: | return $charsets;
|
290: | }
|
291: |
|
292: | if ($result = mysqli_query($link, 'SHOW CHARSET')) {
|
293: | while ($row = mysqli_fetch_assoc($result)) {
|
294: | $charsets[$row['Charset']] = $row['Description'];
|
295: | }
|
296: | }
|
297: |
|
298: | return $charsets;
|
299: | }
|
300: |
|
301: | |
302: | |
303: | |
304: | |
305: | |
306: |
|
307: | function getDbCollations($link, $charset)
|
308: | {
|
309: | static $collations = array();
|
310: | if (!empty($collations[$charset])) {
|
311: | return $collations[$charset];
|
312: | }
|
313: |
|
314: | if ($result = mysqli_query($link, "SHOW COLLATION WHERE CHARSET = '" . mysqli_real_escape_string($link, $charset) . "'")) {
|
315: | while ($row = mysqli_fetch_assoc($result)) {
|
316: | $collations[$charset][$row['Collation']] = $row['Default'] ? 1 : 0;
|
317: | }
|
318: | }
|
319: |
|
320: | return $collations[$charset];
|
321: | }
|
322: |
|
323: | |
324: | |
325: | |
326: | |
327: | |
328: | |
329: |
|
330: | function validateDbCharset($link, &$charset, &$collation)
|
331: | {
|
332: | $error = null;
|
333: |
|
334: | if (empty($charset)) {
|
335: | $collation = '';
|
336: | }
|
337: | if (empty($charset) && empty($collation)) {
|
338: | return $error;
|
339: | }
|
340: |
|
341: | $charsets = getDbCharsets($link);
|
342: | if (!isset($charsets[$charset])) {
|
343: | $error = sprintf(ERR_INVALID_DBCHARSET, $charset);
|
344: | } elseif (!empty($collation)) {
|
345: | $collations = getDbCollations($link, $charset);
|
346: | if (!isset($collations[$collation])) {
|
347: | $error = sprintf(ERR_INVALID_DBCOLLATION, $collation);
|
348: | }
|
349: | }
|
350: |
|
351: | return $error;
|
352: | }
|
353: |
|
354: | |
355: | |
356: | |
357: | |
358: | |
359: | |
360: | |
361: | |
362: | |
363: |
|
364: | function xoFormFieldCollation($name, $value, $label, $help, $link, $charset)
|
365: | {
|
366: | if (empty($charset) || !$collations = getDbCollations($link, $charset)) {
|
367: | return '';
|
368: | }
|
369: |
|
370: | $options = array();
|
371: | foreach ($collations as $key => $isDefault) {
|
372: | if ($isDefault) {
|
373: | $options = array($key => $key . ' (Default)') + $options;
|
374: | } else {
|
375: | $options[$key] = $key;
|
376: | }
|
377: | }
|
378: |
|
379: | return xoFormSelect($name, $value, $label, $options, $help);
|
380: | }
|
381: |
|
382: | |
383: | |
384: | |
385: | |
386: | |
387: | |
388: | |
389: | |
390: | |
391: |
|
392: | function xoFormBlockCollation($name, $value, $label, $help, $link, $charset)
|
393: | {
|
394: | return xoFormFieldCollation($name, $value, $label, $help, $link, $charset);
|
395: | }
|
396: |
|
397: | |
398: | |
399: | |
400: | |
401: | |
402: | |
403: | |
404: | |
405: |
|
406: | function xoFormFieldCharset($name, $value, $label, $help, $link)
|
407: | {
|
408: | if (!$charsets = getDbCharsets($link)) {
|
409: | return '';
|
410: | }
|
411: | foreach ($charsets as $k => $v) {
|
412: | $charsets[$k] = $v . ' (' . $k . ')';
|
413: | }
|
414: | asort($charsets);
|
415: | $label = installerHtmlSpecialChars($label);
|
416: | $name = installerHtmlSpecialChars($name);
|
417: | $value = installerHtmlSpecialChars($value);
|
418: | $extra = 'onchange="setFormFieldCollation(\'DB_COLLATION\', this.value)"';
|
419: | return xoFormSelect($name, $value, $label, $charsets, $help, $extra);
|
420: | }
|
421: |
|
422: | |
423: | |
424: | |
425: | |
426: | |
427: | |
428: | |
429: |
|
430: | function xoPutLicenseKey($system_key, $licensefile, $license_file_dist = 'license.dist.php')
|
431: | {
|
432: |
|
433: | $fver = fopen($licensefile, 'w');
|
434: | $fver_buf = file($license_file_dist);
|
435: | foreach ($fver_buf as $line => $value) {
|
436: | $ret = $value;
|
437: | if (strpos($value, 'XOOPS_LICENSE_KEY') > 0) {
|
438: | $ret = 'define(\'XOOPS_LICENSE_KEY\', \'' . $system_key . "');";
|
439: | }
|
440: | fwrite($fver, $ret, strlen($ret));
|
441: | }
|
442: | fclose($fver);
|
443: | chmod($licensefile, 0444);
|
444: |
|
445: | return sprintf(WRITTEN_LICENSE, XOOPS_LICENSE_CODE, $system_key);
|
446: | }
|
447: |
|
448: | |
449: | |
450: | |
451: |
|
452: | function xoBuildLicenceKey()
|
453: | {
|
454: | $xoops_serdat = array();
|
455: | $checksums = array(1 => 'md5', 2 => 'sha1');
|
456: | $type = mt_rand(1, 2);
|
457: | $func = $checksums[$type];
|
458: |
|
459: | error_reporting(0);
|
460: |
|
461: |
|
462: | if ($xoops_serdat['version'] = $func(XOOPS_VERSION)) {
|
463: | $xoops_serdat['version'] = substr($xoops_serdat['version'], 0, 6);
|
464: | }
|
465: | if ($xoops_serdat['licence'] = $func(XOOPS_LICENSE_CODE)) {
|
466: | $xoops_serdat['licence'] = substr($xoops_serdat['licence'], 0, 2);
|
467: | }
|
468: | if ($xoops_serdat['license_text'] = $func(XOOPS_LICENSE_TEXT)) {
|
469: | $xoops_serdat['license_text'] = substr($xoops_serdat['license_text'], 0, 2);
|
470: | }
|
471: |
|
472: | if ($xoops_serdat['domain_host'] = $func($_SERVER['HTTP_HOST'])) {
|
473: | $xoops_serdat['domain_host'] = substr($xoops_serdat['domain_host'], 0, 2);
|
474: | }
|
475: |
|
476: |
|
477: | $xoops_serdat['file'] = $func(__FILE__);
|
478: | $xoops_serdat['basename'] = $func(basename(__FILE__));
|
479: | $xoops_serdat['path'] = $func(__DIR__);
|
480: |
|
481: | foreach ($_SERVER as $key => $data) {
|
482: | $xoops_serdat[$key] = substr($func(serialize($data)), 0, 4);
|
483: | }
|
484: |
|
485: | $xoops_key = '';
|
486: | foreach ($xoops_serdat as $key => $data) {
|
487: | $xoops_key .= $data;
|
488: | }
|
489: | while (strlen($xoops_key) > 40) {
|
490: | $lpos = mt_rand(18, strlen($xoops_key));
|
491: | $xoops_key = substr($xoops_key, 0, $lpos) . substr($xoops_key, $lpos + 1, strlen($xoops_key) - ($lpos + 1));
|
492: | }
|
493: |
|
494: | return xoStripeKey($xoops_key);
|
495: | }
|
496: |
|
497: | |
498: | |
499: | |
500: | |
501: | |
502: |
|
503: | function xoStripeKey($xoops_key)
|
504: | {
|
505: | $uu = 0;
|
506: | $num = 6;
|
507: | $length = 30;
|
508: | $strip = floor(strlen($xoops_key) / 6);
|
509: | $strlen = strlen($xoops_key);
|
510: | $ret = '';
|
511: | for ($i = 0; $i < $strlen; ++$i) {
|
512: | if ($i < $length) {
|
513: | ++$uu;
|
514: | if ($uu == $strip) {
|
515: | $ret .= substr($xoops_key, $i, 1) . '-';
|
516: | $uu = 0;
|
517: | } else {
|
518: | if (substr($xoops_key, $i, 1) != '-') {
|
519: | $ret .= substr($xoops_key, $i, 1);
|
520: | } else {
|
521: | $uu--;
|
522: | }
|
523: | }
|
524: | }
|
525: | }
|
526: | $ret = str_replace('--', '-', $ret);
|
527: | if (substr($ret, 0, 1) == '-') {
|
528: | $ret = substr($ret, 2, strlen($ret));
|
529: | }
|
530: | if (substr($ret, strlen($ret) - 1, 1) == '-') {
|
531: | $ret = substr($ret, 0, strlen($ret) - 1);
|
532: | }
|
533: |
|
534: | return $ret;
|
535: | }
|
536: |
|
537: |
|
538: | |
539: | |
540: |
|
541: | function writeLicenseKey()
|
542: | {
|
543: | return xoPutLicenseKey(xoBuildLicenceKey(), XOOPS_VAR_PATH . '/data/license.php', __DIR__ . '/license.dist.php');
|
544: | }
|
545: | |