public function up()
 {
     $cfg = \w34u\ssp\Configuration::getConfiguration();
     $query = "CREATE TABLE `" . $cfg->sessionTable . "` (\n\t\t  `SessionId` char(32) NOT NULL default '',\n\t\t  `UserId` char(32) NOT NULL default '',\n\t\t  `SessionTime` int(11) NOT NULL default '0',\n\t\t  `SessionName` varchar(30) NOT NULL default '',\n\t\t  `SessionIp` varchar(40) NOT NULL default '',\n\t\t  `SessionUserIp` varchar(40) NOT NULL default '',\n\t\t  `SessionCheckIp` tinyint(4) NOT NULL default '0',\n\t\t  `SessionRandom` int(11) NOT NULL default '0',\n\t\t  `SessionData` blob NOT NULL,\n\t\t  PRIMARY KEY  (`SessionId`),\n\t\t  KEY `SessionTime` (`SessionTime`)\n\t\t) CHARACTER SET " . $cfg->connectionEncoding . " COLLATE " . $cfg->tableCollation;
     $this->query($query);
     $query = "CREATE TABLE `" . $cfg->tokenTable . "` (\n\t\t  `token` char(32) NOT NULL default '',\n\t\t  `time` int(11) NOT NULL default '0',\n\t\t  `id` varchar(50) NOT NULL default '',\n\t\t  PRIMARY KEY  (`token`),\n\t\t  KEY `time` (`time`),\n\t\t  KEY `id` (`id`)\n\t\t) CHARACTER SET " . $cfg->connectionEncoding . " COLLATE " . $cfg->tableCollation;
     $this->query($query);
     $query = "CREATE TABLE `" . $cfg->userTable . "` (\n\t\t  `UserId` char(32) NOT NULL default '',\n\t\t  `UserEmail` varchar(255) NOT NULL default '',\n\t\t  `UserName` varchar(50) default NULL,\n\t\t  `UserPassword` varchar(255) NOT NULL default '',\n\t\t  `UserIp` varchar(30) NOT NULL default '',\n\t\t  `UserIpCheck` tinyint(4) NOT NULL default '0',\n\t\t  `UserAccess` varchar(20) NOT NULL default 'public',\n\t\t  `lang` varchar(10) NOT NULL default '',\n\t\t  `country` varchar(10) NOT NULL default '',\n\t\t  `UserDateLogon` int(11) NOT NULL default '0',\n\t\t  `UserDateLastLogon` int(11) NOT NULL default '0',\n\t\t  `UserDateCreated` int(11) NOT NULL default '0',\n\t\t  `UserDisabled` tinyint(4) NOT NULL default '0',\n\t\t  `UserPending` tinyint(4) NOT NULL default '0',\n\t\t  `UserAdminPending` tinyint(4) NOT NULL default '0',\n\t\t  `CreationFinished` tinyint(4) NOT NULL default '0',\n\t\t  `UserWaiting` tinyint(4) NOT NULL default '0',\n\t\t  `UserInvisible` tinyint(4) NOT NULL default '0',\n\t\t  PRIMARY KEY  (`UserId`),\n\t\t  KEY `UserEmail` (`UserEmail`),\n\t\t  UNIQUE KEY `UserName` (`UserName`),\n\t\t  KEY `UserPassword` (`UserPassword`),\n\t\t  KEY `UserDisabled` (`UserDisabled`,`UserPending`,`UserAdminPending`,`CreationFinished`,`UserWaiting`)\n\t\t) CHARACTER SET " . $cfg->connectionEncoding . " COLLATE " . $cfg->tableCollation;
     $this->query($query);
     $query = "CREATE TABLE `" . $cfg->userMiscTable . "` (\n\t\t  `UserId` char(32) NOT NULL default '',\n\t\t  `Title` varchar(15) NOT NULL default '',\n\t\t  `FirstName` varchar(20) NOT NULL default '',\n\t\t  `Initials` varchar(5) NOT NULL default '',\n\t\t  `FamilyName` varchar(30) NOT NULL default '',\n\t\t  `Address` varchar(255) NOT NULL default '',\n\t\t  `TownCity` varchar(30) NOT NULL default '',\n\t\t  `PostCode` varchar(10) NOT NULL default '',\n\t\t  `County` varchar(20) NOT NULL default '',\n\t\t  `Country` varchar(5) NOT NULL default '',\n\t\t  PRIMARY KEY  (`UserId`)\n\t\t) CHARACTER SET " . $cfg->connectionEncoding . " COLLATE " . $cfg->tableCollation;
     $this->query($query);
     $query = "CREATE TABLE `" . $cfg->responseTable . "` (\n\t\t  `token` char(32) NOT NULL default '',\n\t\t  `time` int(11) NOT NULL default '0',\n\t\t  `UserId` char(32) NOT NULL default '',\n\t\t  PRIMARY KEY  (`token`),\n\t\t  KEY `time` (`time`)\n\t\t) CHARACTER SET " . $cfg->connectionEncoding . " COLLATE " . $cfg->tableCollation;
     $this->query($query);
     $query = "CREATE TABLE `" . $cfg->tableRememberMe . "` (\n\t\t  `id` char(32) NOT NULL default '',\n\t\t  `user_id` char(32) NOT NULL default '',\n\t\t  `date_expires` int(11) NOT NULL default '0',\n\t\t  PRIMARY KEY  (`id`),\n\t\t  KEY `date_expires` (`date_expires`)\n\t\t) CHARACTER SET " . $cfg->connectionEncoding . " COLLATE " . $cfg->tableCollation;
     $this->query($query);
 }
