Пример #1
0
function main_default($eventData)
{
    global $gEnv, $gLocale, $gPage_content;
    $jp_cfg = new ConfigFile(CONFIG_PATH . 'jpcache.cfg', true);
    $xml_def = '<vertgroup><name>prefs</name><children>
  <form><name>prefs</name><args><method>post</method><action type="encoded">' . urlencode(build_events_call_string('', array(array('main', 'default', ''), array('action', 'setprefs', '')))) . '</action></args><children>
    <grid><name>prefs</name><children>
      <label row="0" col="0"><name>cachetime</name><args><label type="encoded">' . urlencode($gLocale->GetStr('cachetime.label')) . '</label></args></label>
      <string row="0" col="1"><name>cachetime</name><args><disp>action</disp><size>5</size><value>' . $jp_cfg->Value('CACHE_TIME') . '</value></args></string>
      <label row="1" col="0"><name>cacheon</name><args><label type="encoded">' . urlencode($gLocale->GetStr('cacheon.label')) . '</label></args></label>
      <checkbox row="1" col="1"><name>cacheon</name><args><disp>action</disp><checked>' . ($jp_cfg->Value('CACHE_ON') == '1' ? 'true' : 'false') . '</checked></args></checkbox>
      <label row="2" col="0"><name>usegzip</name><args><label type="encoded">' . urlencode($gLocale->GetStr('usegzip.label')) . '</label></args></label>
      <checkbox row="2" col="1"><name>usegzip</name><args><disp>action</disp><checked>' . ($jp_cfg->Value('USE_GZIP') == '1' ? 'true' : 'false') . '</checked></args></checkbox>
      <label row="3" col="0"><name>cachepost</name><args><label type="encoded">' . urlencode($gLocale->GetStr('cachepost.label')) . '</label></args></label>
      <checkbox row="3" col="1"><name>cachepost</name><args><disp>action</disp><checked>' . ($jp_cfg->Value('CACHE_POST') == '1' ? 'true' : 'false') . '</checked></args></checkbox>
    </children></grid>
  </children></form>
  <horizbar><name>hb</name></horizbar>
  <button><name>submit</name>
    <args>
      <label type="encoded">' . urlencode($gLocale->GetStr('setprefs.submit')) . '</label>
      <themeimage>button_ok</themeimage>
      <horiz>true</horiz>
      <frame>true</frame>
      <formsubmit>prefs</formsubmit>
      <action type="encoded">' . urlencode(build_events_call_string('', array(array('main', 'default', ''), array('action', 'setprefs', '')))) . '</action>
    </args>
  </button>
</children></vertgroup>';
    $gPage_content = new HuiXml('page', array('definition' => $xml_def));
}
Пример #2
0
 public function fillDbLayers()
 {
     global $dbtypes;
     $dbtypes = array();
     $dbcfgfile = new ConfigFile(CONFIG_PATH . 'dblayers.cfg', TRUE);
     $dbtypes = (array) $dbcfgfile->ValuesArray();
 }
 /**
  * Returns allowed values for select fields
  *
  * @param string $option_path Option path
  *
  * @return array
  */
 public function getOptionValueList($option_path)
 {
     $value = $this->_configFile->getDbEntry($option_path);
     if ($value === null) {
         trigger_error("{$option_path} - select options not defined", E_USER_ERROR);
         return array();
     }
     if (!is_array($value)) {
         trigger_error("{$option_path} - not a static value list", E_USER_ERROR);
         return array();
     }
     // convert array('#', 'a', 'b') to array('a', 'b')
     if (isset($value[0]) && $value[0] === '#') {
         // remove first element ('#')
         array_shift($value);
         // $value has keys and value names, return it
         return $value;
     }
     // convert value list array('a', 'b') to array('a' => 'a', 'b' => 'b')
     $has_string_keys = false;
     $keys = array();
     for ($i = 0, $nb = count($value); $i < $nb; $i++) {
         if (!isset($value[$i])) {
             $has_string_keys = true;
             break;
         }
         $keys[] = is_bool($value[$i]) ? (int) $value[$i] : $value[$i];
     }
     if (!$has_string_keys) {
         $value = array_combine($keys, $value);
     }
     // $value has keys and value names, return it
     return $value;
 }
Пример #4
0
 /**
  * Returns validator list
  *
  * @param ConfigFile $cf Config file instance
  *
  * @return array
  */
 public static function getValidators(ConfigFile $cf)
 {
     static $validators = null;
     if ($validators === null) {
         $validators = $cf->getDbEntry('_validators', array());
         if (!defined('PMA_SETUP')) {
             // not in setup script: load additional validators for user
             // preferences we need original config values not overwritten
             // by user preferences, creating a new PMA_Config instance is a
             // better idea than hacking into its code
             $uvs = $cf->getDbEntry('_userValidators', array());
             foreach ($uvs as $field => $uv_list) {
                 $uv_list = (array) $uv_list;
                 foreach ($uv_list as &$uv) {
                     if (!is_array($uv)) {
                         continue;
                     }
                     for ($i = 1; $i < count($uv); $i++) {
                         if (substr($uv[$i], 0, 6) == 'value:') {
                             $uv[$i] = PMA_arrayRead(substr($uv[$i], 6), $GLOBALS['PMA_Config']->base_settings);
                         }
                     }
                 }
                 $validators[$field] = isset($validators[$field]) ? array_merge((array) $validators[$field], $uv_list) : $uv_list;
             }
         }
     }
     return $validators;
 }
