XOOPS  2.6.0
page_siteinit.php
Go to the documentation of this file.
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 
27 require_once __DIR__ . '/include/common.inc.php';
28 
29 set_time_limit(0); // don't want this to timeout
30 
31 function exception_handler($exception)
32 {
33  echo "Uncaught exception: " , $exception->getMessage(), "\n";
34  var_dump($exception->getTrace());
35 }
36 
37 set_exception_handler('exception_handler');
38 
39 \Xoops\Core\Cache\CacheManager::createDefaultConfig();
40 
42 
43 // setup legacy db support
45 
46 //Set active modules in cache folder, delete caches if existing
47 //$xoops->setActiveModules();
48 $modules_active = array();
49 $xoops->cache()->write('system/modules/active', $modules_active);
50 
51 $root = dirname(__DIR__);
52 $language = $wizard->language;
53 $xoops->setConfig('locale', $language);
54 $xoops->loadLocale();
55 $xoops->loadLocale('system');
56 
57 // Install system module
58 include_once $root . "/modules/system/class/module.php";
59 include_once $root . "/modules/system/class/system.php";
60 
63 $status = $system_module->install('system', true);
64 if (!$status) {
65  $_SESSION['error'] = $system_module->error;
66  //$sql = $xoops->db()->getConfiguration()->getSQLLogger()->queries;
67 }
68 
69 $pageHasForm = true;
70 $pageHasHelp = false;
71 
72 $siteconfig = $_SESSION['siteconfig'];
73 
74 $error = $_SESSION['error'];
75 
76 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
77  $siteconfig['adminname'] = $_POST['adminname'];
78  $siteconfig['adminmail'] = $_POST['adminmail'];
79  $siteconfig['adminpass'] = $_POST['adminpass'];
80  $siteconfig['adminpass2'] = $_POST['adminpass2'];
81  $error = array();
82 
83  if (empty($siteconfig['adminname'])) {
84  $error['name'][] = ERR_REQUIRED;
85  }
86  if (empty($siteconfig['adminmail'])) {
87  $error['email'][] = ERR_REQUIRED;
88  }
89  if (empty($siteconfig['adminpass'])) {
90  $error['pass'][] = ERR_REQUIRED;
91  }
92  if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $siteconfig['adminmail'])) {
93  $error['email'][] = ERR_INVALID_EMAIL;
94  }
95  if ($siteconfig['adminpass'] != $siteconfig['adminpass2']) {
96  $error['pass'][] = ERR_PASSWORD_MATCH;
97  }
98  if ($error) {
99  $_SESSION['error'] = $error;
100  $_SESSION['siteconfig'] = $siteconfig;
101  $wizard->redirectToPage('+0');
102  return 200;
103  } else {
104  $_SESSION['error'] = $error;
105  $_SESSION['siteconfig'] = $siteconfig;
106  $wizard->redirectToPage('+1');
107  return 302;
108  }
109 } else {
110  $dbm = new XoopsDatabaseManager();
111 
112  if (!$dbm->isConnectable()) {
113  $_SESSION['error'] = $error;
114  $_SESSION['siteconfig'] = $siteconfig;
115  $wizard->redirectToPage('dbsettings');
116  exit();
117  }
118 
119  $res = $dbm->query("SELECT COUNT(*) FROM " . $dbm->db->prefix("users"));
120  list ($isadmin) = $dbm->db->fetchRow($res);
121 }
122 
123 ob_start();
124 
125 if ($isadmin) {
126  $pageHasForm = false;
127  $pageHasHelp = false;
128  echo "<div class='x2-note errorMsg'>" . ADMIN_EXIST . "</div>\n";
129 } else {
130  ?>
131 <fieldset>
132  <legend><?php echo LEGEND_ADMIN_ACCOUNT; ?></legend>
133 
134  <?php
135  echo '<script type="text/javascript">
136  var desc = new Array();
137  desc[0] = "' . PASSWORD_DESC . '";
138  desc[1] = "' . PASSWORD_VERY_WEAK . '";
139  desc[2] = "' . PASSWORD_WEAK . '";
140  desc[3] = "' . PASSWORD_BETTER . '";
141  desc[4] = "' . PASSWORD_MEDIUM . '";
142  desc[5] = "' . PASSWORD_STRONG . '";
143  desc[6] = "' . PASSWORD_STRONGEST . '";
144  </script>';
145 
146  echo xoFormField('adminname', $siteconfig['adminname'], ADMIN_LOGIN_LABEL);
147  if (!empty($error["name"])) {
148  echo '<ul class="diags1">';
149  foreach ($error["name"] as $errmsg) {
150  echo '<li class="failure">' . $errmsg . '</li>';
151  }
152  echo '</ul>';
153  }
154 
155  echo xoFormField('adminmail', $siteconfig['adminmail'], ADMIN_EMAIL_LABEL);
156  if (!empty($error["email"])) {
157  echo '<ul class="diags1">';
158  foreach ($error["email"] as $errmsg) {
159  echo '<li class="failure">' . $errmsg . '</li>';
160  }
161  echo '</ul>';
162  }
163  ?>
164 
165  <div id="password">
166  <div id="passwordinput">
167  <?php
168  echo xoPassField('adminpass', '', ADMIN_PASS_LABEL);
169  echo xoPassField('adminpass2', '', ADMIN_CONFIRMPASS_LABEL);
170  if (!empty($error["pass"])) {
171  echo '<ul class="diags1">';
172  foreach ($error["pass"] as $errmsg) {
173  echo '<li class="failure">' . $errmsg . '</li>';
174  }
175  echo '</ul>';
176  }
177  ?>
178  </div>
179 
180  <div id="passwordmetter" class="xoform-help">
181  <label class="xolabel" for='passwordStrength'><strong><?php echo PASSWORD_LABEL; ?></strong></label>
182 
183  <div id='passwordStrength' class='strength0'>
184  <span id='passwordDescription'><?php echo PASSWORD_DESC; ?></span>
185  </div>
186 
187  <label class="xolabel" for='password_generator'><strong><?php echo PASSWORD_GENERATOR; ?></strong></label>
188 
189  <div id="passwordgenerator">
190  <input type='text' name='generated_pw' id='generated_pw' value=''/><br/>
191  <button type='button' class="gradient_bar button" onclick='javascript:suggestPassword(14);'/>
192  <?php echo PASSWORD_GENERATE; ?></button>
193  <button type='button' class="gradient_bar button"
194  onclick='javascript:suggestPasswordCopy("adminpass");'/>
195  <?php echo PASSWORD_COPY; ?></button>
196  </div>
197  </div>
198  </div>
199  <br style="clear: both;"/>
200 </fieldset>
201 <script type="text/javascript">
202  showHideHelp(this);
203 </script>
204  <?php
205 
206 }
207 $content = ob_get_contents();
208 ob_end_clean();
209 $error = '';
210 
211 $_SESSION['error'] = $error;
212 $_SESSION['siteconfig'] = $siteconfig;
213 $_SESSION['pageHasHelp'] = $pageHasHelp;
214 $_SESSION['pageHasForm'] = $pageHasForm;
215 $_SESSION['content'] = $content;
216 include XOOPS_INSTALL_PATH . '/include/install_tpl.php';
const ERR_PASSWORD_MATCH
Definition: install.php:150
$_SESSION['error']
const PASSWORD_STRONG
Definition: install.php:222
$error
if(!$dbm->isConnectable()) $res
static getInstance()
Definition: system.php:46
static getInstance()
Definition: Xoops.php:160
const PASSWORD_VERY_WEAK
Definition: install.php:218
const PASSWORD_STRONGEST
Definition: install.php:223
$_SERVER['REQUEST_URI']
const ADMIN_LOGIN_LABEL
Definition: install.php:122
$siteconfig
xoPassField($name, $value, $label, $help= '')
Definition: functions.php:103
const PASSWORD_COPY
Definition: install.php:216
const ADMIN_EMAIL_LABEL
Definition: install.php:123
const PASSWORD_MEDIUM
Definition: install.php:221
const PASSWORD_GENERATOR
Definition: install.php:214
const PASSWORD_LABEL
Definition: install.php:212
const ADMIN_CONFIRMPASS_LABEL
Definition: install.php:125
$system_module
exit
Definition: browse.php:104
if(!$status) $pageHasForm
$wizard
Definition: common.inc.php:66
$root
$status
const PASSWORD_WEAK
Definition: install.php:219
const XOOPS_INSTALL_PATH
Definition: common.inc.php:33
xoFormField($name, $value, $label, $help= '')
Definition: functions.php:76
const ADMIN_EXIST
Definition: install.php:187
const PASSWORD_BETTER
Definition: install.php:220
const LEGEND_ADMIN_ACCOUNT
Definition: install.php:121
const ERR_INVALID_EMAIL
Definition: install.php:148
$system
$xoops
$GLOBALS['xoopsDB']
$language
$modules_active
const ERR_REQUIRED
Definition: install.php:149
const PASSWORD_DESC
Definition: install.php:213
const ADMIN_PASS_LABEL
Definition: install.php:124
exception_handler($exception)
$pageHasHelp
const PASSWORD_GENERATE
Definition: install.php:215
$content