public function admin()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!\Core\user()->checkAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     $image = ConfigHandler::Get('/favicon/image');
     $form = new Form();
     $form->set('callsmethod', 'AdminController::_ConfigSubmit');
     $form->addElement(ConfigHandler::GetConfig('/favicon/image')->getAsFormElement());
     $form->addElement('submit', ['value' => t('STRING_SAVE')]);
     $view->title = 'Site Favicon';
     $view->assign('current', $image);
     $view->assign('form', $form);
 }
 public function admin()
 {
     $view = $this->getView();
     if (!$this->setAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     $dir = \ConfigHandler::Get('/markdownbrowser/basedir');
     $markdownFiles = [];
     if (!$dir) {
         \Core\set_message('t:MESSAGE_ERROR_MARKDOWNBROWSER_NO_CONFIGURED_DIRECTORY');
     } else {
         // Make sure it's readable!
         $dir = \Core\Filestore\Factory::Directory($dir);
         $dirbase = $dir->getPath();
         $dirlen = strlen($dirbase);
         if (!$dir->exists()) {
             \Core\set_message('t:MESSAGE_ERROR_MARKDOWNBROWSER_DIRECTORY_DOES_NOT_EXIST');
         } else {
             $files = $dir->ls('md', true);
             foreach ($files as $file) {
                 /** @var \Core\Filestore\File $file */
                 $fileBase = substr($file->getFilename(), $dirlen);
                 if (strpos($fileBase, 'index.md') !== false) {
                     $fileRel = substr($fileBase, 0, -8);
                 } else {
                     $fileRel = substr($fileBase, 0, -3);
                 }
                 $warning = '';
                 if (preg_match('/[A-Z]/', $fileRel) !== 0) {
                     $warning = t('STRING_MARKDOWNBROWSER_WARNING_FILE_HAS_CAPITALS');
                 } elseif (strpos($fileRel, ' ')) {
                     $warning = t('STRING_MARKDOWNBROWSER_WARNING_FILE_HAS_SPACES');
                 }
                 $markdownFiles[] = ['filename' => $fileBase, 'view_url' => '/markdownbrowser/view/' . $fileRel, 'edit_url' => '/markdownbrowser/update/' . $fileRel, 'page' => PageModel::Construct('/markdownbrowser/view/' . $fileRel), 'warning' => $warning];
             }
         }
     }
     $form = new Form();
     $form->set('callsmethod', 'AdminController::_ConfigSubmit');
     $form->addElement(ConfigHandler::GetConfig('/markdownbrowser/basedir')->asFormElement());
     $form->addElement(ConfigHandler::GetConfig('/markdownbrowser/source')->asFormElement());
     $form->addElement(ConfigHandler::GetConfig('/markdownbrowser/autoregister')->asFormElement());
     $form->addElement('submit', ['value' => t('STRING_SAVE')]);
     $view->title = 't:STRING_MARKDOWNBROWSER_ADMIN';
     $view->assign('form', $form);
     $view->assign('files', $markdownFiles);
 }
Esempio n. 3
0
 /**
  * View to set google API keys and other configuration options.
  */
 public function configure()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     $configs = ['general' => ['title' => 'General', 'configs' => ['/google/services/public_api_key']], 'analytics' => ['title' => 'Analytics', 'configs' => ['/google-analytics/accountid', '/google/tagmanager/tagid']], 'maps' => ['title' => 'Maps', 'configs' => ['/googlemaps/enterprise/privatekey', '/googlemaps/enterprise/clientname']], 'cse' => ['title' => 'Custom Search', 'configs' => ['/google/cse/key']]];
     $form = new Form();
     $form->set('callsmethod', 'GoogleController::ConfigureSave');
     foreach ($configs as $gk => $gdat) {
         $group = new FormTabsGroup(['name' => $gk, 'title' => $gdat['title']]);
         foreach ($gdat['configs'] as $c) {
             /** @var ConfigModel $config */
             $config = ConfigHandler::GetConfig($c);
             $group->addElement($config->getAsFormElement());
         }
         $form->addElement($group);
     }
     $form->addElement('submit', ['name' => 'submit', 'value' => 'Update Settings']);
     $view->title = 'Google Keys and Apps ';
     $view->assign('form', $form);
 }
 /**
  * Provide a UI for the simple site password option.
  */
 public function sitepassword()
 {
     $view = $this->getView();
     $request = $this->getPageRequest();
     if (!\Core\user()->checkAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     // Build a form to handle the config options themselves.
     // These will include password strength, whether or not captcha is enabled, etc.
     $configs = ['/security/site_password'];
     $configform = new Form();
     $configform->set('callsmethod', 'SecurityController::SitePasswordSave');
     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);
     }
     $configform->addElement('submit', ['name' => 'submit', 'value' => 'Save Password']);
     $view->title = 'Simple Site Password';
     $view->assign('form', $configform);
 }