/**
 * Common initialization for user preferences modification pages
 *
 * @param ConfigFile $cf Config file instance
 *
 * @return void
 */
function PMA_userprefsPageInit(ConfigFile $cf)
{
    $forms_all_keys = PMA_readUserprefsFieldNames($GLOBALS['forms']);
    $cf->resetConfigData();
    // start with a clean instance
    $cf->setAllowedKeys($forms_all_keys);
    $cf->setCfgUpdateReadMapping(array('Server/hide_db' => 'Servers/1/hide_db', 'Server/only_db' => 'Servers/1/only_db'));
    $cf->updateWithGlobalConfig($GLOBALS['cfg']);
}
Пример #6
0
 public static function factory($file, $type='file', $options=0) {
   $config = new ConfigFile();
   
   if (!$result = $config->loadFileType($file, $type, $options)) {
      die("FATAL ERROR: cannot load $type configuration file: " . self::getfileByType($file, $type));
   }
   
   return $config;
 }
Пример #7
0
 protected function getConfigVars()
 {
     require_once 'ConfigFile.class.php';
     // Load the config
     $configFilePath = $this->argv[1];
     global $configFile;
     $configFile = new ConfigFile($configFilePath);
     $configFile->load();
     $vars = $configFile->getVars();
     return $vars;
 }
Пример #8
0
 public static function factory($file, $type='file', $options=0) {
   $config = new ConfigFile();
   
   if (!$result = $config->loadFileType($file, $type, $options)) {
       if ($options & ConfigFile::OPTION_DIE_ON_FAILURE) {
         die("FATAL ERROR: cannot load $type configuration file: $file");
       }
   }
   
   return $config;
 }
Пример #9
0
 /**
  * Connects to the DB using the _POST array
  * Also writes a config file upon a successful connect
  */
 function connect()
 {
     $this->connector = new Connector($_POST[FORM_SERVER], $_POST[FORM_USER], $_POST[FORM_PASSWORD], $_POST[FORM_DATABASE]);
     $this->connector->connectDatabase();
     if ($this->connector->success()) {
         $cfg = new ConfigFile(CONFIG_FILE_NAME);
         $cfg->generate();
         return true;
     }
     echo "Couldn't connect to DB";
     return false;
 }
Пример #10
0
 public static function factory($file, $type='file', $options=0) {
   $config = new ConfigFile();
   if (!($options & self::OPTION_DO_NOT_CREATE)) {
       $options = $options | self::OPTION_CREATE_WITH_DEFAULT;
   }
   
   if (!$result = $config->loadFileType($file, $type, $options)) {
       if ($options & self::OPTION_DO_NOT_CREATE) {
           return false;
       }
      throw new Exception("FATAL ERROR: cannot load $type configuration file: " . self::getfileByType($file, $type));
   }
   
   return $config;
 }
Пример #11
0
 public static function factory($file, $type = 'file', $options = 0)
 {
     Kurogo::log(LOG_DEBUG, "Loading config file {$file} of type {$type} with options {$options}", 'config');
     $config = new ConfigFile();
     if (!($options & self::OPTION_DO_NOT_CREATE)) {
         $options = $options | self::OPTION_CREATE_WITH_DEFAULT;
     }
     if (!($result = $config->loadFileType($file, $type, $options))) {
         if ($options & self::OPTION_DO_NOT_CREATE) {
             return false;
         }
         throw new KurogoConfigurationException("FATAL ERROR: cannot load {$type} configuration file: " . self::getfileByType($file, $type));
     }
     return $config;
 }
Пример #12
0
 /**
  * Returns class instance
  *
  * @return ConfigFile
  */
 public static function getInstance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new ConfigFile();
     }
     return self::$_instance;
 }