Beispiel #2
0
<?php

namespace w34u\ssp;

require '../includeheader.php';
$cfg = \w34u\ssp\Configuration::getConfiguration();
if ($cfg->enableSetup !== true) {
    exit('Setup disabled, Enable in configuration, ->enableSetup');
}
$content = [];
if (!isset($_POST['SFC_Submit'])) {
    // set up database if not posting the form
    define('RUCKUSING_WORKING_BASE', getcwd());
    $db_config = (require RUCKUSING_WORKING_BASE . DIRECTORY_SEPARATOR . 'ruckusing.conf.php');
    if (isset($db_config['ruckusing_base'])) {
        define('RUCKUSING_BASE', $db_config['ruckusing_base']);
    } else {
        define('RUCKUSING_BASE', dirname(__FILE__));
    }
    require_once RUCKUSING_BASE . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.inc.php';
    $params = ['index.php', 'db:migrate'];
    $main = new \Ruckusing_FrameworkRunner($db_config, $params);
    $content['database_creation'] = $main->execute();
}
$session = new Protect();
$ssp = new Setup($session, true);
$admin = new UserAdmin($session, $ssp, '', 'sspsmalltemplate.tpl');
echo $admin->adminCreate($content);
Beispiel #3
0
    /**
     * Creates an admin user if non exists
     * @param array $content - Content from previous routines
     * @return bool - true on success
     */
    public function adminCreate($content)
    {
        // check for any exisiting admin users
        $adminAccess = array_filter($this->cfg->userLevels, function ($level) {
            $cfg = \w34u\ssp\Configuration::getConfiguration();
            if ($level >= $cfg->adminLevel) {
                return true;
            }
            return false;
        });
        $sql = '
			select
				UserId
			from
				%s
			where
				UserAccess in (%s)
				 ';
        $sql = sprintf($sql, $this->cfg->userTable, "'" . implode("','", array_keys($adminAccess)) . "'");
        $this->db->query($sql, [], "SSP Admin Creation: Finding any admin users");
        if ($this->db->numRows() > 0) {
            $content['admin_creation_status'] = $this->session->t('There are already admin users in the system, please delete these first if attempting to recover access to the system.');
        } else {
            // create admin user
            $form = new sfc\Form(SSP_Path(), 'none', 'createAdminForm');
            $form->tplf = 'adminCreateForm.tpl';
            $form->errorAutoFormDisplay = false;
            if ($this->cfg->loginType === 0) {
                $form->fe('text', 'email', 'Admin email');
                $form->currentElelementObject->required = true;
                $form->currentElelementObject->dataType = 'email';
            }
            if ($this->cfg->loginType === 1) {
                $form->fe('text', 'userName', 'Admin user name');
                $form->currentElelementObject->required = true;
                $form->currentElelementObject->dataType = 'email';
            }
            $form->fe('text', 'password1', 'Password');
            $form->currentElelementObject->required = true;
            $form->currentElelementObject->dataType = 'password';
            $form->fe('text', 'password2', 'Repeat the password');
            $form->currentElelementObject->required = true;
            $form->currentElelementObject->dataType = 'password';
            if ($form->processForm($_POST)) {
                if (!$form->error) {
                    if (strcmp($form->getField('password1'), $form->getField('password2')) === 0) {
                        $userId = md5(uniqid($this->cfg->magicUser, true));
                        $userPassword = $this->session->cryptPassword($form->getField('password1'));
                        $userDate = time();
                        $fields = array("UserId" => $userId, "UserPassword" => $userPassword, "UserAccess" => 'admin', "UserDateCreated" => $userDate, "CreationFinished" => "1");
                        if ($this->cfg->loginType === 0) {
                            $fields['UserEmail'] = $form->getField('email');
                        }
                        if ($this->cfg->loginType === 1) {
                            $fields['UserName'] = $form->getField('userName');
                        }
                        $this->db->insert($this->cfg->userTable, $fields, "SSP Admin Creation: Creating admin entry");
                        // create empty misc info
                        $this->userMiscInit($userId);
                        $userInfo = $this->db->get($this->cfg->userTable, array("UserId" => $userId), "Getting user info for auto login of admin on creation");
                        $login = new Logon($this->session, "", true, false);
                        $login->userLoginCheck($userInfo);
                        $content['admin_creation_status'] = $this->session->t('Admin user created');
                    } else {
                        $form->setError('password1', 'Please check the passwords, they must be the same');
                        $content['form'] = $form->create(true);
                    }
                } else {
                    $content['form'] = $form->create(true);
                }
            } else {
                $content['form'] = $form->create();
            }
        }
        $content['adminPath'] = $this->cfg->totalAdminScript;
        $tpl = new Template($content, 'adminCreate.tpl');
        $mainTpl = $this->tpl(['content' => $tpl->output(), 'title' => 'Site database creation and intialisation'], true);
        return $mainTpl->output();
    }
Beispiel #4
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->cfg = \w34u\ssp\Configuration::getConfiguration();
     $this->charset = $this->cfg->siteEncoding;
 }
 public function down()
 {
     $cfg = \w34u\ssp\Configuration::getConfiguration();
     $this->change_column($cfg->sessionTable, 'SessionRandom', 'integer', ['limit' => 11]);
 }
 public function down()
 {
     $cfg = \w34u\ssp\Configuration::getConfiguration();
     $this->change_column($cfg->userTable, 'UserIp', 'string', ['limit' => 30]);
 }