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