Пример #13
0
 /**
  * Test for ConfigFile::getConfigArray
  *
  * @return void
  * @test
  */
 public function testGetConfigArray()
 {
     $this->object->setPersistKeys(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE));
     $this->object->set('Array/test', array('x', 'y'));
     $default_value = $this->object->getDefault(self::SIMPLE_KEY_WITH_DEFAULT_VALUE);
     $this->assertEquals(array(self::SIMPLE_KEY_WITH_DEFAULT_VALUE => $default_value, 'Array/test' => array('x', 'y')), $this->object->getConfigArray());
 }
 /**
  * Test for ConfigGenerator::getConfigFile
  *
  * @return void
  * @group medium
  */
 public function testGetConfigFile()
 {
     $GLOBALS['cfg']['AvailableCharsets'] = array();
     unset($_SESSION['eol']);
     $GLOBALS['PMA_Config'] = new PMA_Config();
     $GLOBALS['server'] = 0;
     $cf = new ConfigFile();
     $_SESSION['ConfigFile0'] = array('a', 'b', 'c');
     $_SESSION['ConfigFile0']['Servers'] = array(array(1, 2, 3));
     $cf->setPersistKeys(array("1/", 2));
     $date = date(DATE_RFC1123);
     $result = ConfigGenerator::getConfigFile($cf);
     $this->assertContains("<?php\n" . "/*\n" . " * Generated configuration file\n" . " * Generated by: phpMyAdmin " . $GLOBALS['PMA_Config']->get('PMA_VERSION') . " setup script\n" . " * Date: " . $date . "\n" . " */\n\n", $result);
     $this->assertContains("/* Servers configuration */\n" . '$i = 0;' . "\n\n" . "/* Server: localhost [0] */\n" . '$i++;' . "\n" . '$cfg[\'Servers\'][$i][\'0\'] = 1;' . "\n" . '$cfg[\'Servers\'][$i][\'1\'] = 2;' . "\n" . '$cfg[\'Servers\'][$i][\'2\'] = 3;' . "\n\n" . "/* End of servers configuration */\n\n", $result);
     $this->assertContains('?>', $result);
 }
Пример #15
0
 /**
  * Initializes the application.
  *
  * Sets the application's root directory, loads the configuration file
  * and initializes the authorization.
  *
  * @param string $rootDir Root directory of this application
  */
 public static function init($rootDir)
 {
     self::$rootDir = $rootDir;
     if (ConfigFile::load()) {
         Security\Authorization::init();
     }
 }
 public function loadModel($id)
 {
     $model = ConfigFile::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('mc', 'The requested page does not exist.'));
     }
     return $model;
 }
Пример #17
0
    /**
     * Creates config file
     *
     * @return string
     */
    public static function getConfigFile()
    {
        $cf = ConfigFile::getInstance();

        $crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win') ? "\r\n" : "\n";
        $c = $cf->getConfig();

        // header
        $ret = '<?php' . $crlf
            . '/*' . $crlf
            . ' * Generated configuration file' . $crlf
            . ' * Generated by: phpMyAdmin '
                    . $GLOBALS['PMA_Config']->get('PMA_VERSION')
                    . ' setup script' . $crlf
            . ' * Date: ' . date(DATE_RFC1123) . $crlf
            . ' */' . $crlf . $crlf;

        // servers
        if ($cf->getServerCount() > 0) {
            $ret .= "/* Servers configuration */$crlf\$i = 0;" . $crlf . $crlf;
            foreach ($c['Servers'] as $id => $server) {
                $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [$id] ", '*/', '-') . "*/" . $crlf
                    . '$i++;' . $crlf;
                foreach ($server as $k => $v) {
                    $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
                    $ret .= "\$cfg['Servers'][\$i]['$k'] = "
                        . (is_array($v) && self::_isZeroBasedArray($v)
                                ? self::_exportZeroBasedArray($v, $crlf)
                                : var_export($v, true))
                        . ';' . $crlf;
                }
                $ret .= $crlf;
            }
            $ret .= '/* End of servers configuration */' . $crlf . $crlf;
        }
        unset($c['Servers']);

        // other settings
        $persistKeys = $cf->getPersistKeysMap();

        foreach ($c as $k => $v) {
            $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
            $ret .= self::_getVarExport($k, $v, $crlf);
            if (isset($persistKeys[$k])) {
                unset($persistKeys[$k]);
            }
        }
        // keep 1d array keys which are present in $persist_keys (config.values.php)
        foreach (array_keys($persistKeys) as $k) {
            if (strpos($k, '/') === false) {
                $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
                $ret .= self::_getVarExport($k, $cf->getDefault($k), $crlf);
            }
        }
        $ret .= '?>';

        return $ret;
    }
Пример #18
0
/**
 * Runs validation $validator_id on values $values and returns error list.
 *
 * Return values:
 * o array, keys - field path or formset id, values - array of errors
 *   when $isPostSource is true values is an empty array to allow for error list
 *   cleanup in HTML documen
 * o false - when no validators match name(s) given by $validator_id
 *
 * @param string|array $validator_id ID of validator(s) to run
 * @param array        $values       Values to validate
 * @param bool         $isPostSource tells whether $values are directly from
 *                                   POST request
 *
 * @return bool|array
 */