Esempio n. 5
0
 /**
  * Internal function to parse and handle the configs in the theme.xml file.
  * This is used for installations and upgrades.
  *
  * Returns false if nothing changed, else will return the configuration options changed.
  *
  * @param boolean $install Set to false to force uninstall/disable mode.
  * @param int     $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
  *
  * @return false | array
  *
  * @throws \InstallerException
  */
 public function _parseConfigs($install = true, $verbosity = 0)
 {
     // Keep track of if this changed anything.
     $changes = array();
     $action = $install ? 'Installing' : 'Uninstalling';
     $set = $install ? 'Set' : 'Unset';
     \Core\Utilities\Logger\write_debug($action . ' configs for ' . $this->getName());
     // I need to get the schema definitions first.
     $node = $this->_xmlloader->getElement('configs');
     //$prefix = $node->getAttribute('prefix');
     // Now, get every table under this node.
     foreach ($node->getElementsByTagName('config') as $confignode) {
         /** @var \DOMElement $confignode */
         $key = $confignode->getAttribute('key');
         $options = $confignode->getAttribute('options');
         $type = $confignode->getAttribute('type');
         $default = $confignode->getAttribute('default');
         $title = $confignode->getAttribute('title');
         $description = $confignode->getAttribute('description');
         $mapto = $confignode->getAttribute('mapto');
         $encrypted = $confignode->getAttribute('encrypted');
         $formAtts = $confignode->getAttribute('form-attributes');
         if ($encrypted === null || $encrypted === '') {
             $encrypted = '0';
         }
         if ($verbosity == 2) {
             CLI::PrintActionStart($action . ' config ' . $key);
         }
         // Themes only allow for keys starting with "/theme/"!
         // This is to encourage that all themes share a common subset of configuration options.
         // EG: if the end user sees: "Site Logo", "Business Address", "Business Phone" on one theme,
         // they would be expecting to see those same options with the same values if they change the theme,
         // (and the new theme supports those same options).
         if (strpos($key, '/theme/') !== 0) {
             trigger_error('Please ensure that all config options in themes start with "/theme/"! (Mismatched config found in ' . $this->getName() . ':' . $key, E_USER_NOTICE);
             continue;
         }
         // Default if omitted.
         if (!$type) {
             $type = 'string';
         }
         $m = \ConfigHandler::GetConfig($key);
         $m->set('options', $options);
         $m->set('type', $type);
         $m->set('default_value', $default);
         $m->set('title', $title);
         $m->set('description', $description);
         $m->set('mapto', $mapto);
         $m->set('encrypted', $encrypted);
         $m->set('form_attributes', $formAtts);
         // Default from the xml, only if it's not already set.
         if ($m->get('value') === null || !$m->exists()) {
             $m->set('value', $confignode->getAttribute('default'));
         }
         // Allow configurations to overwrite any value.  This is useful on the initial installation.
         if (is_array(\Core\Session::Get('configs')) && isset(\Core\Session::Get('configs')[$key])) {
             $m->set('value', \Core\Session::Get('configs')[$key]);
         }
         if ($m->save()) {
             $changes[] = $set . ' configuration [' . $m->get('key') . '] to [' . $m->get('value') . ']';
             if ($verbosity == 2) {
                 CLI::PrintActionStatus(true);
             }
         } else {
             if ($verbosity == 2) {
                 CLI::PrintActionStatus('skip');
             }
         }
         // Make it available immediately
         \ConfigHandler::CacheConfig($m);
     }
     return sizeof($changes) ? $changes : false;
 }
 public function config()
 {
     // Admin-only page.
     if (!\Core\user()->checkAccess('g:admin')) {
         return View::ERROR_ACCESSDENIED;
     }
     $view = $this->getView();
     $keys = ['/package_repository/base_directory', '/package_repository/is_private', '/package_repository/description', '/package_repository/auto_ip_restrict'];
     $form = new Form();
     $form->set('callsmethod', 'AdminController::_ConfigSubmit');
     foreach ($keys as $k) {
         $c = ConfigHandler::GetConfig($k);
         $f = $c->asFormElement();
         // Don't need them grouped
         $f->set('group', '');
         $form->addElement($f);
     }
     $form->addElement('submit', ['value' => 'Save Options']);
     $view->title = 'Package Repository Configuration';
     $view->mastertemplate = 'admin';
     $view->assign('form', $form);
 }
 /**
  * Set a given skin for default use on email communications.
  *
  * Will NOT affect the theme selected.
  */
 public function setemaildefault()
 {
     $request = $this->getPageRequest();
     $view = $this->getView();
     $theme = $this->getPageRequest()->getParameter(0);
     $template = $this->getPageRequest()->getParameter('template');
     // If the browser prefers JSON data, send that.
     if ($request->prefersContentType(View::CTYPE_JSON)) {
         $view->contenttype = View::CTYPE_JSON;
     }
     // Validate
     if (!\Theme\validate_theme_name($theme)) {
         \Core\set_message('Invalid theme requested', 'error');
         \Core\go_back();
     }
     if (Core::IsComponentAvailable('multisite') && MultiSiteHelper::GetCurrentSiteID()) {
         $config_default = ConfigHandler::GetConfig('/theme/default_email_template');
         if ($config_default->get('overrideable') == 0) {
             // It's a child site and the admin never gave them permission to change default themes!
             \Core\set_message('Unable to set the default template on a child site, please ensure that the "/theme/default_email_template" config is set to be overrideable!', 'error');
             \Core\go_back();
         }
     }
     if ($request->isPost()) {
         if ($theme != ConfigHandler::Get('/theme/selected')) {
             \Core\set_message('The admin skin must be on the same theme as the site!', 'error');
             \Core\go_back();
         }
         ConfigHandler::Set('/theme/default_email_template', $template);
         \Core\set_message('Updated email skin', 'success');
         \Core\go_back();
     } else {
         return View::ERROR_BADREQUEST;
     }
 }
