コード例 #1
0
ファイル: SpotPage_edituser.php プロジェクト: niel/spotweb
 function render()
 {
     $groupMembership = array();
     $formMessages = array('errors' => array(), 'info' => array());
     # check the users' permissions
     if ($this->_userIdToEdit == $this->_currentSession['user']['userid']) {
         $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_edit_own_user, '');
     } else {
         $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_edit_other_users, '');
     }
     # if
     # per default the result is 'not tried'
     $editResult = array();
     # Instantiate the spotuser object
     $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings);
     # and create a nic and shiny page title
     $this->_pageTitle = "spot: edit user";
     # retrieve the to-edit user
     $spotUser = $this->_db->getUser($this->_userIdToEdit);
     if ($spotUser === false) {
         $formMessages['errors'][] = sprintf(_('User %d can not be found'), $this->_userIdToEdit);
         $editResult = array('result' => 'failure');
     }
     # if
     # request the users' groupmembership
     if ($spotUser != false) {
         $groupMembership = $this->_db->getGroupList($spotUser['userid']);
     }
     # if
     /* 
      * bring the forms' action into the local scope for 
      * easier access
      */
     $formAction = $this->_editUserForm['action'];
     # Only perform certain validations when the form is actually submitted
     if (!empty($formAction) && empty($formMessages['errors'])) {
         # sta niet toe, dat de admin user gewist wordt
         if ($spotUser['userid'] <= SPOTWEB_ADMIN_USERID && $formAction == 'delete') {
             $formMessages['errors'][] = _('Admin and Anonymous can not be deleted');
             $editResult = array('result' => 'failure');
         }
         # if
     }
     # if
     # Only perform certain validations when the form is actually submitted
     if (!empty($formAction) && empty($formMessages['errors'])) {
         switch ($formAction) {
             case 'delete':
                 $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_delete_user, '');
                 $spotUser = array_merge($spotUser, $this->_editUserForm);
                 $spotUserSystem->removeUser($spotUser['userid']);
                 $editResult = array('result' => 'success');
                 break;
                 # case delete
             # case delete
             case 'edit':
                 # Remove any non-valid fields from the array
                 $this->_editUserForm = $this->cleanseEditForm($this->_editUserForm);
                 # validate the user fields
                 $spotUser = array_merge($spotUser, $this->_editUserForm);
                 $formMessages['errors'] = $spotUserSystem->validateUserRecord($spotUser, true);
                 if (empty($formMessages['errors'])) {
                     # actually update the user record
                     $spotUserSystem->setUser($spotUser);
                     /*
                      * Update the users' password, but only when
                      * a new password is given
                      */
                     if (!empty($spotUser['newpassword1'])) {
                         $spotUserSystem->setUserPassword($spotUser);
                     }
                     # if
                     /*
                      * Did we get an groupmembership list? If so,
                      * try to update it as well
                      */
                     if (isset($this->_editUserForm['grouplist'])) {
                         # retrieve the list of user groups
                         $groupList = array();
                         foreach ($this->_editUserForm['grouplist'] as $val) {
                             if ($val != 'dummy') {
                                 $groupList[] = array('groupid' => $val, 'prio' => count($groupList));
                             }
                             # if
                         }
                         # for
                         # make sure there is at least one group
                         if (count($groupList) < 1) {
                             $formMessages['errors'][] = _('A user must be member of at least one group');
                             $editResult = array('result' => 'failure');
                         } else {
                             # Mangle the current group membership to a common format
                             $currentGroupList = array();
                             foreach ($groupList as $value) {
                                 $currentGroupList[] = $value['groupid'];
                             }
                             # foreach
                             # and mangle the new requested group membership
                             $tobeGroupList = array();
                             foreach ($groupMembership as $value) {
                                 $tobeGroupList[] = $value['id'];
                             }
                             # foreach
                             /*
                              * Try to compare the grouplist with the current
                              * grouplist. If the grouplist changes, the user 
                              * needs change group membership permissions
                              */
                             sort($currentGroupList, SORT_NUMERIC);
                             sort($tobeGroupList, SORT_NUMERIC);
                             /* 
                              * If the groupmembership list changes, lets make sure
                              * the user has the specific permission
                              */
                             $groupDiff = count($currentGroupList) != count($tobeGroupList);
                             for ($i = 0; $i < count($currentGroupList) && !$groupDiff; $i++) {
                                 $groupDiff = $currentGroupList[$i] != $tobeGroupList[$i];
                             }
                             # for
                             if ($groupDiff) {
                                 if ($this->_spotSec->allowed(SpotSecurity::spotsec_edit_groupmembership, '')) {
                                     $spotUserSystem->setUserGroupList($spotUser, $groupList);
                                 } else {
                                     $formMessages['errors'][] = _('Changing group membership is not allowed');
                                     $editResult = array('result' => 'failure');
                                 }
                                 # else
                             }
                             # if
                         }
                         # if
                     }
                     # if
                     # report success
                     $editResult = array('result' => 'success');
                 } else {
                     $editResult = array('result' => 'failure');
                 }
                 # else
                 break;
                 # case 'edit'
             # case 'edit'
             case 'removeallsessions':
                 $spotUserSystem->removeAllUserSessions($spotUser['userid']);
                 $editResult = array('result' => 'success');
                 break;
                 # case 'removeallsessions'
             # case 'removeallsessions'
             case 'resetuserapi':
                 $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_consume_api, '');
                 $user = $spotUserSystem->resetUserApi($spotUser);
                 $editResult = array('result' => 'success', 'newapikey' => $user['apikey']);
                 break;
                 # case resetuserapi
         }
         # switch
     }
     # if
     #- display stuff -#
     $this->template('edituser', array('edituserform' => $spotUser, 'formmessages' => $formMessages, 'editresult' => $editResult, 'groupMembership' => $groupMembership));
 }
コード例 #2
0
ファイル: install.php プロジェクト: niel/spotweb
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
}
コード例 #3
0
	function render() {
		$groupMembership = array();
		$formMessages = array('errors' => array(),
							  'info' => array());
							  
		# Controleer de users' rechten
		if ($this->_userIdToEdit == $this->_currentSession['user']['userid']) {
			$this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_edit_own_user, '');
		} else {
			$this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_edit_other_users, '');
		} # if
		
		# edituser resultaat is standaard niet geprobeerd
		$editResult = array();

		# Instantieer het Spot user system
		$spotUserSystem = new SpotUserSystem($this->_db, $this->_settings);
		
		# zet de page title
		$this->_pageTitle = "spot: edit user";
		
		# haal de te editten user op 
		$spotUser = $this->_db->getUser($this->_userIdToEdit);
		if ($spotUser === false) {
			$formMessages['errors'][] = array('edituser_usernotfound', array($spotUser['username']));
			$editResult = array('result' => 'failure');
		} # if
		
		# Vraag group membership van deze user op
		if ($spotUser != false) {
			$groupMembership = $this->_db->getGroupList($spotUser['userid']);
		} # if

		# Bepaal welke actie er gekozen was (welke knop ingedrukt was)
		$formAction = '';
		if (isset($this->_editUserForm['submitedit'])) {
			$formAction = 'edit';
			unset($this->_editUserForm['submitedit']);
		} elseif (isset($this->_editUserForm['submitdelete'])) {
			$formAction = 'delete';
			unset($this->_editUserForm['submitdelete']);
			
			$this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_delete_user, '');
		} elseif (isset($this->_editUserForm['submitresetuserapi'])) {
			$formAction = 'resetapi';
			unset($this->_editUserForm['submitresetuserapi']);

			$this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_consume_api, '');
		} elseif (isset($this->_editUserForm['removeallsessions'])) {
			$formAction = 'removeallsessions';
			unset($this->_editUserForm['removeallsessions']);
		} # else

		# Is dit een submit van een form, of nog maar de aanroep?
		if ((!empty($formAction)) && (empty($formMessages['errors']))) {
			# sta niet toe, dat de anonymous user gewijzigd wordt
			if ($spotUser['userid'] == SPOTWEB_ANONYMOUS_USERID) {
				$formMessages['errors'][] = array('edituser_cannoteditanonymous', array());
				$editResult = array('result' => 'failure');
			} # if

			# sta niet toe, dat de admin user gewist wordt
			if (($spotUser['userid'] <= SPOTWEB_ADMIN_USERID) && ($formAction == 'delete')) {
				$formMessages['errors'][] = array('edituser_cannotremovesystemuser', array());
				$editResult = array('result' => 'failure');
			} # if
		} # if


		# Is dit een submit van een form, of nog maar de aanroep?
		if ((!empty($formAction)) && (empty($formMessages['errors']))) {
			switch($formAction) {
				case 'delete' : {
					$spotUser = array_merge($spotUser, $this->_editUserForm);
					$spotUserSystem->removeUser($spotUser['userid']);
					$editResult = array('result' => 'success');

					break;
				} # case delete

				case 'edit'	: {
					# Verwijder eventueel niet geldige velden uit het formulier
					$this->_editUserForm = $this->cleanseEditForm($this->_editUserForm);
					
					# valideer de user
					$spotUser = array_merge($spotUser, $this->_editUserForm);
					$formMessages['errors'] = $spotUserSystem->validateUserRecord($spotUser, true);

					if (empty($formMessages['errors'])) {
						# bewerkt de user
						$spotUserSystem->setUser($spotUser);

						# als de gebruker een nieuw wachtwoord opgegeven heeft, update dan 
						# het wachtwoord ook
						if (!empty($spotUser['newpassword1'])) {
							$spotUserSystem->setUserPassword($spotUser);
						} # if
						
						# Zijn er ook groupmembership lijsten meegestuurd? Zo ja, 
						# en als de user het recht heeft, update die dan ook
						if (isset($this->_editUserForm['grouplist'])) {
							# vraag de lijst met usergroepen op
							$groupList = array();
							foreach($this->_editUserForm['grouplist'] as $val) {
								if ($val != 'dummy') {
									$groupList[] = array('groupid' => $val,
														'prio' => count($groupList));
								} # if
							} # for
							
							# zorg er voor dat er meer dan 1 groep overblijft
							if (count($groupList) < 1) {
								$formMessages['errors'][] = array('edituser_usermusthaveonegroup', array());
								$editResult = array('result' => 'failure');
							} else {
								$spotUserSystem->setUserGroupList($spotUser, $groupList);
							} # if
						} # if

						# als het toevoegen van de user gelukt is, laat het weten
						$editResult = array('result' => 'success');
					} else {
						$editResult = array('result' => 'failure');
					} # else
					break;
				} # case 'edit' 
				
				case 'removeallsessions' : {
					$spotUserSystem->removeAllUserSessions($spotUser['userid']);
					$editResult = array('result' => 'success');

					break;
				} # case 'removeallsessions'

				case 'resetapi' : {
					$user = $spotUserSystem->resetUserApi($spotUser);
					$editResult = array('result' => 'success', 'newapikey' => $user['apikey']);

					break;
				} # case resetapi
			} # switch
		} # if

		#- display stuff -#
		$this->template('edituser', array('edituserform' => $spotUser,
										    'formmessages' => $formMessages,
											'editresult' => $editResult,
											'groupMembership' => $groupMembership));
	} # render