function PMA_config_validate($validator_id, &$values, $isPostSource)
{
    // find validators
    $validator_id = (array) $validator_id;
    $validators = PMA_config_get_validators();
    $vids = array();
    $cf = ConfigFile::getInstance();
    foreach ($validator_id as &$vid) {
        $vid = $cf->getCanonicalPath($vid);
        if (isset($validators[$vid])) {
            $vids[] = $vid;
        }
    }
    if (empty($vids)) {
        return false;
    }
    // create argument list with canonical paths and remember path mapping
    $arguments = array();
    $key_map = array();
    foreach ($values as $k => $v) {
        $k2 = $isPostSource ? str_replace('-', '/', $k) : $k;
        $k2 = strpos($k2, '/') ? $cf->getCanonicalPath($k2) : $k2;
        $key_map[$k2] = $k;
        $arguments[$k2] = $v;
    }
    // validate
    $result = array();
    foreach ($vids as $vid) {
        // call appropriate validation functions
        foreach ((array) $validators[$vid] as $validator) {
            $vdef = (array) $validator;
            $vname = array_shift($vdef);
            $args = array_merge(array($vid, &$arguments), $vdef);
            $r = call_user_func_array($vname, $args);
            // merge results
            if (is_array($r)) {
                foreach ($r as $key => $error_list) {
                    // skip empty values if $isPostSource is false
                    if (!$isPostSource && empty($error_list)) {
                        continue;
                    }
                    if (!isset($result[$key])) {
                        $result[$key] = array();
                    }
                    $result[$key] = array_merge($result[$key], (array) $error_list);
                }
            }
        }
    }
    // restore original paths
    $new_result = array();
    foreach ($result as $k => $v) {
        $k2 = isset($key_map[$k]) ? $key_map[$k] : $k;
        $new_result[$k2] = $v;
    }
    return empty($new_result) ? true : $new_result;
}
Пример #19
0
 /**
  * Fills out {@link userprefs_keys} and {@link userprefs_disallow}
  *
  * @return void
  */
 private function _loadUserprefsInfo()
 {
     if ($this->_userprefsKeys === null) {
         $this->_userprefsKeys = array_flip(PMA_readUserprefsFieldNames());
         // read real config for user preferences display
         $userprefs_disallow = defined('PMA_SETUP') ? $this->_configFile->get('UserprefsDisallow', array()) : $GLOBALS['cfg']['UserprefsDisallow'];
         $this->_userprefsDisallow = array_flip($userprefs_disallow);
     }
 }
Пример #20
0
 function close()
 {
     self::$tabspaces = 1;
     self::write(['', '# Including the functions']);
     self::write('require_once( __DIR__ . \'/functions.php\' );');
     self::write(['', '', '# Initializing nuQuery']);
     self::write('require_once( __DIR__ . \'/nuquery.php\' );');
     self::write('$nuquery = new nuQuery();');
     self::write(['', '', '/* ----- This file was auto-generated on ' . date('Y-m-d H:i:s') . ' ------ */', '']);
     self::$tabspaces = 0;
     self::write('?>', false);
     fclose(self::$handle);
 }
Пример #21
0
/**
 * Returns config file contents depending on GET type value:
 * o session - uses ConfigFile::getConfigFile()
 * o post - uses POST textconfig value
 *
 * @return string
 */
function get_config()
{
    $type = PMA_ifSetOr($_GET['type'], 'session');
    if ($type == 'session') {
        $config = ConfigFile::getInstance()->getConfigFile();
    } else {
        $config = PMA_ifSetOr($_POST['textconfig'], '');
        // make sure our eol is \n
        $config = str_replace("\r\n", "\n", $config);
        if ($_SESSION['eol'] == 'win') {
            $config = str_replace("\n", "\r\n", $config);
        }
    }
    return $config;
}
Пример #22
0
/**
 * Processes forms registered in $form_display, handles error correction
 *
 * @param FormDisplay $form_display
 */
function process_formset(FormDisplay $form_display)
{
    if (filter_input(INPUT_GET, 'mode') == 'revert') {
        // revert erroneous fields to their default values
        $form_display->fixErrors();
        // drop post data
        header('HTTP/1.1 303 See Other');
        header('Location: index.php');
        exit;
    }
    if (!$form_display->process(false)) {
        // handle form view and failed POST
        $form_display->display(true, true);
    } else {
        // check for form errors
        if ($form_display->hasErrors()) {
            // form has errors, show warning
            $separator = PMA_get_arg_separator('html');
            $page = filter_input(INPUT_GET, 'page');
            $formset = filter_input(INPUT_GET, 'formset');
            $formset = $formset ? "{$separator}formset=$formset" : '';
            $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
            if ($id === null && $page == 'servers') {
                // we've just added a new server, get it's id
                $id = ConfigFile::getInstance()->getServerCount();
            }
            $id = $id ? "{$separator}id=$id" : '';
            ?>
            <div class="error">
                <h4><?php echo __('Warning') ?></h4>
                <?php echo __('Submitted form contains errors') ?><br />
                <a href="?page=<?php echo $page . $formset . $id . $separator ?>mode=revert"><?php echo __('Try to revert erroneous fields to their default values') ?></a>
            </div>
            <?php $form_display->displayErrors() ?>
            <a class="btn" href="index.php"><?php echo __('Ignore errors') ?></a>
            &nbsp;
            <a class="btn" href="?page=<?php echo $page . $formset . $id . $separator ?>mode=edit"><?php echo __('Show form') ?></a>
            <?php
        } else {
            // drop post data
            header('HTTP/1.1 303 See Other');
            header('Location: index.php');
            exit;
        }
    }
}
Пример #23
0
 function test_apply()
 {
     $htaccess = new ConfigFile('testhtaccess');
     $htaccess->param('RewriteBase', 'RewriteBase /xxx/yyy/');
     $resultat = $htaccess->apply($this->HtaccessDist);
     $this->assertEqual($resultat, $this->HtaccessWithBase);
     $resultat = $htaccess->apply($resultat);
     //apply twice
     $this->assertEqual($resultat, $this->HtaccessWithBase);
     $htaccess->param('RewriteRule ^x/$', 'RewriteRule ^x/$  /yyyyyyy [L]');
     $resultat = $htaccess->apply($this->HtaccessDist);
     $this->assertEqual($resultat, $this->HtaccessNewRule);
 }