Esempio n. 8
0
	public function email_config(){
		// Admin-only page.
		if(!\Core\user()->checkAccess('g:admin')){
			return View::ERROR_ACCESSDENIED;
		}

		$view = $this->getView();

		$keys = [
			'/core/email/enable_sending',
			'/core/email/from',
			'/core/email/from_name',
			'/core/email/sandbox_to',
			'/core/email/mailer',
			'/core/email/sendmail_path',
			'/core/email/smtp_auth',
			'/core/email/smtp_host',
			'/core/email/smtp_domain',
			'/core/email/smtp_user',
			'/core/email/smtp_password',
			'/core/email/smtp_port',
			'/core/email/smtp_security',
		];

		$form = new Form();
		$form->set('callsmethod', 'AdminController::_ConfigSubmit');

		foreach($keys as $k){
			$c = ConfigHandler::GetConfig($k);
			$f = $c->asFormElement();
			// Don't need them grouped
			$f->set('group', '');
			$form->addElement($f);
		}
		$form->addElement('submit', ['value' => t('STRING_SAVE')]);

		$view->title = 'Email Options & Diagnostics';
		$view->assign('form', $form);
		$view->assign('email_enabled', ConfigHandler::Get('/core/email/enable_sending'));
	}
	/**
	 * 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);
	}
Esempio n. 10
0
	/**
	 * Internal function to parse and handle the configs in the component.xml file.
	 * This is used for installations and upgrades.
	 *
	 * Returns false if nothing changed, else will return an int of the number of configuration options changed.
	 *
	 * @param boolean $install   Set to false to force uninstall/disable mode.
	 * @param int     $verbosity (default 0) 0: standard output, 1: real-time, 2: real-time verbose output.
	 *
	 * @return boolean | int
	 * @throws InstallerException
	 */
	public function _parseConfigs($install = true, $verbosity = 0) {
		// Keep track of if this changed anything.
		$changes = array();

		$action = $install ? 'Installing' : 'Uninstalling';
		$set    = $install ? 'Set' : 'Removed';

		Core\Utilities\Logger\write_debug($action . ' configs for ' . $this->getName());

		// I need to get the schema definitions first.
		$node = $this->_xmlloader->getElement('configs');
		//$prefix = $node->getAttribute('prefix');
		$componentName = $this->getKeyName();

		// Now, get every table under this node.
		foreach ($node->getElementsByTagName('config') as $confignode) {
			/** @var DOMElement $confignode */
			$key         = $confignode->getAttribute('key');
			$options     = $confignode->getAttribute('options');
			$type        = $confignode->getAttribute('type');
			$default     = $confignode->getAttribute('default');
			$title       = $confignode->getAttribute('title');
			$description = $confignode->getAttribute('description');
			$mapto       = $confignode->getAttribute('mapto');
			$encrypted   = $confignode->getAttribute('encrypted');
			$formAtts    = $confignode->getAttribute('form-attributes');

			if($encrypted === null || $encrypted === '') $encrypted = '0';

			// Default if omitted.
			if(!$type) $type = 'string';

			if($verbosity == 2){
				CLI::PrintActionStart($action . ' config ' . $key);
			}

			$m   = ConfigHandler::GetConfig($key);
			if($install){
				// Installation/Upgrade Logic
				$m->set('options', $options);
				$m->set('type', $type);
				$m->set('default_value', $default);
				$m->set('title', $title);
				$m->set('description', $description);
				$m->set('mapto', $mapto);
				$m->set('encrypted', $encrypted);
				$m->set('form_attributes', $formAtts);
				$m->set('component', $componentName);

				// Default from the xml, only if it's not already set.
				if ($m->get('value') === null || !$m->exists()){
					$m->set('value', $confignode->getAttribute('default'));
				}
				// Allow configurations to overwrite any value.  This is useful on the initial installation.
				if(\Core\Session::Get('configs/' . $key) !== null){
					$m->set('value', \Core\Session::Get('configs/' . $key));
				}

				if ($m->save()){
					$changes[] = $set . ' configuration [' . $m->get('key') . '] to [' . $m->get('value') . ']';
					if($verbosity == 2){
						CLI::PrintActionStatus(true);
					}
				}
				else{
					if($verbosity == 2){
						CLI::PrintActionStatus('skip');
					}
				}

				// Make it available immediately
				ConfigHandler::CacheConfig($m);
			}
			else{
				// Uninstallation Logic
				$m->delete();

				$changes[] = $set . ' configuration [' . $key . ']';
				if($verbosity == 2){
					CLI::PrintActionStatus(true);
				}
			}
		}

		return (sizeof($changes)) ? $changes : false;

	} // private function _parseConfigs