XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
settingmanager.php
1<?php
12
13
14include_once './class/textsanitizer.php';
15
16
18
19 public $database;
20 public $dbhost;
21 public $dbuname;
22 public $dbpass;
23 public $dbname;
24 public $prefix;
25 public $db_pconnect;
26 public $root_path;
27 public $trust_path;
28 public $xoops_url;
29
30 public $salt;
31
32 public $sanitizer;
33
37 public function __construct($post = false ) {
38 $this->sanitizer = TextSanitizer::getInstance();
39 if ( $post ) {
40 $this->readPost();
41 } else {
42 $this->database = 'mysql';
43 $this->dbhost = 'localhost';
44
45 //
46 // Generate prefix
47 mt_srand( (double) microtime() * 1_000_000 );
48 do {
49 $this->prefix = substr( md5( random_int( 1, 6 ) ), 0, 6 );
50 } while ( ! preg_match( '/^[a-z]/', $this->prefix ) );
51
52 $this->salt = substr( md5( random_int(0, mt_getrandmax()) ), 5, 8 );
53
54 $this->db_pconnect = 0;
55
56 $this->root_path = str_replace( '\\', '/', getcwd() ); // "
57 $this->root_path = str_replace( '/install', '', $this->root_path );
58
59 $filepath = ( ! empty( $_SERVER['REQUEST_URI'] ) )
60 ? dirname( $_SERVER['REQUEST_URI'] )
61 : dirname( $_SERVER['SCRIPT_NAME'] );
62
63 // "
64 $filepath = str_replace( [ '\\', '/install' ], [ '/', '' ], $filepath );
65 if ( '/' === substr( $filepath, 0, 1 ) ) {
66 $filepath = substr( $filepath, 1 );
67 }
68 if ( '/' === substr( $filepath, - 1 ) ) {
69 $filepath = substr( $filepath, 0, - 1 );
70 }
71 $protocol = ( ! empty( $_SERVER['HTTPS'] ) && ( 'on' === $_SERVER['HTTPS'] ) ) ? 'https://' : 'http://';
72 $this->xoops_url = ( ! empty( $filepath ) ) ? $protocol . $_SERVER['HTTP_HOST'] . '/' . $filepath : $protocol . $_SERVER['HTTP_HOST'];
73
74 // find xoops_trust_path
75 $path = $this->root_path;
76 while ( strlen( $path ) > 4 ) {
77 if ( is_dir( $path . '/xoops_trust_path' ) ) {
78 $this->trust_path = $path . '/xoops_trust_path';
79 break;
80 }
81 if ( is_dir( $path . '/trust_path' ) ) {
82 $this->trust_path = $path . '/trust_path';
83 break;
84 }
85 $path = dirname( $path );
86 }
87 }
88 }
89
90 public function readPost() {
91 if ( isset( $_POST['database'] ) ) {
92 $this->database = $this->sanitizer->stripSlashesGPC( $_POST['database'] );
93 }
94 if ( isset( $_POST['dbhost'] ) ) {
95 $this->dbhost = $this->sanitizer->stripSlashesGPC( $_POST['dbhost'] );
96 }
97 if ( isset( $_POST['dbuname'] ) ) {
98 $this->dbuname = $this->sanitizer->stripSlashesGPC( $_POST['dbuname'] );
99 }
100 if ( isset( $_POST['dbpass'] ) ) {
101 $this->dbpass = $this->sanitizer->stripSlashesGPC( $_POST['dbpass'] );
102 }
103 if ( isset( $_POST['dbname'] ) ) {
104 $this->dbname = $this->sanitizer->stripSlashesGPC( $_POST['dbname'] );
105 }
106 if ( isset( $_POST['prefix'] ) ) {
107 $this->prefix = $this->sanitizer->stripSlashesGPC( $_POST['prefix'] );
108 }
109 if ( isset( $_POST['db_pconnect'] ) ) {
110 $this->db_pconnect = (int) $_POST['db_pconnect'] > 0 ? 1 : 0;
111 }
112 if ( isset( $_POST['root_path'] ) ) {
113 $this->root_path = $this->sanitizer->stripSlashesGPC( $_POST['root_path'] );
114 }
115 if ( isset( $_POST['trust_path'] ) ) {
116 $this->trust_path = $this->sanitizer->stripSlashesGPC( $_POST['trust_path'] );
117 }
118 if ( isset( $_POST['xoops_url'] ) ) {
119 $this->xoops_url = $this->sanitizer->stripSlashesGPC( $_POST['xoops_url'] );
120 }
121 if ( isset( $_POST['salt'] ) ) {
122 $this->salt = $this->sanitizer->stripSlashesGPC( $_POST['salt'] );
123 }
124 }
125
126 public function readConstant() {
127 if ( defined( 'XOOPS_DB_TYPE' ) ) {
128 $this->database = XOOPS_DB_TYPE;
129 }
130 if ( defined( 'XOOPS_DB_HOST' ) ) {
131 $this->dbhost = XOOPS_DB_HOST;
132 }
133 if ( defined( 'XOOPS_DB_USER' ) ) {
134 $this->dbuname = XOOPS_DB_USER;
135 }
136 if ( defined( 'XOOPS_DB_PASS' ) ) {
137 $this->dbpass = XOOPS_DB_PASS;
138 }
139 if ( defined( 'XOOPS_DB_NAME' ) ) {
140 $this->dbname = XOOPS_DB_NAME;
141 }
142 if ( defined( 'XOOPS_DB_PREFIX' ) ) {
143 $this->prefix = XOOPS_DB_PREFIX;
144 }
145 if ( defined( 'XOOPS_DB_PCONNECT' ) ) {
146 $this->db_pconnect = XOOPS_DB_PCONNECT > 0 ? 1 : 0;
147 }
148 if ( defined( 'XOOPS_ROOT_PATH' ) ) {
149 $this->root_path = XOOPS_ROOT_PATH;
150 }
151 if ( defined( 'XOOPS_TRUST_PATH' ) ) {
152 $this->trust_path = XOOPS_TRUST_PATH;
153 }
154 if ( defined( 'XOOPS_URL' ) ) {
155 $this->xoops_url = XOOPS_URL;
156 }
157 if ( defined( 'XOOPS_SALT' ) ) {
158 $this->salt = XOOPS_SALT;
159 }
160 }
161
162 public function checkData() {
163 $ret = '';
164 $error = [];
165
166 if ( empty( $this->dbhost ) ) {
167 $error[] = sprintf( _INSTALL_L57, _INSTALL_L27 );
168 }
169 if ( empty( $this->dbname ) ) {
170 $error[] = sprintf( _INSTALL_L57, _INSTALL_L29 );
171 }
172 if ( empty( $this->prefix ) ) {
173 $error[] = sprintf( _INSTALL_L57, _INSTALL_L30 );
174 }
175 if ( empty( $this->salt ) ) {
176 $error[] = sprintf( _INSTALL_L57, _INSTALL_LANG_XOOPS_SALT );
177 }
178 if ( empty( $this->root_path ) ) {
179 $error[] = sprintf( _INSTALL_L57, _INSTALL_L55 );
180 }
181 if ( empty( $this->trust_path ) ) {
182 $error[] = sprintf( _INSTALL_L57, _INSTALL_L55 );
183 }
184 if ( empty( $this->xoops_url ) ) {
185 $error[] = sprintf( _INSTALL_L57, _INSTALL_L56 );
186 }
187
188 if ( ! empty( $error ) ) {
189 $ret .= '<div class="confirmError">';
190 foreach ( $error as $err ) {
191 $ret .= $err.'<br>';
192 }
193 $ret .= '</div>';
194 }
195
196 return $ret;
197 }
198
199 public function editform() {
200 $ret = '<h4>' . _INSTALL_L51 . '</h4>
201 <p><small>' . _INSTALL_L66 . '</small>
202 <br>
203 <select size="1" name="database" id="database">';
204 $dblist = $this->getDBList();
205 foreach ( $dblist as $val ) {
206 $ret .= '<option value="' . $val . '"';
207 if ( $val === $this->database ) {
208 $ret .= ' selected="selected"';
209 }
210 $ret .= '>' . $val . '</option>';
211 }
212 $ret .= '</select></p>';
213 $ret .= $this->editform_sub( _INSTALL_L27, _INSTALL_L67, 'dbhost', $this->sanitizer->htmlSpecialChars( $this->dbhost ) );
214 $ret .= $this->editform_sub( _INSTALL_L28, _INSTALL_L65, 'dbuname', $this->sanitizer->htmlSpecialChars( $this->dbuname ) );
215 $ret .= $this->editform_sub( _INSTALL_L52, _INSTALL_L68, 'dbpass', $this->sanitizer->htmlSpecialChars( $this->dbpass ) );
216 $ret .= $this->editform_sub( _INSTALL_L29, _INSTALL_L64, 'dbname', $this->sanitizer->htmlSpecialChars( $this->dbname ) );
217 $ret .= $this->editform_sub( _INSTALL_L30, _INSTALL_L63, 'prefix', $this->sanitizer->htmlSpecialChars( $this->prefix ) );
218 $ret .= $this->editform_sub( _INSTALL_LANG_XOOPS_SALT, _INSTALL_LANG_XOOPS_SALT_DESC, 'salt', $this->sanitizer->htmlSpecialChars( $this->salt ) );
219
220 $ret .= '<h4>' . _INSTALL_L54 . '</h4>
221 <p><span style="font-size:85%;">' . _INSTALL_L69 . '</span></p>
222 <p><input type="radio" name="db_pconnect" value="1"' . ( 1 === $this->db_pconnect ? ' checked="checked"' : '' ) . '>' . _INSTALL_L23 . '
223 <input type="radio" name="db_pconnect" value="0"' . ( 1 !== $this->db_pconnect ? ' checked="checked"' : '' ) . '>' . _INSTALL_L24 . '
224 </p>';
225
226 $ret .= $this->editform_sub( _INSTALL_L55, _INSTALL_L59, 'root_path', $this->sanitizer->htmlSpecialChars( $this->root_path ) );
227 $ret .= $this->editform_sub( _INSTALL_L75, _INSTALL_L76, 'trust_path', $this->sanitizer->htmlSpecialChars( $this->trust_path ) );
228 $ret .= $this->editform_sub( _INSTALL_L56, _INSTALL_L58, 'xoops_url', $this->sanitizer->htmlSpecialChars( $this->xoops_url ) );
229
230 return $ret;
231 }
232
233 public function editform_sub( $title, $desc, $name, $value ) {
234 return '<h4>' . $title . '</h4>
235 <p><span style="font-size:85%;">' . $desc . '</span><br>
236 <input type="text" name="' . $name . '" id="' . $name . '" size="30" maxlength="100" value="' . htmlspecialchars( $value, ENT_QUOTES | ENT_HTML5 ) . '">
237 </p>';
238 }
239
240 public function confirmForm() {
241 $yesno = empty( $this->db_pconnect ) ? _INSTALL_L24 : _INSTALL_L23;
242 $ret = '<h3>' . _INSTALL_L51 . '</h3>
243 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->database ) . '</p>
244 <h4>' . _INSTALL_L27 . '</h4>
245 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbhost ) . '</p>
246 <h4>' . _INSTALL_L28 . '</h4>
247 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbuname ) . '</p>
248 <h4>' . _INSTALL_L52 . '</h4>
249 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbpass ) . '</p>
250 <h4>' . _INSTALL_L29 . '</h4>
251 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->dbname ) . '</p>
252 <h4>' . _INSTALL_L30 . '</h4>
253 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->prefix ) . '</p>
254 <h4>' . _INSTALL_LANG_XOOPS_SALT . '</h4>
255 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->salt ) . '</p>
256 <h4>' . _INSTALL_L54 . '</h4>
257 <p class="data">' . $yesno . '</p>
258 <h4>' . _INSTALL_L55 . '</h4>
259 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->root_path ) . '</p>
260 <h4>' . _INSTALL_L75 . '</h4>
261 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->trust_path ) . '</p>
262 <h4>' . _INSTALL_L56 . '</h4>
263 <p class="data">' . $this->sanitizer->htmlSpecialChars( $this->xoops_url ) . '</p>
264 <br>
265 <input type="hidden" name="database" value="' . $this->sanitizer->htmlSpecialChars( $this->database ) . '">
266 <input type="hidden" name="dbhost" value="' . $this->sanitizer->htmlSpecialChars( $this->dbhost ) . '">
267 <input type="hidden" name="dbuname" value="' . $this->sanitizer->htmlSpecialChars( $this->dbuname ) . '">
268 <input type="hidden" name="dbpass" value="' . $this->sanitizer->htmlSpecialChars( $this->dbpass ) . '">
269 <input type="hidden" name="dbname" value="' . $this->sanitizer->htmlSpecialChars( $this->dbname ) . '">
270 <input type="hidden" name="prefix" value="' . $this->sanitizer->htmlSpecialChars( $this->prefix ) . '">
271 <input type="hidden" name="salt" value="' . $this->sanitizer->htmlSpecialChars( $this->salt ) . '">
272 <input type="hidden" name="db_pconnect" value="' . (int) $this->db_pconnect . '">
273 <input type="hidden" name="root_path" value="' . $this->sanitizer->htmlSpecialChars( $this->root_path ) . '">
274 <input type="hidden" name="trust_path" value="' . $this->sanitizer->htmlSpecialChars( $this->trust_path ) . '">
275 <input type="hidden" name="xoops_url" value="' . $this->sanitizer->htmlSpecialChars( $this->xoops_url ) . '">
276 ';
277 return $ret;
278 }
279
280
281 public function getDBList() {
282
283 // Validate if the MySQLi extension is present
284// if (extension_loaded('mysqli')) {
285// trigger_error('The extension "MySQLi" is not available', E_USER_ERROR);
286// }
287
288
289 return [ extension_loaded( 'mysql' ) ? 'mysql' : 'mysqli' ];
290 $dirname = '../class/database/';
291 $dirlist = [];
292 if (is_dir($dirname) && $handle = opendir($dirname)) {
293 while (false !== ($file = readdir($handle))) {
294 if ( !preg_match("/^[.]{1,2}$/",$file) ) {
295 if (strtolower($file) != 'cvs' && is_dir($dirname.$file) ) {
296 $dirlist[$file] = strtolower($file);
297 }
298 }
299 }
300 closedir($handle);
301 asort($dirlist);
302 reset($dirlist);
303 }
304 return $dirlist;
305 }
306}
__construct($post=false)