Пример #24
0
  function __construct() {
    // Load main configuration file
    $config = ConfigFile::factory('kurogo', 'project', ConfigFile::OPTION_IGNORE_MODE | ConfigFile::OPTION_IGNORE_LOCAL);
    $this->addConfig($config);

    define('CONFIG_MODE', $config->getVar('CONFIG_MODE'));
    define('CONFIG_IGNORE_LOCAL', $config->getVar('CONFIG_IGNORE_LOCAL'));

    //make sure active site is set    
    if (!$site = $this->getVar('ACTIVE_SITE')) {
        die("FATAL ERROR: ACTIVE_SITE not set");
    }
    
    //make sure site_dir is set and is a valid path
    if (!($siteDir = $this->getVar('SITE_DIR')) || !($siteDir = realpath_exists($siteDir))) {
        die("FATAL ERROR: Site Directory ". $this->getVar('SITE_DIR') . " not found for site " . $site);
    }
    
    // Set up defines relative to SITE_DIR
    define('SITE_DIR',             $siteDir);
    define('SITE_KEY',             md5($siteDir));
    define('SITE_LIB_DIR',         SITE_DIR.'/lib');
    define('SITE_APP_DIR',         SITE_DIR.'/app');
    define('SITE_MODULES_DIR',     SITE_DIR.'/app/modules');
    define('DATA_DIR',             SITE_DIR.'/data');
    define('CACHE_DIR',            SITE_DIR.'/cache');
    define('LOG_DIR',              SITE_DIR.'/logs');
    define('SITE_CONFIG_DIR',      SITE_DIR.'/config');

    //load in the site config file (required);
    $config = ConfigFile::factory('site', 'site');
    $this->addConfig($config);

    // Set up theme define
    if (!$theme = $this->getVar('ACTIVE_THEME')) {
        die("FATAL ERROR: ACTIVE_THEME not set");
    }
    
    define('THEME_DIR', SITE_DIR.'/themes/'.$theme);
  }
Пример #25
0
if (!defined('PHPMYADMIN')) {
    exit;
}

/**
 * Core libraries.
 */
require_once './libraries/display_select_lang.lib.php';
require_once './libraries/config/FormDisplay.class.php';
require_once './setup/lib/index.lib.php';

// prepare unfiltered language list
$all_languages = PMA_langList();
uasort($all_languages, 'PMA_language_cmp');

$cf = ConfigFile::getInstance();
$separator = PMA_get_arg_separator('html');

// message handling
messages_begin();

//
// Check phpMyAdmin version
//
if (isset($_GET['version_check'])) {
    PMA_version_check();
}

