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:
25:
26: include_once './class/textsanitizer.php';
27:
28: 29: 30: 31: 32: 33: 34:
35: class setting_manager {
36:
37: var $database;
38: var $dbhost;
39: var $dbuname;
40: var $dbpass;
41: var $dbname;
42: var $prefix;
43: var $db_pconnect;
44: var $root_path;
45: var $trust_path;
46: var $xoops_url;
47:
48: var $salt;
49:
50: var $sanitizer;
51:
52: function setting_manager($post=false){
53:
54: $this->sanitizer =& TextSanitizer::getInstance();
55: if($post){
56: $this->readPost();
57: }else{
58: $this->database = 'mysql';
59: $this->dbhost = 'localhost';
60:
61:
62:
63:
64: srand(microtime() * 10000);
65: do {
66: $this->prefix = substr(md5(rand()), 0, 6);
67: } while (!preg_match("/^[a-z]/", $this->prefix));
68:
69: $this->salt = substr(md5(rand()), 5, 8);
70:
71: $this->db_pconnect = 0;
72:
73: $this->root_path = str_replace('\\','/',getcwd());
74: $this->root_path = str_replace('/install', '', $this->root_path);
75:
76: $filepath = (! empty($_SERVER['REQUEST_URI']))
77: ? dirname($_SERVER['REQUEST_URI'])
78: : dirname($_SERVER['SCRIPT_NAME']);
79:
80: $filepath = str_replace('\\', '/', $filepath);
81: $filepath = str_replace('/install', '', $filepath);
82: if ( substr($filepath, 0, 1) == '/' ) {
83: $filepath = substr($filepath,1);
84: }
85: if ( substr($filepath, -1) == '/' ) {
86: $filepath = substr($filepath, 0, -1);
87: }
88: $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
89: $this->xoops_url = (!empty($filepath)) ? $protocol.$_SERVER['HTTP_HOST'].'/'.$filepath : $protocol.$_SERVER['HTTP_HOST'];
90:
91: $path = $this->root_path ;
92: while( strlen( $path ) > 4 ) {
93: if( is_dir( $path . '/xoops_trust_path' ) ) {
94: $this->trust_path = $path . '/xoops_trust_path' ;
95: break ;
96: }
97: $path = dirname( $path ) ;
98: }
99: }
100: }
101:
102: function readPost(){
103: if(isset($_POST['database']))
104: $this->database = $this->sanitizer->stripSlashesGPC($_POST['database']);
105: if(isset($_POST['dbhost']))
106: $this->dbhost = $this->sanitizer->stripSlashesGPC($_POST['dbhost']);
107: if(isset($_POST['dbuname']))
108: $this->dbuname = $this->sanitizer->stripSlashesGPC($_POST['dbuname']);
109: if(isset($_POST['dbpass']))
110: $this->dbpass = $this->sanitizer->stripSlashesGPC($_POST['dbpass']);
111: if(isset($_POST['dbname']))
112: $this->dbname = $this->sanitizer->stripSlashesGPC($_POST['dbname']);
113: if(isset($_POST['prefix']))
114: $this->prefix = $this->sanitizer->stripSlashesGPC($_POST['prefix']);
115: if(isset($_POST['db_pconnect']))
116: $this->db_pconnect = intval($_POST['db_pconnect']) > 0 ? 1 : 0;
117: if(isset($_POST['root_path']))
118: $this->root_path = $this->sanitizer->stripSlashesGPC($_POST['root_path']);
119: if(isset($_POST['trust_path']))
120: $this->trust_path = $this->sanitizer->stripSlashesGPC($_POST['trust_path']);
121: if(isset($_POST['xoops_url']))
122: $this->xoops_url = $this->sanitizer->stripSlashesGPC($_POST['xoops_url']);
123: if(isset($_POST['salt']))
124: $this->salt = $this->sanitizer->stripSlashesGPC($_POST['salt']);
125: }
126:
127: function readConstant(){
128: if(defined('XOOPS_DB_TYPE'))
129: $this->database = XOOPS_DB_TYPE;
130: if(defined('XOOPS_DB_HOST'))
131: $this->dbhost = XOOPS_DB_HOST;
132: if(defined('XOOPS_DB_USER'))
133: $this->dbuname = XOOPS_DB_USER;
134: if(defined('XOOPS_DB_PASS'))
135: $this->dbpass = XOOPS_DB_PASS;
136: if(defined('XOOPS_DB_NAME'))
137: $this->dbname = XOOPS_DB_NAME;
138: if(defined('XOOPS_DB_PREFIX'))
139: $this->prefix = XOOPS_DB_PREFIX;
140: if(defined('XOOPS_DB_PCONNECT'))
141: $this->db_pconnect = intval(XOOPS_DB_PCONNECT) > 0 ? 1 : 0;
142: if(defined('XOOPS_ROOT_PATH'))
143: $this->root_path = XOOPS_ROOT_PATH;
144: if(defined('XOOPS_TRUST_PATH'))
145: $this->trust_path = XOOPS_TRUST_PATH;
146: if(defined('XOOPS_URL'))
147: $this->xoops_url = XOOPS_URL;
148: if(defined('XOOPS_SALT'))
149: $this->salt = XOOPS_SALT;
150: }
151:
152: function checkData(){
153: $ret = '';
154: $error = array();
155:
156: if ( empty($this->dbhost) ) {
157: $error[] = sprintf(_INSTALL_L57, _INSTALL_L27);
158: }
159: if ( empty($this->dbname) ) {
160: $error[] = sprintf(_INSTALL_L57, _INSTALL_L29);
161: }
162: if ( empty($this->prefix) ) {
163: $error[] = sprintf(_INSTALL_L57, _INSTALL_L30);
164: }
165: if ( empty($this->salt) ) {
166: $error[] = sprintf(_INSTALL_L57, _INSTALL_LANG_XOOPS_SALT);
167: }
168: if ( empty($this->root_path) ) {
169: $error[] = sprintf(_INSTALL_L57, _INSTALL_L55);
170: }
171: if ( empty($this->trust_path) ) {
172: $error[] = sprintf(_INSTALL_L57, _INSTALL_L55);
173: }
174: if ( empty($this->xoops_url) ) {
175: $error[] = sprintf(_INSTALL_L57, _INSTALL_L56);
176: }
177:
178: if (!empty($error)) {
179: foreach ( $error as $err ) {
180: $ret .= '<p><span style="color:#ff0000;"><b>'.$err.'</b></span></p>'."\n";
181: }
182: }
183:
184: return $ret;
185: }
186:
187: function editform(){
188: $ret =
189: '<table width="100%" class="outer" cellspacing="5">
190: <tr valign="top" align="left">
191: <td class="head">
192: <b>'._INSTALL_L51.'</b><br />
193: <span style="font-size:85%;">'._INSTALL_L66.'</span>
194: </td>
195: <td class="even">
196: <select size="1" name="database" id="database">';
197: $dblist = $this->getDBList();
198: foreach($dblist as $val){
199: $ret .= '<option value="'.$val.'"';
200: if($val == $this->database) $ret .= ' selected="selected"';
201: $ret .= '>'.$val.'</option>';
202: }
203: $ret .= '</select>
204: </td>
205: </tr>
206: ';
207: $ret .= $this->editform_sub(_INSTALL_L27, _INSTALL_L67, 'dbhost', $this->sanitizer->htmlSpecialChars($this->dbhost));
208: $ret .= $this->editform_sub(_INSTALL_L28, _INSTALL_L65, 'dbuname', $this->sanitizer->htmlSpecialChars($this->dbuname));
209: $ret .= $this->editform_sub(_INSTALL_L52, _INSTALL_L68, 'dbpass', $this->sanitizer->htmlSpecialChars($this->dbpass));
210: $ret .= $this->editform_sub(_INSTALL_L29, _INSTALL_L64, 'dbname', $this->sanitizer->htmlSpecialChars($this->dbname));
211: $ret .= $this->editform_sub(_INSTALL_L30, _INSTALL_L63, 'prefix', $this->sanitizer->htmlSpecialChars($this->prefix));
212: $ret .= $this->editform_sub(_INSTALL_LANG_XOOPS_SALT, _INSTALL_LANG_XOOPS_SALT_DESC, 'salt', $this->sanitizer->htmlSpecialChars($this->salt));
213:
214: $ret .= '<tr valign="top" align="left">
215: <td class="head">
216: <b>'._INSTALL_L54.'</b><br />
217: <span style="font-size:85%;">'._INSTALL_L69.'</span>
218: </td>
219: <td class="even">
220: <input type="radio" name="db_pconnect" value="1"'.($this->db_pconnect == 1 ? ' checked="checked"' : '' ).' />'._INSTALL_L23.'
221: <input type="radio" name="db_pconnect" value="0"'.($this->db_pconnect != 1 ? ' checked="checked"' : '' ).' />'._INSTALL_L24.'
222: </td>
223: </tr>
224: ';
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: $ret .= "</table>";
231: return $ret;
232: }
233:
234: function editform_sub($title, $desc, $name, $value){
235: return '<tr valign="top" align="left">
236: <td class="head">
237: <b>'.$title.'</b><br />
238: <span style="font-size:85%;">'.$desc.'</span>
239: </td>
240: <td class="even">
241: <input type="text" name="'.$name.'" id="'.$name.'" size="30" maxlength="100" value="'.htmlspecialchars($value).'" />
242: </td>
243: </tr>
244: ';
245: }
246:
247: function confirmForm(){
248: $yesno = empty($this->db_pconnect) ? _INSTALL_L24 : _INSTALL_L23;
249: $ret =
250: '<table border="0" cellpadding="5" cellspacing="1" valign="top" width="90%" class="separate">
251: <tr>
252: <td class="bg3"><b>'._INSTALL_L51.'</b></td>
253: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->database).'</td>
254: </tr>
255: <tr>
256: <td class="bg3"><b>'._INSTALL_L27.'</b></td>
257: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->dbhost).'</td>
258: </tr>
259: <tr>
260: <td class="bg3"><b>'._INSTALL_L28.'</b></td>
261: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->dbuname).'</td>
262: </tr>
263: <tr>
264: <td class="bg3"><b>'._INSTALL_L52.'</b></td>
265: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->dbpass).'</td>
266: </tr>
267: <tr>
268: <td class="bg3"><b>'._INSTALL_L29.'</b></td>
269: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->dbname).'</td>
270: </tr>
271: <tr>
272: <td class="bg3"><b>'._INSTALL_L30.'</b></td>
273: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->prefix).'</td>
274: </tr>
275: <tr>
276: <td class="bg3"><b>'._INSTALL_LANG_XOOPS_SALT.'</b></td>
277: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->salt).'</td>
278: </tr>
279: <tr>
280: <td class="bg3"><b>'._INSTALL_L54.'</b></td>
281: <td class="bg1">'.$yesno.'</td>
282: </tr>
283: <tr>
284: <td class="bg3"><b>'._INSTALL_L55.'</b></td>
285: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->root_path).'</td>
286: </tr>
287: <tr>
288: <td class="bg3"><b>'._INSTALL_L75.'</b></td>
289: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->trust_path).'</td>
290: </tr>
291: <tr>
292: <td class="bg3"><b>'._INSTALL_L56.'</b></td>
293: <td class="bg1">'.$this->sanitizer->htmlSpecialChars($this->xoops_url).'</td>
294: </tr>
295: </table>
296: <input type="hidden" name="database" value="'.$this->sanitizer->htmlSpecialChars($this->database).'" />
297: <input type="hidden" name="dbhost" value="'.$this->sanitizer->htmlSpecialChars($this->dbhost).'" />
298: <input type="hidden" name="dbuname" value="'.$this->sanitizer->htmlSpecialChars($this->dbuname).'" />
299: <input type="hidden" name="dbpass" value="'.$this->sanitizer->htmlSpecialChars($this->dbpass).'" />
300: <input type="hidden" name="dbname" value="'.$this->sanitizer->htmlSpecialChars($this->dbname).'" />
301: <input type="hidden" name="prefix" value="'.$this->sanitizer->htmlSpecialChars($this->prefix).'" />
302: <input type="hidden" name="salt" value="'.$this->sanitizer->htmlSpecialChars($this->salt).'" />
303: <input type="hidden" name="db_pconnect" value="'.intval($this->db_pconnect).'" />
304: <input type="hidden" name="root_path" value="'.$this->sanitizer->htmlSpecialChars($this->root_path).'" />
305: <input type="hidden" name="trust_path" value="'.$this->sanitizer->htmlSpecialChars($this->trust_path).'" />
306: <input type="hidden" name="xoops_url" value="'.$this->sanitizer->htmlSpecialChars($this->xoops_url).'" />
307: ';
308: return $ret;
309: }
310:
311:
312: function getDBList()
313: {
314: return array('mysql');
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330: }
331: }
332:
333:
334: ?>
335: