Example #1
0
	/**
	 * @param cbantispamWhitelistTable $row
	 * @param array                    $input
	 * @param string                   $type
	 * @param int|string               $tab
	 * @param UserTable                $user
	 * @param cbPluginHandler          $plugin
	 */
	static public function showWhitelist( $row, $input, $type, $tab, $user, $plugin )
	{
		global $_CB_framework;

		cbValidator::loadValidation();

		$name			=	CBuser::getInstance( (int) $user->get( 'id' ), false )->getField( 'formatname', null, 'html', 'none', 'profile', 0, true );
		$pageTitle		=	CBTxt::T( 'WHITELIST_NAME', 'Whitelist [name]', array( '[name]' => $name ) );

		$_CB_framework->setPageTitle( $pageTitle );
		$_CB_framework->appendPathWay( htmlspecialchars( CBTxt::T( 'Whitelists' ) ), $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), true, $tab ) );
		$_CB_framework->appendPathWay( htmlspecialchars( $pageTitle ), $_CB_framework->pluginClassUrl( $plugin->element, true, ( $row->get( 'id' ) ? array( 'action' => 'whitelist', 'func' => ( $type ? $type : 'edit' ), 'id' => (int) $row->get( 'id' ), 'usr' => (int) $user->get( 'id' ) ) : array( 'action' => 'whitelist', 'func' => ( $type ? $type : 'new' ), 'usr' => (int) $user->get( 'id' ) ) ) ) );

		$return			=	'<div class="whitelistEdit">'
						.		'<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'whitelist', 'func' => 'save', 'id' => (int) $row->get( 'id' ), 'usr' => (int) $user->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="whitelistForm" id="whitelistForm" class="cb_form whitelistForm form-auto cbValidation">'
						.			( $pageTitle ? '<div class="whitelistTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null )
						.			'<div class="cbft_select cbtt_select form-group cb_form_line clearfix">'
						.				'<label for="type" class="col-sm-3 control-label">' . CBTxt::T( 'Type' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['type']
						.					getFieldIcons( 1, 1, null, CBTxt::T( 'Select the whitelist type. Type determines what value should be supplied.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="cbft_text cbtt_input form-group cb_form_line clearfix">'
						.				'<label for="value" class="col-sm-3 control-label">' . CBTxt::T( 'Value' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['value']
						.					getFieldIcons( 1, 1, null, CBTxt::T( 'Input whitelist value in relation to the type. User type use the users user_id (e.g. 42). IP Address type use a full valid IP Address (e.g. 192.168.0.1). Email type use a fill valid email address (e.g. invalid@cb.invalid). Email Domain type use a full email address domain after @ (e.g. example.com).' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">'
						.				'<label for="reason" class="col-sm-3 control-label">' . CBTxt::T( 'Reason' ) . '</label>'
						.				'<div class="cb_field col-sm-9">'
						.					$input['reason']
						.					getFieldIcons( 1, 0, null, CBTxt::T( 'Optionally input whitelist reason. Note this is for administrative purposes only.' ) )
						.				'</div>'
						.			'</div>'
						.			'<div class="form-group cb_form_line clearfix">'
						.				'<div class="col-sm-offset-3 col-sm-9">'
						.					'<input type="submit" value="' . htmlspecialchars( ( $row->get( 'id' ) ? CBTxt::T( 'Update Whitelist' ) : CBTxt::T( 'Create Whitelist' ) ) ) . '" class="whitelistButton whitelistButtonSubmit btn btn-primary"' . cbValidator::getSubmitBtnHtmlAttributes() . ' />&nbsp;'
						.					' <input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="whitelistButton whitelistButtonCancel btn btn-default" onclick="if ( confirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to cancel? All unsaved data will be lost!' ) ) . '\' ) ) { location.href = \'' . $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $tab ) . '\'; }" />'
						.				'</div>'
						.			'</div>'
						.			cbGetSpoofInputTag( 'plugin' )
						.		'</form>'
						.	'</div>';

		echo $return;
	}
Example #2
0
	/**
	 * Whitelists this attempt by ip address
	 *
	 * @return bool
	 */
	public function whitelist()
	{
		$ip					=	$this->get( 'ip_address' );

		if ( $ip ) {
			$whitelist		=	new cbantispamWhitelistTable();

			$whitelist->load( array( 'value' => $ip, 'type' => 'ip' ) );

			if ( ! $whitelist->get( 'id' ) ) {
				$whitelist->set( 'type', 'ip' );
				$whitelist->set( 'value', $ip );

				if ( ! $whitelist->store() ) {
					$this->setError( $whitelist->getError() );

					return false;
				}
			}
		}

		return true;
	}
	/**
	 * Deletes a user whitelist
	 *
	 * @param int       $id
	 * @param UserTable $user
	 */
	private function deleteWhitelist( $id, $user )
	{
		global $_CB_framework;

		$row			=	new cbantispamWhitelistTable();

		$row->load( (int) $id );

		$profileUrl		=	$_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, $this->_tab );

		if ( ! $row->get( 'id' ) ) {
			cbRedirect( $profileUrl, CBTxt::T( 'Not authorized.' ), 'error' );
		}

		if ( ! $row->delete() ) {
			cbRedirect( $profileUrl, CBTxt::T( 'WHITELIST_DELETE_FAILED', 'Whitelist failed to delete! Error: [error]', array( '[error]' => $row->getError() ) ), 'error' );
		}

		cbRedirect( $profileUrl, CBTxt::T( 'Whitelist deleted successfully!' ) );
	}