//
// Perform various security, compatibility and consistency checks
//
  protected function initializeForPage() {
        $this->addJQuery();
        switch ($this->page)
        {
             case 'module':
                $moduleID = $this->getArg('moduleID');
                if (empty($moduleID)) {
                    $this->redirectTo('modules');
                }

                $module = WebModule::factory($moduleID);
                $moduleData = $module->getModuleData();
                $moduleSections = array();
                
                if ($section = $this->getArg('section')) {
                    
                    if ($section=='feeds' && $module->hasFeeds()) {
                        if (strlen($this->getArg('removeFeed'))>0) {
                            $index = $this->getArg('removeFeed');
                            $module->removeFeed($index);
                        }

                        if ($this->getArg('addFeed')) {
                            $feedData = $this->getArg('addFeedData');
                            if (!$module->addFeed($feedData, $error)) {
                                $this->assign('errorMessage', $error);
                            }
                        }

                        $moduleData['feeds'] = $module->loadFeedData();
                        if (!$moduleData['feeds']) {
                            $moduleData['feeds'] = array();
                        }
                        $this->assign('feedURL', $this->buildBreadcrumbURL('module', array(
                                'moduleID'=>$moduleID,
                                'section'=>$section),false
                            ));
                        $this->assign('feedFields', $module->getFeedFields());
                    } elseif (!isset($moduleData[$section])) {
                        $this->redirectTo('module', array('moduleID'=>$moduleID), false);
                    }
                }

                if ($this->getArg('submit')) {
                    $merge = $this->getArg('merge', true);
                    if ($merge) {
                        $moduleData = $this->prepareSubmitData('moduleData');
                        $moduleData = array_merge($module->getModuleDefaultData(), $moduleData);
                    } else {
                        $moduleData = $this->prepareSubmitData('moduleData');
                    }

                    if ($section) {
                        $moduleData = array($section=>$moduleData[$section]);
                    } else {
                        /* only include the scalar values since array values come from sections */
                        $_data = array();
                        foreach ($moduleData as $var=>$val) {
                            if (is_scalar($val)) {
                                $_data[$var] = $val;
                            }
                            $moduleData = $_data;
                        }
                    }

                    $module->saveConfig($moduleData, $section);
                    if ($section) {
                        $this->redirectTo('module', array('moduleID'=>$moduleID), false);
                    } else {
                        $this->redirectTo('modules', false, false);
                    }
                } 
                
                $this->setPageTitle(sprintf("Administering %s module", $moduleData['title']));
                $this->setBreadcrumbTitle($moduleData['title']);
                $this->setBreadcrumbLongTitle($moduleData['title']);
                
                
                $formListItems = array();

                if ($section) {
                    $moduleData = $moduleData[$section];
                } else {
                   $formListItems[] = $this->getModuleItemForKey('id', $moduleID);
                }
                
                foreach ($moduleData as $key=>$value) {
                    if (is_scalar($value)) {
                        $formListItems[] = $module->getModuleItemForKey($key, $value);
                    } else {
                        $moduleSections[$key] = $module->getSectionTitleForKey($key);
                    }
                }
                
                if (!$section) {
                    foreach ($moduleSections as $key=>$title) {
                        $formListItems[] = array(
                            'type'=>'url',
                            'name'=>$title,
                            'value'=>$this->buildBreadcrumbURL('module', array(
                                'moduleID'=>$moduleID,
                                'section'=>$key)
                            )
                        );
                    }

                    if ($module->hasFeeds()) {
                        $formListItems[] = array(
                            'type'=>'url',
                            'name'=>'Data Configuration',
                            'value'=>$this->buildBreadcrumbURL('module', array(
                                'moduleID'=>$moduleID,
                                'section'=>'feeds')
                            )
                        );
                    }

                    $formListItems[] = array(
                        'type'=>'url',
                        'name'=>'Page Data',
                        'value'=>$this->buildBreadcrumbURL('pageData', array(
                            'moduleID'=>$moduleID
                            )
                        )
                    );
                } 
                
                $_module = array(
                    'id'=>$moduleID
                );

                $this->assign('formListItems', $formListItems);
                $this->assign('module'       , $_module);
                $this->assign('section'      , $section);

                if ($section) {
                    $module->prepareAdminForSection($section, $this);
                }
                break;

            case 'modules':
                $allModules = $this->getAllModules();
                $moduleList = array();

                foreach ($allModules as $moduleID=>$moduleData) {
                    try {
                        $moduleList[] = array(
                            'img'=>"/modules/home/images/{$moduleID}.png",
                            'title'=>$moduleData->getModuleName(),
                            'url'=>$this->buildBreadcrumbURL('module', array(
                                'moduleID'=>$moduleID
                                )
                            )
                        );
                        $this->assign('moduleList', $moduleList);
                        
                    } catch(Exception $e) {}
                }
            
                break;
            case 'pageData':
                $moduleID = $this->getArg('moduleID');
                if (empty($moduleID)) {
                    $this->redirectTo('modules');
                }

                $module = WebModule::factory($moduleID);
                $pageData = $module->getPageData();

                if ($this->getArg('submit')) {
                    $pageData = $this->prepareSubmitData('pageData');
                    $module->saveConfig(array('nav'=>$pageData), 'nav');
                } 
                
                $this->setPageTitle(sprintf("Administering Page Data for %s", $module->getModuleName()));
                $pages = array();

                foreach ($pageData as $page=>$_pageData) {
                    $item = array();
                    $item[] = array(
                        'label'=>'Page',
                        'type'=>'label',
                        'value'=>$page
                    );
                    $item[] = array(
                        'label'=>'Title',
                        'type'=>'text',
                        'name'=>"pageData[$page][pageTitle]",
                        'typename'=>"pageData][$page][pageTitle",
                        'value'=>isset($_pageData['pageTitle']) ? $_pageData['pageTitle'] : ''
                    );
                    $item[] = array(
                        'label'=>'Breadcrumb Title',
                        'type'=>'text',
                        'name'=>"pageData[$page][breadcrumbTitle]",
                        'typename'=>"pageData][$page][breadcrumbTitle",
                        'value'=>isset($_pageData['breadcrumbTitle']) ? $_pageData['breadcrumbTitle'] : ''
                    );
                    $item[] = array(
                        'label'=>'Breadcrumb Long Title',
                        'type'=>'text',
                        'name'=>"pageData[$page][breadcrumbLongTitle]",
                        'typename'=>"pageData][$page][breadcrumbLongTitle",
                        'value'=>isset($_pageData['breadcrumbLongTitle']) ? $_pageData['breadcrumbLongTitle'] : ''
                    );
                    $pages[$page] = $item;
                }
                
                $_module = array(
                    'id'=>$moduleID
                );

                $this->assign('pages'        , $pages);
                $this->assign('module'       , $_module);

                break;
            case 'strings':
                $configFile = ConfigFile::factory('strings', 'site', ConfigFile::OPTION_CREATE_WITH_DEFAULT | ConfigFile::OPTION_IGNORE_LOCAL);

                if ($this->getArg('submit')) {
                    $strings = $this->prepareSubmitData('strings');
                    $configFile->addSectionVars($strings, false);
                    $configFile->saveFile();
                    $this->redirectTo('index', false, false);
                } 

                $strings = $configFile->getSectionVars(true);
                $formListItems = array();
                foreach ($strings as $key=>$value) {
                    if (is_scalar($value)) {
                        $formListItems[] = array(
                        'label'=>implode(" ", array_map("ucfirst", explode("_", strtolower($key)))),
                        'name'=>"strings[$key]",
                        'typename'=>"strings][$key",
                        'value'=>$value,
                        'type'=>'text'
                        );
                    } else {
                        $formListItems[] = array(
                        'label'=>implode(" ", array_map("ucfirst", explode("_", strtolower($key)))),
                        'name'=>"strings[$key]",
                        'typename'=>"strings][$key",
                        'value'=>implode("\n\n", $value),
                        'type'=>'paragraph'
                        );
                    }
                }

                $this->assign('localFile'    , $configFile->localFile());
                $this->assign('strings', $strings);
                $this->assign('formListItems', $formListItems);
                break;

            case 'site':
                $configFile = ConfigFile::factory('config', 'site', ConfigFile::OPTION_IGNORE_LOCAL);
                $siteVars = $configFile->getSectionVars();

                if ($section = $this->getArg('section')) {
                
                    if (!isset($siteVars[$section])) {
                        $section = null;
                    }
                }
                
                $formListItems = array();

                if ($section) {

                    if ($this->getArg('submit')) {
                        $sectionVars = $this->prepareSubmitData('siteData');
                        $configFile->addSectionVars($sectionVars, true);
                        $configFile->saveFile();
                        $this->redirectTo('site', false, false);
                    }

                    $formListItems = array();
                    $sectionVars = $configFile->getSection($section);

                    foreach ($sectionVars as $key=>$value) {
                        $formListItems[] = $this->getSiteItemForKey($section, $key, $value);
                    }

                } else {
                    foreach ($siteVars as $sectionName=>$sectionVars){
                        $formListItems[] = array(
                            'type'=>'url',
                            'name'=>$this->getSectionTitleForKey($sectionName),
                            'value'=>$this->buildBreadcrumbURL('site', array(
                                'section'=>$sectionName
                                )
                            )
                        );
                    }
                }
                                            
                $this->assign('localFile'    , $configFile->localFile());
                $this->assign('section'      , $section);
                $this->assign('formListItems', $formListItems);
                
                break;

            case 'sessions';
                $session = $this->getSession();
                
                if ($this->getArg('deleteSession')) {
                    $sessionID = key($this->getArg('deleteSession'));
                    // you can't delete your own session
                    if ($sessionID != $session->getSessionID()) {
                        $session->deleteSession($sessionID);
                    }
                }
                
                $activeSessions = $session->getActiveSessions();
                $sessions = array();

                foreach ($activeSessions as $sessionID=>$sessionData) {
                    $sessionItem = array(
                        'label'=>$sessionData['userID'] . " (" . $sessionData['auth'] . ")",
                        'subtitle'=>'Last Access: ' . date('m/d/y H:i:s', $sessionData['ping'])
                    );
                    
                    // you can't delete your own session
                    if ($sessionID != $session->getSessionID()) {
                        $sessionItem['name'] ='deleteSession[' . $sessionID . ']';
                        $sessionItem['type'] ='submit';
                        $sessionItem['confirm'] = true;
                        $sessionItem['value'] = 'Delete';
                    }

                    $sessions[] = $sessionItem;
                }
                
                $this->assign('sessions', $sessions);
                break;

            case 'index':
                $adminList = array();
                $adminList[] = array(
                    'title'=>'Modules',
                    'url'=>$this->buildBreadcrumbURL('modules', array()),
                    'subtitle'=>'Manage module configuration and data'
                );
                $adminList[] = array(
                    'title'=>'Site Configuration',
                    'url'=>$this->buildBreadcrumbURL('site', array()),
                    'subtitle'=>'Manage site-wide configuration'
                );
                $adminList[] = array(
                    'title'=>'String Configuration',
                    'url'=>$this->buildBreadcrumbURL('strings', array()),
                    'subtitle'=>'Update textual strings used throughout the site'
                );
                if ($this->getSiteVar('AUTHENTICATION_ENABLED')) {
                    $adminList[] = array(
                        'title'=>'User Sessions',
                        'url'=>$this->buildBreadcrumbURL('sessions', array()),
                        'subtitle'=>'View and manage active user sessions'
                    );
                }
                $this->assign('adminList', $adminList);
                break;
  
        }  
        
  }
 /**
  * Returns the authentication config file
  * @return ConfigFile
 */
 private static function getAuthorityConfigFile()
 {
     return ConfigFile::factory('authentication', 'site');
 }
    }
    $form_display->registerForm($form_name, $form, 1);
}
if (isset($_POST['revert'])) {
    // revert erroneous fields to their default values
    $form_display->fixErrors();
    // redirect
    $url_params = array('form' => $form_param);
    PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'prefs_forms.php' . PMA_generate_common_url($url_params, '&'));
    exit;
}
$error = null;
if ($form_display->process(false) && !$form_display->hasErrors()) {
    // save settings
    $old_settings = PMA_load_userprefs();
    $result = PMA_save_userprefs(ConfigFile::getInstance()->getConfigArray());
    if ($result === true) {
        // reload config
        $GLOBALS['PMA_Config']->loadUserPreferences();
        $hash = ltrim(filter_input(INPUT_POST, 'tab_hash'), '#');
        PMA_userprefs_redirect($forms, $old_settings, 'prefs_forms.php', array('form' => $form_param), $hash);
        exit;
    } else {
        $error = $result;
    }
}
// display forms
$GLOBALS['js_include'][] = 'config.js';
require './libraries/header.inc.php';
require './libraries/user_preferences.inc.php';
if ($error) {
Пример #29
0
 /**
  * Validates and saves form data to session
  *
  * @param  array|string  $forms               array of form names
  * @param  bool          $allow_partial_save  allows for partial form saving on failed validation
  * @return boolean  true on success (no errors and all saved)
  */
 public function save($forms, $allow_partial_save = true)
 {
     $result = true;
     $cf = ConfigFile::getInstance();
     $forms = (array) $forms;
     $values = array();
     $to_save = array();
     $this->errors = array();
     foreach ($forms as $form) {
         /* @var $form Form */
         if (isset($this->forms[$form])) {
             $form = $this->forms[$form];
         } else {
             continue;
         }
         // get current server id
         $change_index = $form->index === 0 ? $cf->getServerCount() + 1 : false;
         // grab POST values
         foreach ($form->fields as $field => $system_path) {
             $work_path = array_search($system_path, $this->system_paths);
             $key = $this->translated_paths[$work_path];
             // ensure the value is set
             if (!isset($_POST[$key])) {
                 // checkboxes aren't set by browsers if they're off
                 if ($form->getOptionType($field) == 'boolean') {
                     $_POST[$key] = false;
                 } else {
                     $this->errors[$form->name][] = PMA_lang('error_missing_field_data', '<i>' . PMA_lang_name($system_path) . '</i>');
                     $result = false;
                     continue;
                 }
             }
             // cast variables to correct type
             $type = $form->getOptionType($field);
             switch ($type) {
                 case 'double':
                     settype($_POST[$key], 'float');
                     break;
                 case 'boolean':
                 case 'integer':
                     if ($_POST[$key] !== '') {
                         settype($_POST[$key], $type);
                     }
                     break;
                 case 'select':
                     if (!$this->_validateSelect($_POST[$key], $form->getOptionValueList($system_path))) {
                         $this->errors[$work_path][] = $GLOBALS["strstrSetuperror_incorrect_value"];
                         $result = false;
                         continue;
                     }
                     break;
                 case 'string':
                     $_POST[$key] = trim($_POST[$key]);
                     break;
                 case 'array':
                     // eliminate empty values and ensure we have an array
                     $post_values = explode("\n", $_POST[$key]);
                     $_POST[$key] = array();
                     foreach ($post_values as $v) {
                         $v = trim($v);
                         if ($v !== '') {
                             $_POST[$key][] = $v;
                         }
                     }
                     break;
             }
             // now we have value with proper type
             $values[$system_path] = $_POST[$key];
             if ($change_index !== false) {
                 $work_path = str_replace("Servers/{$form->index}/", "Servers/{$change_index}/", $work_path);
             }
             $to_save[$work_path] = $system_path;
         }
     }
     // save forms
     if ($allow_partial_save || empty($this->errors)) {
         foreach ($to_save as $work_path => $path) {
             // TrustedProxies requires changes before saving
             if ($path == 'TrustedProxies') {
                 $proxies = array();
                 $i = 0;
                 foreach ($values[$path] as $value) {
                     $matches = array();
                     if (preg_match("/^(.+):(?:[ ]?)(\\w+)\$/", $value, $matches)) {
                         // correct 'IP: HTTP header' pair
                         $ip = trim($matches[1]);
                         $proxies[$ip] = trim($matches[2]);
                     } else {
                         // save also incorrect values
                         $proxies["-{$i}"] = $value;
                         $i++;
                     }
                 }
                 $values[$path] = $proxies;
             }
             $cf->set($work_path, $values[$path], $path);
         }
     }
     // don't look for non-critical errors
     $this->_validate();
     return $result;
 }
Пример #30
0
 public static function getSiteAccessControlLists()
 {
     $config = ConfigFile::factory('acls', 'site', ConfigFile::OPTION_CREATE_EMPTY);
     $acls = array();
     foreach ($config->getSectionVars() as $aclArray) {
         if ($acl = AccessControlList::createFromArray($aclArray)) {
             $acls[] = $acl;
         }
     }
     return $acls;
 }