Exemple #1
0
function createSystem()
{
    global $settings;
    global $_testInstall_Ok;
    try {
        /*
         * The settings system is used to create a lot of output,
         * we swallow it all
         */
        ob_start();
        /*
         * Now create the database ...
         */
        $settings['db'] = $_SESSION['spotsettings']['db'];
        $spotUpgrader = new SpotUpgrader($settings['db'], $settings);
        $spotUpgrader->database();
        /*
         * and create all the different settings (only the default) ones
         */
        $spotUpgrader->settings();
        /*
         * Create the users
         */
        $spotUpgrader->users();
        /*
         * print all the output as HTML comment for debugging
         */
        $dbCreateOutput = ob_get_contents();
        ob_end_clean();
        /*
         * Now it is time to do something with
         * the information the user has given to us
         */
        $db = new SpotDb($_SESSION['spotsettings']['db']);
        $db->connect();
        /* 
         * add the database settings to the main settings array for now
         */
        $settings['db'] = $_SESSION['spotsettings']['db'];
        /* and create the database settings */
        $spotSettings = SpotSettings::singleton($db, $settings);
        /*
         * Update the NNTP settings in the databas
         */
        $spotSettings->set('nntp_nzb', $_SESSION['spotsettings']['nntp']['nzb']);
        $spotSettings->set('nntp_hdr', $_SESSION['spotsettings']['nntp']['hdr']);
        $spotSettings->set('nntp_post', $_SESSION['spotsettings']['nntp']['post']);
        /*
         * Create the given user
         */
        $spotUserSystem = new SpotUserSystem($db, $spotSettings);
        $spotUser = $_SESSION['spotsettings']['adminuser'];
        /*
         * Create a private/public key pair for this user
         */
        $spotSigning = Services_Signing_Base::newServiceSigning();
        $userKey = $spotSigning->createPrivateKey($spotSettings->get('openssl_cnf_path'));
        $spotUser['publickey'] = $userKey['public'];
        $spotUser['privatekey'] = $userKey['private'];
        /*
         * and actually add the user
         */
        $userId = $spotUserSystem->addUser($spotUser);
        # Change the administrators' account password to that of this created user
        $adminUser = $spotUserSystem->getUser(SPOTWEB_ADMIN_USERID);
        $adminUser['newpassword1'] = $spotUser['newpassword1'];
        $spotUserSystem->setUserPassword($adminUser);
        # update the settings with our system type and our admin id
        $spotSettings->set('custom_admin_userid', $userId);
        $spotSettings->set('systemtype', $spotUser['systemtype']);
        # Set the system type
        $spotUpgrader->resetSystemType($spotUser['systemtype']);
        /* 
         * Create the necessary database connection information
         */
        $dbConnectionString = '';
        switch ($_SESSION['spotsettings']['db']['engine']) {
            case 'mysql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'mysql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # mysql
            # mysql
            case 'postgresql':
                $dbConnectionString .= "\$dbsettings['engine'] = 'pdo_pgsql';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['host'] = '" . $_SESSION['spotsettings']['db']['host'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['dbname'] = '" . $_SESSION['spotsettings']['db']['dbname'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['user'] = '******'spotsettings']['db']['user'] . "';" . PHP_EOL;
                $dbConnectionString .= "\$dbsettings['pass'] = '******'spotsettings']['db']['pass'] . "';" . PHP_EOL;
                break;
                # postgresql
        }
        # switch
        # Try to create the dbsettings.inc.php file for the user
        @file_put_contents("dbsettings.inc.php", "<?php" . PHP_EOL . $dbConnectionString);
        $createdDbSettings = file_exists("dbsettings.inc.php");
        ?>

			<table summary="PHP settings">
				<tr> <th colspan='2'> Installation succesful </th> </tr>
				<tr> <td colspan='2'> Spotweb has been installed succesfuly! </td> </tr>
				<tr> <td colspan='2'> &nbsp; </td> </tr>
<?php 
        if (!$createdDbSettings) {
            ?>
				<tr> 
						<td> &rarr; </td>
						<td> 
								You need to create a textfile with the database settings in it. Please copy & paste the below
							exactly in a file called <i>dbsettings.inc.php</i>.
							<pre><?php 
            echo "&lt;?php " . PHP_EOL . $dbConnectionString;
            ?>
							</pre>
				 		</td> 
				</tr>
<?php 
        }
        ?>
				<tr> 
						<td> &rarr; </td>
						<td> 
							Spotweb retrieves its information from the newsservers, this is called "retrieving" or retrieval of Spots.
							You need to schedule a retrieval job to run <i>retrieve.php</i> on a regular basis. The first time retrieval
							is run this can take up to several hours before completion.
				 		</td> 
				</tr>
			</table>

			<?php 
        echo '<!-- ' . $dbCreateOutput . ' -->';
    } catch (Exception $x) {
        ?>
			<div id='error'><?php 
        echo $x->getMessage();
        ?>
				<?php 
        echo $x->getTraceAsString();
        ?>
			<br /><br />
			</div>
	<?php 
    }
    # exception
}
 function render()
 {
     $formMessages = array('errors' => array(), 'info' => array());
     # Controleer de users' rechten
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_create_new_user, '');
     # creeer een default spotuser zodat het form altijd
     # de waardes van het form kan renderen
     $spotUser = array('username' => '', 'firstname' => '', 'lastname' => '', 'mail' => '');
     # createuser resultaat is standaard niet geprobeerd
     $createResult = array();
     # Instantieer het Spot user system
     $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings);
     # zet de page title
     $this->_pageTitle = "spot: create user";
     # Is dit een submit van een form, of nog maar de aanroep?
     if (isset($this->_createUserForm['submit'])) {
         # submit unsetten we altijd
         unset($this->_createUserForm['submit']);
         # userid zetten we altijd op false voor het maken van een
         # nieuwe user, omdat validateUserRecord() anders denkt
         # dat we een bestaande user aan het bewerken zijn en we bv.
         # het mailaddress niet controleren op dubbelen behalve 'zichzelf'
         $this->_createUserForm['userid'] = false;
         # creeer een random password voor deze user
         $spotUser['newpassword1'] = substr($spotUserSystem->generateUniqueId(), 1, 9);
         $spotUser['newpassword2'] = $spotUser['newpassword1'];
         # valideer de user
         $spotUser = array_merge($spotUser, $this->_createUserForm);
         $formMessages['errors'] = $spotUserSystem->validateUserRecord($spotUser, false);
         # Is er geen andere user met dezelfde username?
         if ($this->_db->usernameExists($spotUser['username'])) {
             $formMessages['errors'][] = array('validateuser_usernameexists', array($spotUser['username']));
         }
         # if
         if (empty($formMessages['errors'])) {
             # Creer een private en public key paar voor deze user
             $spotSigning = new SpotSigning();
             $userKey = $spotSigning->createPrivateKey($this->_settings->get('openssl_cnf_path'));
             $spotUser['publickey'] = $userKey['public'];
             $spotUser['privatekey'] = $userKey['private'];
             # Notificatiesysteem initialiseren
             $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $this->_currentSession);
             # voeg de user toe
             $spotUserSystem->addUser($spotUser);
             # als het toevoegen van de user gelukt is, laat het weten
             $createResult = array('result' => 'success', 'user' => $spotUser['username'], 'password' => $spotUser['newpassword1']);
             # verstuur een e-mail naar de nieuwe gebruiker als daar om is gevraagd
             if ($this->_createUserForm['sendmail'] == "true" || $this->_createUserForm['sendmail'] == "on" || $this->_settings->get('sendwelcomemail')) {
                 $spotsNotifications->sendNewUserMail($spotUser);
             }
             # if
             # en verstuur een notificatie
             $spotsNotifications->sendUserAdded($spotUser['username'], $spotUser['newpassword1']);
         } else {
             $createResult = array('result' => 'failure');
         }
         # else
     }
     # if
     #- display stuff -#
     $this->template('createuser', array('createuserform' => $spotUser, 'formmessages' => $formMessages, 'createresult' => $createResult));
 }