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: * See the enclosed file license.txt for licensing information.
14: * If you did not receive this file, get it at https://www.gnu.org/licenses/gpl-2.0.html
15: *
16: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
17: * @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18: * @package installer
19: * @since 2.3.0
20: * @author Haruki Setoyama <haruki@planewave.org>
21: * @author Kazumi Ono <webmaster@myweb.ne.jp>
22: * @author Skalpa Keo <skalpa@xoops.org>
23: * @author Taiwen Jiang <phppp@users.sourceforge.net>
24: * @author DuGris (aka L. JEN) <dugris@frxoops.org>
25: */
26: class XoopsInstallWizard
27: {
28: public $language = 'english';
29: public $pages = array();
30: public $currentPage = 'langselect';
31: public $pageIndex = 0;
32: public $configs = array();
33: public $form;
34:
35: /**
36: * @return bool
37: */
38: public function xoInit()
39: {
40: if (@empty($_SERVER['REQUEST_URI'])) {
41: $_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
42: }
43:
44: // Load the main language file
45: $this->initLanguage(!empty($_COOKIE['xo_install_lang']) ? $_COOKIE['xo_install_lang'] : 'english');
46: // Setup pages
47: include_once __DIR__ . '/../include/page.php';
48: $this->pages = $pages;
49:
50: // Load default configs
51: include_once __DIR__ . '/../include/config.php';
52: $this->configs = $configs;
53: /*
54: // Database type
55: $this->db_types = $db_types;
56:
57: // setup config site info
58: $this->conf_names = $conf_names;
59:
60: // languages config files
61: $this->language_files = $language_files;
62:
63: // extension_loaded
64: $this->extensions = $extensions;
65:
66: // Modules to be installed by default
67: $this->modules = $modules;
68:
69: // xoops_lib, xoops_data directories
70: $this->xoopsPathDefault = $xoopsPathDefault;
71:
72: // writable xoops_lib, xoops_data directories
73: $this->dataPath = $dataPath;
74:
75: // Protector default trust_path
76: $this->trust_path = isset($trust_path) ? $trust_path : false;
77:
78: // Writable files and directories
79: $this->writable = $writable;
80: */
81:
82: if (!$this->checkAccess()) {
83: return false;
84: }
85:
86: $pagename = preg_replace('~(page_)(.*)~', '$2', basename($_SERVER['PHP_SELF'], '.php'));
87: $this->setPage($pagename);
88:
89: // Prevent client caching
90: header('Cache-Control: no-store, no-cache, must-revalidate', false);
91: header('Pragma: no-cache');
92:
93: return true;
94: }
95:
96: /**
97: * @return bool
98: */
99: public function checkAccess()
100: {
101: if (INSTALL_USER != '' && INSTALL_PASSWORD != '') {
102: if (!isset($_SERVER['PHP_AUTH_USER'])) {
103: header('WWW-Authenticate: Basic realm="XOOPS Installer"');
104: header('HTTP/1.0 401 Unauthorized');
105: echo 'You can not access this XOOPS installer.';
106:
107: return false;
108: }
109: if (INSTALL_USER != '' && $_SERVER['PHP_AUTH_USER'] != INSTALL_USER) {
110: header('HTTP/1.0 401 Unauthorized');
111: echo 'You can not access this XOOPS installer.';
112:
113: return false;
114: }
115: if (INSTALL_PASSWORD != $_SERVER['PHP_AUTH_PW']) {
116: header('HTTP/1.0 401 Unauthorized');
117: echo 'You can not access this XOOPS installer.';
118:
119: return false;
120: }
121: }
122:
123: if (empty($GLOBALS['xoopsOption']['checkadmin'])) {
124: return true;
125: }
126:
127: if (empty($GLOBALS['xoopsUser']) && !empty($_COOKIE['xo_install_user'])) {
128: return install_acceptUser($_COOKIE['xo_install_user']);
129: }
130: if (empty($GLOBALS['xoopsUser'])) {
131: redirect_header('../user.php');
132: }
133: if (!$GLOBALS['xoopsUser']->isAdmin()) {
134: return false;
135: }
136:
137: return true;
138: }
139:
140: /**
141: * @param $file
142: */
143: public function loadLangFile($file)
144: {
145: if (file_exists(__DIR__ . "/../language/{$this->language}/{$file}.php")) {
146: include_once __DIR__ . "/../language/{$this->language}/{$file}.php";
147: } else {
148: include_once __DIR__ . "/../language/english/$file.php";
149: }
150: }
151:
152: /**
153: * @param $language
154: */
155: public function initLanguage($language)
156: {
157: $language = preg_replace("/[^a-z0-9_\-]/i", '', $language);
158: if (!file_exists("./language/{$language}/install.php")) {
159: $language = 'english';
160: }
161: $this->language = $language;
162: $this->loadLangFile('install');
163: }
164:
165: /**
166: * @param $page
167: *
168: * @return bool|mixed
169: */
170: public function setPage($page)
171: {
172: $pages = array_keys($this->pages);
173: if ((int)$page && $page >= 0 && $page < count($pages)) {
174: $this->pageIndex = $page;
175: $this->currentPage = $pages[$page];
176: } elseif (isset($this->pages[$page])) {
177: $this->currentPage = $page;
178: $this->pageIndex = array_search($this->currentPage, $pages);
179: } else {
180: return false;
181: }
182:
183: if ($this->pageIndex > 0 && !isset($_COOKIE['xo_install_lang'])) {
184: header('Location: index.php');
185: }
186:
187: return $this->pageIndex;
188: }
189:
190: /**
191: * @return string
192: */
193: public function baseLocation()
194: {
195: $proto = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')) ? 'https' : 'http';
196: $host = $_SERVER['HTTP_HOST'];
197: $base = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'));
198:
199: return $proto . '://' . $host . $base;
200: }
201:
202: /**
203: * @param $page
204: *
205: * @return string
206: */
207: public function pageURI($page)
208: {
209: $pages = array_keys($this->pages);
210: $pageIndex = $this->pageIndex;
211: if (!(int)$page[0]) {
212: if ($page[0] == '+') {
213: $pageIndex += substr($page, 1);
214: } elseif ($page[0] == '-') {
215: $pageIndex -= substr($page, 1);
216: } else {
217: $pageIndex = (int)array_search($page, $pages);
218: }
219: }
220: if (!isset($pages[$pageIndex])) {
221: if (defined('XOOPS_URL')) {
222: return XOOPS_URL;
223: } else {
224: return $this->baseLocation();
225: }
226: }
227: $page = $pages[$pageIndex];
228:
229: return $this->baseLocation() . "/page_{$page}.php";
230: }
231:
232: /**
233: * @param $page
234: * @param int $status
235: * @param string $message
236: */
237: public function redirectToPage($page, $status = 303, $message = 'See other')
238: {
239: $location = $this->pageURI($page);
240: $proto = !@empty($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
241: header("{$proto} {$status} {$message}");
242: //header( "Status: $status $message" );
243: header("Location: {$location}");
244: }
245:
246: /**
247: * @return string
248: */
249: public function CreateForm()
250: {
251: $hidden = '';
252: $ret = '';
253:
254: foreach ($this->form as $form) {
255: $ret .= '<div class="panel panel-info">';
256: $ret .= '<div class="panel-heading">' . $form->getTitle() . '</div>';
257: $ret .= '<div class="panel-body">';
258:
259: foreach ($form->getElements() as $ele) {
260: if (is_object($ele)) {
261: if (!$ele->isHidden()) {
262: if (($caption = $ele->getCaption()) != '') {
263: $name = $ele->getName();
264: $ret .= "<label class='xolabel' for='" . $ele->getName() . "'>" . $caption . '</label>';
265: if (($desc = $ele->getDescription()) != '') {
266: $ret .= "<div class='xoform-help alert alert-info'>";
267: $ret .= $desc;
268: $ret .= '</div>';
269: }
270: }
271: $ret .= $ele->render() . "\n";
272: } else {
273: $hidden .= $ele->render() . "\n";
274: }
275: }
276: }
277: $ret .= "</div></div>\n" . $hidden . "\n" . $form->renderValidationJS(true);
278: }
279:
280: return $ret;
281: }
282: }
283: