Пример #1
0
 public function index()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!\Core\user()->checkAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     if ($request->isPost()) {
         // Update/save the site id.
         ConfigHandler::Set('/livefyre/siteid', $_POST['siteid']);
         \Core\set_message('Set Site ID Successfully!', 'success');
         \Core\reload();
     }
     // Pull the configuration options to see if livefyre is currently setup.
     $siteid = ConfigHandler::Get('/livefyre/siteid');
     // Generate the form to either set or update the siteid.
     $form = new Form();
     $form->set('method', 'POST');
     $form->addElement('text', ['name' => 'siteid', 'title' => 'Site ID', 'value' => $siteid]);
     $view->assign('siteid', $siteid);
     $view->assign('url', ROOT_URL_NOSSL);
     $view->assign('form', $form);
     // Setup instructions:
     // http://www.livefyre.com/install/
 }
Пример #2
0
 public function configure()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!\Core\user()->checkAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     if ($request->isPost()) {
         \ConfigHandler::Set('/piwik/server/host', $_POST['server_host']);
         \ConfigHandler::Set('/piwik/siteid', $_POST['site_id']);
         \ConfigHandler::Set('/piwik/tracking/all_subdomains', $_POST['all_domains']);
         \ConfigHandler::Set('/piwik/tracking/domain_title', $_POST['domain_title']);
         \Core\set_message('Updated Piwik settings successfully', 'success');
         \Core\reload();
     }
     $form = new Form();
     $form->addElement('text', ['name' => 'server_host', 'title' => 'Server Host', 'required' => false, 'value' => \ConfigHandler::Get('/piwik/server/host'), 'description' => 'Enter the hostname of your Piwik server without the protocol']);
     $form->addElement('text', ['name' => 'site_id', 'title' => 'Site ID', 'required' => false, 'value' => \ConfigHandler::Get('/piwik/siteid'), 'description' => 'Enter the Site ID of this installation']);
     $form->addElement('checkbox', ['name' => 'all_domains', 'title' => 'Track visitors across all subdomains of your site', 'description' => 'So if one visitor visits x.corepl.us and y.corepl.us, they will be counted as a single unique visitor.', 'value' => '1', 'checked' => \ConfigHandler::Get('/piwik/tracking/all_subdomains')]);
     $form->addElement('checkbox', ['name' => 'domain_title', 'title' => 'Prepend the site domain to the page title when tracking', 'description' => 'So if someone visits the "About" page on blog.corepl.us it will be recorded as "blog / About". This is the easiest way to get an overview of your traffic by sub-domain. ', 'value' => '1', 'checked' => \ConfigHandler::Get('/piwik/tracking/domain_title')]);
     $form->addElement('submit', ['name' => 'submit', 'value' => 'Update']);
     $view->title = 'Piwik Analytics';
     $view->assign('form', $form);
 }
Пример #3
0
	/**
	 * @deprecated 2013.06.11 Please use the namespaced versions.
	 */
	static public function Reload() {
		trigger_error('Core::Reload is deprecated, please use \\Core\\reload() instead.', E_USER_DEPRECATED);
		\Core\reload();
	}
	/**
	 * The main configuration for any user option on the site.
	 *
	 * Displayed under the "Configure" menu.
	 *
	 * @return int
	 */
	public function admin() {
		$view    = $this->getView();
		$request = $this->getPageRequest();

		// This is a super-admin-only page!
		if(!\Core\user()->checkAccess('g:admin')){
			return View::ERROR_ACCESSDENIED;
		}
		
		$userConfigs = [];
		$userSchema = UserModel::GetSchema();
		foreach($userSchema as $k => $dat){
			if(
				$dat['type'] == Model::ATT_TYPE_UUID ||
				$dat['type'] == Model::ATT_TYPE_UUID_FK ||
				$dat['type'] == Model::ATT_TYPE_ID ||
				$dat['type'] == Model::ATT_TYPE_ID_FK ||
				(isset($dat['formtype']) && $dat['formtype'] == 'disabled') ||
				(isset($dat['form']) && isset($dat['form']['type']) && $dat['form']['type'] == 'disabled')
			){
				// Skip these columns.
				continue;
			}
			
			$title = t('STRING_MODEL_USERMODEL_' . strtoupper($k));
			
			$userConfigs[$k] = $title;
		}
		
		// Pull a list of options currently enabled for both registration and edit.
		$onReg = [];
		$onEdits = [];
		
		$curReg = explode('|', ConfigHandler::Get('/user/register/form_elements'));
		$curEdits = explode('|', ConfigHandler::Get('/user/edit/form_elements'));
		
		foreach($curReg as $k){
			if(isset($userConfigs[$k])){
				// It's a valid key in the current application!
				$onReg[] = [
					'key' => $k,
					'checked' => true,
					'title' => $userConfigs[$k],
				];
			}
		}
		foreach($curEdits as $k){
			if(isset($userConfigs[$k])){
				// It's a valid key in the current application!
				$onEdits[] = [
					'key' => $k,
					'checked' => true,
					'title' => $userConfigs[$k],
				];
			}
		}
		
		foreach($userConfigs as $k => $title) {
			// If any key isn't in either curReg and curEdit, tack it to the end of the respective array.
			if(!in_array($k, $curReg)) {
				$onReg[] = [
					'key'     => $k,
					'checked' => false,
					'title'   => $title,
				];
			}
			if(!in_array($k, $curEdits)) {
				$onEdits[] = [
					'key'     => $k,
					'checked' => false,
					'title'   => $title,
				];
			}
		}

		// Build a form to handle the config options themselves.
		// These will include password strength, whether or not captcha is enabled, etc.
		$configs = [
			'/user/displayas', '/user/displayname/anonymous', '/user/email/allowchanging', '/user/enableavatar',
			'/user/password/minlength',
			'/user/password/requirecapitals', '/user/password/requiresymbols', '/user/password/requirenumbers',
			'/user/profileedits/requireapproval',
			'/user/register/allowpublic', '/user/register/requireapproval', '/user/register/requirecaptcha',
		];
		$configform = new Form();

		foreach($configs as $key){
			$el = ConfigHandler::GetConfig($key)->getAsFormElement();
			// I don't need this, (Everything from this group will be on the root-level form).
			$el->set('group', null);
			$configform->addElement($el);
		}

		$authbackends = ConfigHandler::Get('/user/authdrivers');
		if(!$authbackends){
			$authbackendsenabled = [];
		}
		else{
			$authbackendsenabled = explode('|', $authbackends);
		}

		$authbackends = [];
		$available = [];
		foreach(Core::GetComponents() as $c){
			/** @var Component_2_1 $c */
			$available = array_merge($available, $c->getUserAuthDrivers());
		}

		foreach($authbackendsenabled as $k){
			if(!isset($available[$k])){
				continue;
			}

			$classname = $available[$k];

			if(!class_exists($classname)){
				continue;
			}
			try{
				/** @var \Core\User\AuthDriverInterface $class */
				$class = new $classname();
			}
			catch(Exception $e){
				continue;
			}

			$authbackends[] = [
				'name' => $k,
				'class' => $classname,
				'title' => $class->getAuthTitle(),
				'enabled' => true,
			];

			unset($available[$k]);
		}


		foreach($available as $k => $classname){
			if(!class_exists($classname)){
				continue;
			}

			try{
				/** @var \Core\User\AuthDriverInterface $class */
				$class = new $classname();
			}
			catch(Exception $e){
				continue;
			}

			$authbackends[] = [
				'name' => $k,
				'class' => $classname,
				'title' => $class->getAuthTitle(),
				'enabled' => false,
			];
		}


		if($request->isPost()){
			$onEditSelected = (isset($_POST['onedit'])) ? implode('|', $_POST['onedit']) : '';
			$onRegSelected  = (isset($_POST['onregister'])) ? implode('|', $_POST['onregister']) : '';
			$authSelected   = (isset($_POST['authbackend'])) ? implode('|', $_POST['authbackend']) : '';

			if($authSelected == ''){
				\Core\set_message('At least one auth backend is required, re-enabling datastore.', 'info');
				$authSelected = 'datastore';
			}
			
			ConfigHandler::Set('/user/register/form_elements', $onRegSelected);
			ConfigHandler::Set('/user/edit/form_elements', $onEditSelected);
			ConfigHandler::Set('/user/authdrivers', $authSelected);

			// Handle the actual config options too!
			foreach($configs as $key){
				ConfigHandler::Set($key, $_POST['config'][$key]);
			}

			\Core\set_message('Saved configuration options successfully', 'success');
			\Core\reload();
		}

		$view->mastertemplate = 'admin';
		$view->title = 'User Options';
		$view->assign('configform', $configform);
		$view->assign('auth_backends', $authbackends);
		$view->assign('on_register_elements', $onReg);
		$view->assign('on_edit_elements', $onEdits);
	}
Пример #5
0
	/**
	 * Function that is fired off on page load.
	 * This checks if a form was submitted and that form was present in the SESSION.
	 *
	 * @return null
	 */
	public static function CheckSavedSessionData() {
		// This needs to ignore the /form/savetemporary.ajax page!
		// This is a custom page that's meant to intercept all POST submissions.
		if(preg_match('#^/form/(.*)\.ajax$#', REL_REQUEST_PATH)) return;

		// There has to be data in the session.
		$forms = \Core\Session::Get('FormData/*');

		$formid = (isset($_REQUEST['___formid'])) ? $_REQUEST['___formid'] : false;
		$form   = false;

		foreach ($forms as $k => $v) {
			// If the object isn't a valid object after unserializing...
			if (!($el = unserialize($v))) {
				\Core\Session::UnsetKey('FormData/' . $k);
				continue;
			}

			// Check the expires time
			if ($el->get('expires') <= Time::GetCurrent()) {
				\Core\Session::UnsetKey('FormData/' . $k);
				continue;
			}

			if ($k == $formid) {
				// Remember this for after all the checks have finished.
				$form = $el;
			}
		}

		// No form found... simple enough
		if (!$form) return;

		// Otherwise
		/** @var $form Form */

		// Ensure the submission types match up.
		if (strtoupper($form->get('method')) != $_SERVER['REQUEST_METHOD']) {
			\Core\set_message('t:MESSAGE_ERROR_FORM_SUBMISSION_TYPE_DOES_NOT_MATCH');
			return;
		}

		// Ensure the REFERRER and original URL match up.
		if($_SERVER['HTTP_REFERER'] != $form->originalurl){
			// @todo This is reported to be causing issues with production sites.
			//       If found true, this check may need to be removed / refactored.
			//\Core\set_message('Form submission referrer does not match, please try your submission again.', 'error');
			SystemLogModel::LogInfoEvent(
				'Form Referrer Mismatch',
				'Form referrer does not match!  Submitted: [' . $_SERVER['HTTP_REFERER'] . '] Expected: [' . $form->originalurl . ']'
			);
			//return;
		}

		// Run though each element submitted and try to validate it.
		if (strtoupper($form->get('method')) == 'POST') $src =& $_POST;
		else $src =& $_GET;

		$form->loadFrom($src);

		// Try to load the form from that form.  That will call all of the model's validation logic
		// and will throw exceptions if it doesn't.
		try{
			$form->getModel();

			// Still good?
			if (!$form->hasError()){
				$status = call_user_func($form->get('callsmethod'), $form);
			}
			else{
				$status = false;
			}
		}
		catch(ModelValidationException $e){
			\Core\set_message($e->getMessage(), 'error');
			$status = false;
		}
		catch(GeneralValidationException $e){
			\Core\set_message($e->getMessage(), 'error');
			$status = false;
		}
		catch(Exception $e){
			if(DEVELOPMENT_MODE){
				// Developers get the full message
				\Core\set_message($e->getMessage(), 'error');
			}
			else{
				// While users of production-enabled sites get a friendlier message.
				\Core\set_message('t:MESSAGE_ERROR_FORM_SUBMISSION_UNHANDLED_EXCEPTION');
			}
			Core\ErrorManagement\exception_handler($e);
			$status = false;
		}

		// The form was submitted.  Set its persistent flag to true so that whatever may be listening for it can retrieve the user's values.
		$form->persistent = true;

		// Regardless, bundle this form back into the session so the controller can use it if needed.
		\Core\Session::Set('FormData/' . $formid, serialize($form));

		// Fail statuses.
		if ($status === false) return;
		if ($status === null) return;

		// Guess it's not false and not null... must be good then.

		// @todo Handle an internal save procedure for "special" groups such as pageinsertables and what not.

		// Cleanup
		\Core\Session::UnsetKey('FormData/' . $formid);


		if ($status === 'die'){
			// If it's set to die, simply exit the script without outputting anything.
			exit;
		}
		elseif($status === 'back'){
			if($form->referrer && $form->referrer != REL_REQUEST_PATH){
				// Go back to the original form's referrer.
				\Core\redirect($form->referrer);
			}
			else{
				// Use Core to guess which page to redirect back to, (not as reliable).
				\Core\go_back();
			}
		}
		elseif ($status === true){
			// If the return code is boolean true, it's a reload.
			\Core\reload();
		}
		elseif($status === REL_REQUEST_PATH || $status === CUR_CALL){
			// If the page returned the same page as the current url, force a reload, (as redirect will ignore it)
			\Core\reload();
		}
		else{
			// Anything else gets sent to the redirect system.
			\core\redirect($status);
		}
	}
 /**
  * Administrative page for configuring the Captcha settings.
  */
 public function admin()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     // This is an admin-only page.
     if (!\Core\user()->checkAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     // width, height
     // colors
     $presets = ['simple' => ['name' => 'I trust and like my visitors', 'alt' => 'Simple and easy', 'configs' => ['/captcha/minlength' => 4, '/captcha/maxlength' => 5, '/captcha/linethrough' => 0, '/captcha/yperiod' => 12, '/captcha/yamplitude' => 14, '/captcha/xperiod' => 11, '/captcha/xamplitude' => 2, '/captcha/maxrotation' => 4, '/captcha/blur' => false]], 'med' => ['name' => 'Meh...', 'alt' => 'Moderate level of difficulty', 'configs' => ['/captcha/minlength' => 5, '/captcha/maxlength' => 7, '/captcha/linethrough' => 1, '/captcha/yperiod' => 12, '/captcha/yamplitude' => 14, '/captcha/xperiod' => 11, '/captcha/xamplitude' => 2, '/captcha/maxrotation' => 8, '/captcha/blur' => true]], 'hard' => ['name' => 'All visitors deserve to be punished!', 'alt' => 'Hieroglyphics are easier', 'configs' => ['/captcha/minlength' => 6, '/captcha/maxlength' => 9, '/captcha/linethrough' => 4, '/captcha/yperiod' => 12, '/captcha/yamplitude' => 20, '/captcha/xperiod' => 11, '/captcha/xamplitude' => 6, '/captcha/maxrotation' => 12, '/captcha/blur' => true]]];
     // See if there's a preset option selected.
     $current = null;
     foreach ($presets as $key => $preset) {
         // This will skim through each preset and if all the options are set to this preset, then it must be the current.
         foreach ($preset['configs'] as $k => $v) {
             if (ConfigHandler::Get($k) != $v) {
                 continue 2;
             }
         }
         // Did it not continue?  Must be the current preset.
         //$current = $preset;
         $current = $key;
         break;
     }
     // This page uses a traditional form post.
     if ($request->isPost()) {
         // See if there's a preset
         $postpreset = $request->getPost('preset');
         if ($postpreset && $postpreset != $current && isset($presets[$postpreset])) {
             foreach ($presets[$postpreset]['configs'] as $k => $v) {
                 ConfigHandler::Set($k, $v);
             }
             \Core\set_message('Switched to ' . $presets[$postpreset]['name'] . ' preset.', 'success');
         }
         // And the blah post options.
         $postwidth = $request->getPost('width');
         $postheight = $request->getPost('height');
         $posttext = $request->getPost('formtext');
         if ($postwidth <= 0) {
             $postwidth = 100;
         }
         if ($postwidth > 400) {
             $postwidth = 400;
         }
         if ($postheight <= 0) {
             $postheight = 100;
         }
         if ($postheight > 200) {
             $postheight = 200;
         }
         if (!$posttext) {
             $posttext = 'Are you a Human?';
         }
         ConfigHandler::Set('/captcha/width', $postwidth);
         ConfigHandler::Set('/captcha/height', $postheight);
         ConfigHandler::Set('/captcha/formtext', $posttext);
         \Core\reload();
     }
     // Build the form.  This will be pretty simple :p
     $form = new Form();
     $presetoptions = array();
     if (!$current) {
         // Add the custom settings option.
         $presetoptions[''] = '-- Custom Settings --';
     }
     foreach ($presets as $key => $preset) {
         $presetoptions[$key] = $preset['name'] . ' (' . $preset['alt'] . ')';
     }
     $form->addElement('select', ['name' => 'preset', 'title' => 'Difficulty Level', 'options' => $presetoptions, 'value' => $current ? $current : '']);
     $form->addElement('text', ['name' => 'width', 'title' => 'Image Width', 'value' => ConfigHandler::Get('/captcha/width')]);
     $form->addElement('text', ['name' => 'height', 'title' => 'Image Height', 'value' => ConfigHandler::Get('/captcha/height')]);
     $form->addElement('text', ['name' => 'formtext', 'title' => 'Form Text', 'value' => ConfigHandler::Get('/captcha/formtext')]);
     // @todo Colors for foreground and background.
     $form->addElement('submit', ['name' => 'submit', 'value' => 'Save Settings']);
     $view->mastertemplate = 'admin';
     $view->title = 'Captcha Tweaks';
     $view->assign('form', $form);
 }
Пример #7
0
	/**
	 * There has been a file selected; check that file for headers and what not to display something useful to the user.
	 */
	private function _import2(){
		$view = $this->getView();
		$request = $this->getPageRequest();

		$filename = \Core\Session::Get('user-import/file');
		$file = \Core\Filestore\Factory::File($filename);
		$contents = $file->getContentsObject();

		if(!$contents instanceof \Core\Filestore\Contents\ContentCSV){
			\Core\set_message($file->getBaseFilename() . ' does not appear to be a valid CSV file!', 'error');
			\Core\Session::UnsetKey('user-import/file');
			\Core\reload();
		}

		$hasheader = $contents->hasHeader();
		$data = $contents->parse();
		$total = sizeof($data);

		// Since I don't want to display the entire dataset in the preview...
		if($hasheader){
			$header = $contents->getHeader();
		}
		else{
			$header = array();
			$i=0;
			foreach($data[0] as $k => $v){
				$header[$i] = 'Column ' . ($i+1);
				$i++;
			}
		}
		$colcount = sizeof($header);

		if($total > 11){
			$preview = array_splice($data, 0, 10);
		}
		else{
			$preview = $data;
		}

		$form = new Form();
		$form->set('callsmethod', 'User\\ImportHelper::FormHandler2');
		$form->addElement('system', ['name' => 'key', 'value' => \Core\Session::Get('user-import/key')]);
		$form->addElement(
			'checkbox',
			[
				'name' => 'has_header',
				'title' => 'Has Header',
				'value' => 1,
				'checked' => $hasheader,
				'description' => 'If this CSV has a header record on line 1, (as illustrated below), check this to ignore that line.'
			]
		);

		$form->addElement(
			'checkbox',
			[
				'name' => 'merge_duplicates',
				'title' => 'Merge Duplicate Records',
				'value' => 1,
				'checked' => true,
				'description' => 'Merge duplicate records that may be found in the import.'
			]
		);

		// Only display the user groups if the current user has access to manage user groups.
		$usergroups = UserGroupModel::Find(['context = ']);
		if(sizeof($usergroups) && \Core\user()->checkAccess('p:/user/groups/manage')){
			$usergroupopts = array();
			foreach($usergroups as $ug){
				$usergroupopts[$ug->get('id')] = $ug->get('name');
			}
			$form->addElement(
				'checkboxes',
				[
					'name' => 'groups[]',
					'title' => 'User Groups to Assign',
					'options' => $usergroupopts,
					'description' => 'Check which groups to set the imported users to.  If merge duplicate records is selected, any found users will be set to the checked groups, (and consequently unset from any unchecked groups).',
				]
			);
		}
		else{
			$form->addElement('hidden', ['name' => 'groups[]', 'value' => '']);
		}

		// Get the map-to options.
		$maptos = ['' => '-- Do Not Map --', 'email' => 'Email', 'password' => 'Password'];

		$configs = UserConfigModel::Find([], null, 'weight asc, name desc');
		foreach($configs as $c){
			$maptos[ $c->get('key') ] = $c->get('name');
		}

		$maptoselects = [];
		foreach($header as $key => $title){
			$value = '';
			if(isset($maptos[$key])) $value = $key;
			if(array_search($title, $maptos)) $value = array_search($title, $maptos);

			$form->addElement(
				'select',
				[
					'name' => 'mapto[' . $key . ']',
					'title' => $title,
					'options' => $maptos,
					'value' => $value
				]
			);
		}


		$view->templatename = 'pages/user/import2.tpl';
		$view->assign('has_header', $hasheader);
		$view->assign('header', $header);
		$view->assign('preview', $preview);
		$view->assign('form', $form);
		$view->assign('total', $total);
		$view->assign('col_count', $colcount);
	}