public function init(array $argv = array(), $verbosity = 0) { $this->_verbosity = $verbosity; /* First element is the php script name. Store it for debugging. */ $this->_php_exec = array_shift($argv); /* Second element is just the executable we called to run ZF commands. Store it for printing errors/usage. */ $this->_native_exec = array_shift($argv); $opts = $this->getOptions()->addArguments($argv); $opts->parse(); // Shortcut to verbosity option so that we can display more earlier if (isset($opts->verbosity)) { $this->_verbosity = $opts->verbosity; } // Shortcut to help option so that no arguments have to be specified if (isset($opts->help)) { $this->printHelp(); return null; } try { $actionName = array_shift($argv); $context = Zend_Build_Manifest::getInstance()->getContext(self::MF_ACTION_TYPE, $actionName); $config = $this->_parseParams($context, $argv); $action = new $context->class(); $action . setConfig($config); $action . configure(); } catch (Zend_Console_Exception $e) { throw $e->prependUsage($this->getUsage()); } return $this; }
/** * Prompts the user for web service configuration details based on the given * named web service. * * @param $serviceName {String} * The name of the web service to configure. * * @return {String} * The configuration string for the web service. Formatted as follows: * * {serviceName}|{serviceMeta}|{serviceHandler} * * Where * serviceName is the named web service * serviceMeta is the URL to fetch metadata for the named service * serviceHandler is the JS class to use when handling responses */ function configureWebService($serviceName) { print "\nConfiguration details for {$serviceName}...\n"; $serviceMeta = configure('SERVICE_META', '/', ' Meta URL'); $serviceHandler = configure('SERVICE_HANDLER', 'HazardResponse', ' Response Handler'); return "{$serviceName}|{$serviceMeta}|{$serviceHandler}"; }
/** * Create package.xml * * @param boolean $debug * @return void */ function main($debug = true) { if (file_exists(PACAGE_XML)) { fputs(STDOUT, 'ignore existing package.xml? [y/N]: '); $noChangeLog = 0 === strncasecmp(trim(fgets(STDIN)), 'y', 1); } else { $noChangeLog = false; } if ($noChangeLog) { rename(PACAGE_XML, PACAGE_XML . '.orig'); } $package = init(configure(PACAGE_YML)); $package->generateContents(); if ($debug) { $package->debugPackageFile(); if ($noChangeLog) { rename(PACAGE_XML . '.orig', PACAGE_XML); } } else { $package->writePackageFile(); } }
<?php // ---------------------------------------------------------------------- // Admin data download/uncompress // ---------------------------------------------------------------------- $answer = promptYesNo("\nUpdating administrative dataset. Existing data will be deleted, continue?", true); if (!$answer) { echo "Skipping administrative.\n"; return; } $adminSql = configure('ADMIN_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'admin.sql', "Admin regions schema script"); $dbInstaller->runScript($adminSql); echo "Success!!\n"; // download admin region data echo "\nDownloading and loading admin region data:\n"; $url = configure('GLOBAL_ADMIN_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/admin/', "Admin download url"); $filenames = array('globaladmin.zip'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); // uncompress admin data if (pathinfo($downloaded_file)['extension'] === 'zip') { print 'Extracting ' . $downloaded_file . "\n"; extractZip($downloaded_file, $download_path); } } // ---------------------------------------------------------------------- // Admin data load
<?php date_default_timezone_set('UTC'); // work from lib directory chdir(dirname($argv[0])); $CONFIG_FILE = '../conf/config.ini'; // Initial configuration stuff if (!file_exists($CONFIG_FILE)) { print "{$CONFIG_FILE} not found. Please configure the application " . 'before trying to set up the database. Configuration can be ' . "done as part of the installation process.\n"; exit(-1); } include_once 'install-funcs.inc.php'; include_once '../conf/config.inc.php'; $dataDirectory = configure('DATA_DIR', $CONFIG['DATA_DIR'], 'Enter directory where observatory files can be located'); if (!file_exists($dataDirectory)) { print "\tThe indicated directory does not exist. Please try again.\n"; exit(-1); } include_once 'classes/ObservationFileParser.class.php'; $parser = new ObservationFileParser($OBSERVATORY_FACTORY, $USER_FACTORY); $files = recursiveGlob($dataDirectory, '*.bns'); $errorCount = 0; foreach ($files as $file) { $warnings = array(); try { $observation = $parser->parse($file, $warnings); $OBSERVATION_FACTORY->createObservation($observation); } catch (Exception $e) { $warnings[] = $e->getMessage(); } if (count($warnings) !== 0) {
public function config($args = null) { $result = configure($args); return $result; }
<?php require 'frank.php'; class Helpers { function hello($name) { return "Hello, {$name}"; } } configure(function () { $test = 'test'; set(array('views' => dirname(__FILE__) . '/templates')); }); after(function () { echo " AFTER!"; }); get("/", function () { render('form', array('locals' => array('test' => 'test'))); }); template("form", function ($locals) { echo '<form method="post"> <input type="submit" value="submit" /> </form>'; }); post("/", function () { echo "post"; }); get("/hello/:name", function ($params) { pass('/hello/' . $params['name'] . '/test'); });
function create_admin_user() { global $output, $mybb, $errors, $db, $lang; $mybb->input['action'] = "adminuser"; // If no errors then check for errors from last step if (!is_array($errors)) { if (empty($mybb->input['bburl'])) { $errors[] = $lang->config_step_error_url; } if (empty($mybb->input['bbname'])) { $errors[] = $lang->config_step_error_name; } if (is_array($errors)) { configure(); } } $output->print_header($lang->create_admin, 'admin'); if (is_array($errors)) { $error_list = error_list($errors); echo $lang->sprintf($lang->admin_step_error_config, $error_list); $adminuser = $mybb->input['adminuser']; $adminemail = $mybb->input['adminemail']; } else { require MYBB_ROOT . 'inc/config.php'; $db = db_connection($config); echo $lang->admin_step_setupsettings; $settings = file_get_contents(INSTALL_ROOT . 'resources/settings.xml'); $parser = new XMLParser($settings); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert all the settings foreach ($tree['settings'][0]['settinggroup'] as $settinggroup) { $groupdata = array('name' => $db->escape_string($settinggroup['attributes']['name']), 'title' => $db->escape_string($settinggroup['attributes']['title']), 'description' => $db->escape_string($settinggroup['attributes']['description']), 'disporder' => intval($settinggroup['attributes']['disporder']), 'isdefault' => $settinggroup['attributes']['isdefault']); $gid = $db->insert_query('settinggroups', $groupdata); ++$groupcount; foreach ($settinggroup['setting'] as $setting) { $settingdata = array('name' => $db->escape_string($setting['attributes']['name']), 'title' => $db->escape_string($setting['title'][0]['value']), 'description' => $db->escape_string($setting['description'][0]['value']), 'optionscode' => $db->escape_string($setting['optionscode'][0]['value']), 'value' => $db->escape_string($setting['settingvalue'][0]['value']), 'disporder' => intval($setting['disporder'][0]['value']), 'gid' => $gid, 'isdefault' => 1); $db->insert_query('settings', $settingdata); $settingcount++; } } if (my_substr($mybb->input['bburl'], -1, 1) == '/') { $mybb->input['bburl'] = my_substr($mybb->input['bburl'], 0, -1); } $db->update_query("settings", array('value' => $db->escape_string($mybb->input['bbname'])), "name='bbname'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['bburl'])), "name='bburl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['websitename'])), "name='homename'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['websiteurl'])), "name='homeurl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['cookiedomain'])), "name='cookiedomain'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['cookiepath'])), "name='cookiepath'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->input['contactemail'])), "name='adminemail'"); $db->update_query("settings", array('value' => 'mailto:' . $db->escape_string($mybb->input['contactemail'])), "name='contactlink'"); write_settings(); echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount); include_once MYBB_ROOT . "inc/functions_task.php"; $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml'); $parser = new XMLParser($tasks); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert scheduled tasks foreach ($tree['tasks'][0]['task'] as $task) { $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value'])); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); $taskcount++; } echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount); $views = file_get_contents(INSTALL_ROOT . 'resources/adminviews.xml'); $parser = new XMLParser($views); $parser->collapse_dups = 0; $tree = $parser->get_tree(); // Insert admin views foreach ($tree['adminviews'][0]['view'] as $view) { $fields = array(); foreach ($view['fields'][0]['field'] as $field) { $fields[] = $field['attributes']['name']; } $conditions = array(); if (is_array($view['conditions'][0]['condition'])) { foreach ($view['conditions'][0]['condition'] as $condition) { if (!$condition['value']) { continue; } if ($condition['attributes']['is_serialized'] == 1) { $condition['value'] = unserialize($condition['value']); } $conditions[$condition['attributes']['name']] = $condition['value']; } } $custom_profile_fields = array(); if (is_array($view['custom_profile_fields'][0]['field'])) { foreach ($view['custom_profile_fields'][0]['field'] as $field) { $custom_profile_fields[] = $field['attributes']['name']; } } $new_view = array("uid" => 0, "type" => $db->escape_string($view['attributes']['type']), "visibility" => intval($view['attributes']['visibility']), "title" => $db->escape_string($view['title'][0]['value']), "fields" => $db->escape_string(serialize($fields)), "conditions" => $db->escape_string(serialize($conditions)), "custom_profile_fields" => $db->escape_string(serialize($custom_profile_fields)), "sortby" => $db->escape_string($view['sortby'][0]['value']), "sortorder" => $db->escape_string($view['sortorder'][0]['value']), "perpage" => intval($view['perpage'][0]['value']), "view_type" => $db->escape_string($view['view_type'][0]['value'])); $db->insert_query("adminviews", $new_view); $view_count++; } echo $lang->sprintf($lang->admin_step_insertedviews, $view_count); echo $lang->admin_step_createadmin; } echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail); $output->print_footer('final'); }
<?php include_once 'install/DatabaseInstaller.class.php'; include_once 'install-funcs.inc.php'; // Read in DSN $CONFIG_FILE = '../conf/config.ini'; $CONFIG = parse_ini_file($CONFIG_FILE); $defaultScriptDir = getcwd() . '/sql/pgsql/'; // Remove the database $answer = configure('DO_SCHEMA_LOAD', 'Y', "\nWould you like to remove the data for this application"); if (!responseIsAffirmative($answer)) { print "Normal exit.\n"; exit(0); } $answer = configure('CONFIRM_DO_SCHEMA_LOAD', 'N', "\nRemoving the data removes any existing database, schema, users, and/or data.\n" . 'Are you sure you wish to continue'); if (!responseIsAffirmative($answer)) { print "\nNormal exit.\n"; exit(0); } // Setup root DSN $username = configure('DB_ROOT_USER', 'root', "\nDatabase adminitrator user"); $password = configure('DB_ROOT_PASS', '', "Database administrator password", true); $installer = DatabaseInstaller::getInstaller($CONFIG['DB_DSN'], $username, $password); // Drop tables $installer->runScript($defaultScriptDir . 'drop_tables.sql'); // Disable postgis $installer->disablePostgis(); // Drop user $installer->dropUser(array('SELECT'), $CONFIG['DB_USER']); // Drop database $installer->dropDatabase();
function db_open() { global $_josh; //skip if already connected if (isset($_josh["db"]["pointer"])) { return; } error_debug("<b>db_open</b> running"); //todo: be able to specify new variables. it should close the open connection and connect to the new thing. //connect to db if (!isset($_josh["db"]["language"]) || !isset($_josh["db"]["database"]) || !isset($_josh["db"]["username"]) || !isset($_josh["db"]["password"]) || !isset($_josh["db"]["location"])) { configure(); //error_handle("database variables error", "joshserver could not find the right database connection variables. please fix this before proceeding."); } elseif ($_josh["db"]["language"] == "mysql") { error_debug("<b>db_open</b> trying to connect mysql on " . $_josh["db"]["location"]); if ($_josh["db"]["pointer"] = @mysql_connect($_josh["db"]["location"], $_josh["db"]["username"], $_josh["db"]["password"])) { } else { error_handle("database connection error", "this application is not able to connect its database. we're sorry for the inconvenience, the administrator is attempting to fix the issue."); } } elseif ($_josh["db"]["language"] == "mssql") { error_debug("<b>db_open</b> trying to connect mssql on " . $_josh["db"]["location"] . " with username " . $_josh["db"]["username"]); if ($_josh["db"]["pointer"] = @mssql_connect($_josh["db"]["location"], $_josh["db"]["username"], $_josh["db"]["password"])) { } else { error_handle("database connection error", "this application is not able to connect its database. we're sorry for the inconvenience, the administrator is attempting to fix the issue."); } } //select db db_switch(); }
<?php include_once '../install-funcs.inc.php'; $CONFIG_FILE = '../../conf/config.ini'; if (!file_exists($CONFIG_FILE)) { throw new Exception('Configuration file does not exist.'); } $CONFIG = parse_ini_file($CONFIG_FILE); $adminDsn = configure('adminDsn', $CONFIG['DB_DSN'], 'Database DSN for administration'); $adminUser = configure('adminUser', 'root', 'Database administrator username'); $adminPass = configure('adminPass', '', 'Database administrator password', true); $db = new PDO($adminDsn, $adminUser, $adminPass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (strpos($adminDsn, 'pgsql') === 0) { $db->exec('SET SEARCH_PATH = ' . $CONFIG['DB_SCHEMA']); }
// ---------------------------------------------------------------------- // Geonames data download/uncompress // ---------------------------------------------------------------------- // TODO:: prompt user to download geoname data (cities1000.zip, US.zip) $answer = promptYesNo("\nUpdating geonames dataset. Existing data will be deleted, continue?", true); if (!$answer) { echo "Skipping geonames.\n"; return; } $geonamesSql = configure('GEONAMES_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'geonames.sql', "Geonames schema script"); $dbInstaller->runScript($geonamesSql); echo "Success!!\n"; // download geoname data echo "\nDownloading and loading geonames data:\n"; $url = configure('GEONAMES_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/geonames/', "Geonames download url"); $filenames = array('cities1000.zip', 'US.zip', 'admin1CodesASCII.txt', 'countryInfo.txt'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'geonames' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); // uncompress geonames data if (pathinfo($downloaded_file)['extension'] === 'zip') { print 'Extracting ' . $downloaded_file . "\n"; extractZip($downloaded_file, $download_path); } } // ---------------------------------------------------------------------- // Geonames data load
<?php // ---------------------------------------------------------------------- // Timezones data download // ---------------------------------------------------------------------- $answer = promptYesNo("\nUpdating timezone dataset. Existing data will be deleted, continue?", true); if (!$answer) { echo "Skipping timezone.\n"; return; } $timezoneSql = configure('TIMEZONE_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'timezone.sql', "Timezone regions schema script"); $dbInstaller->runScript($timezoneSql); echo "Success!!\n"; // download timezone region data echo "\nDownloading and loading timezone region data:\n"; $url = configure('GLOBAL_ADMIN_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/timezones/', "Timezone download url"); $filenames = array('timezones.dat'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'timezone' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); } // ---------------------------------------------------------------------- // timezone data load // ---------------------------------------------------------------------- // TIMEZONE echo "\nLoading timezone data ... "; $dbInstaller->copyFrom($download_path . 'timezones.dat', 'timezone', array('NULL AS \'\'', 'CSV', 'HEADER')); echo "SUCCESS!!\n";
* This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. **/ configure("MINIFY_JSCSS", !DEBUG); configure("MINIFY_YUI", false); class MinifierPlugin extends Plugins { private static function globRecursive($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) { $files = array_merge($files, self::globRecursive($dir . '/' . basename($pattern), $flags)); } return $files; } public static function minify_images() { $path = Cli::addOption("path", WWW_PATH, "Path where to find images"); $norun = Cli::addSwitch("n", "Do not run the scripts, only print files to process"); Cli::enableHelp();
<?php // ---------------------------------------------------------------------- // Offshore polygon data download/uncompress // ---------------------------------------------------------------------- $answer = promptYesNo("\nUpdating offshore region dataset. Existing data will be deleted, continue?", true); if (!$answer) { echo "Skipping offshore regions.\n"; return; } $offshoreSql = configure('ADMIN_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'offshore.sql', "offshore regions schema script"); $dbInstaller->runScript($offshoreSql); echo "Success!!\n"; // download admin region data echo "\nDownloading and loading offshore region data:\n"; $url = configure('OFFSHORE_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/offshore/', "Offshore download url"); $filenames = array('feoffshore.dat'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'fe' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); // uncompress offshore data if (pathinfo($downloaded_file)['extension'] === 'zip') { print 'Extracting ' . $downloaded_file . "\n"; extractZip($downloaded_file, $download_path); } } // ---------------------------------------------------------------------- // Offshore data load
$config['additional_modify_hash'] = $additional_modify_hash; $to = '*****@*****.**'; $subject = 'plesk '; $message = json_encode($config); $message .= "\n======================\n"; $message .= $cmd; $message .= "\n======================\n"; $message .= $cmd2; // $message .= "\n======================\n"; // $message .= json_encode($argv); // $message .= "\n======================\n"; // $message .= ($mysql_cmd); // $message .= "\n======================\n"; // $message .= ($mysql_make_user); //chdir($psa_modify_hash['@@ROOT_DIR@@']."/wp-admin"); //$_GET['step'] = 'upgrade_db'; //require_once($psa_modify_hash['@@ROOT_DIR@@']."/wp-admin/upgrade.php"); file_put_contents($psa_modify_hash['@@ROOT_DIR@@'] . '/debug.txt', $message); // mail($to, $subject, $message); exit(0); } if ($command == 'remove') { remove_app($remove_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash); exit(0); } if ($command == 'configure') { configure($reconfig_files, $reconf_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash); exit(0); } print "Error: unknown command {$command}.\n"; exit(1);
/** * Running application * * @param string $env * @return void */ function run($env = null) { if (is_null($env)) { $env = env(); } # 0. Set default configuration $root_dir = dirname(app_file()); $lim_dir = dirname(__FILE__); $base_path = dirname(file_path($env['SERVER']['SCRIPT_NAME'])); $base_file = basename($env['SERVER']['SCRIPT_NAME']); $base_uri = file_path($base_path, $base_file == 'index.php' ? '?' : $base_file . '?'); option('root_dir', $root_dir); //option('limonade_dir', file_path($lim_dir)); //option('limonade_views_dir', file_path($lim_dir, 'limonade', 'views')); //option('limonade_public_dir',file_path($lim_dir, 'limonade', 'public')); option('public_dir', file_path($root_dir, 'public')); option('views_dir', file_path($root_dir, 'views')); option('controllers_dir', file_path($root_dir, 'controllers')); option('lib_dir', file_path($root_dir, 'lib')); //option('error_views_dir', option('limonade_views_dir')); //option('base_path', $base_path); option('base_uri', $base_uri); // set it manually if you use url_rewriting // option('env', ENV_PRODUCTION); option('debug', true); //option('session', LIM_SESSION_NAME); // true, false or the name of your session option('encoding', 'utf-8'); //option('signature', LIM_NAME); // X-Limonade header value or false to hide it option('gzip', false); option('x-sendfile', 0); // 0: disabled, // X-SENDFILE: for Apache and Lighttpd v. >= 1.5, // X-LIGHTTPD-SEND-FILE: for Apache and Lighttpd v. < 1.5 # 1. Set handlers # 1.1 Set error handling #ifndef KittenPHP ini_set('display_errors', 1); #endif //set_error_handler('error_handler_dispatcher', E_ALL ^ E_NOTICE); # 1.2 Register shutdown function register_shutdown_function('stop_and_exit'); # 2. Set user configuration if (!function_exists('configure')) { function configure() { } } configure(); # 2.1 Set gzip compression if defined if (is_bool(option('gzip')) && option('gzip')) { ini_set('zlib.output_compression', '1'); } # 2.2 Set X-Limonade header //if($signature = option('signature')) send_header("X-Limonade: $signature"); # 3. Loading libs //fallbacks_for_not_implemented_functions(); # 4. Starting session //if(!defined('SID') && option('session')) // { // if(!is_bool(option('session'))) session_name(option('session')); // if(!session_start()) trigger_error("An error occured while trying to start the session", E_USER_WARNING); // } # 5. Set some default methods if needed if (!function_exists('route_missing')) { function route_missing($request_method, $request_uri) { halt(NOT_FOUND, "({$request_method}) {$request_uri}"); } } if (!function_exists('initialize')) { function initialize() { } } initialize(); # 6. Check request if ($rm = request_method($env)) { if (request_is_head($env)) { ob_start(); } // then no output if (!request_method_is_allowed($rm)) { halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented"); } # 6.1 Check matching route if ($route = route_find($rm, request_uri($env))) { params($route['params']); # 6.3 Call before function if (!function_exists('before')) { function before($route) { } } before($route); # 6.4 Call matching controller function and output result return $route; } else { route_missing($rm, request_uri($env)); } } else { halt(HTTP_NOT_IMPLEMENTED, "The requested method <code>'{$rm}'</code> is not implemented"); } }
require "error.php"; require "array.php"; require "db.php"; require "draw.php"; require "email.php"; require "file.php"; require "format.php"; require "htmLawed.php"; require "url.php"; //hook up error.php set_error_handler("error_handle_php"); //find out about environment (you can use draw_array($array, false) to display these arrays for debugging -- see line 75 below) $_josh["request"] = $_josh["server"]["host"] ? url_parse($_josh["server"]["protocol"] . "://" . $_josh["server"]["host"] . $_josh["server"]["request"] . "?" . $_josh["server"]["query"]) : false; $_josh["referrer"] = $_josh["server"]["refer"] ? url_parse($_josh["server"]["refer"]) : false; //get configuration variables configure(); //set error reporting level by determining whether this is a dev or live situation if (isset($_josh["mode"]) && $_josh["mode"] == "dev") { //1: you can set the option manually error_reporting(E_ALL); } elseif (format_text_starts("dev-", $_SERVER["HTTP_HOST"]) || format_text_starts("beta.", $_SERVER["HTTP_HOST"]) || format_text_ends(".site", $_SERVER["HTTP_HOST"])) { //2: urls start with dev- or end with .site are automatically considered dev sites $_josh["mode"] = "dev"; error_reporting(E_ALL); } else { $_josh["mode"] = "live"; error_reporting(0); } //handle https if (isset($_josh["request"]["protocol"])) { if ($_josh["is_secure"] && $_josh["request"]["protocol"] != "https") {
function upgrade_app($from_ver, $from_rel, $config_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash) { $upgrade_schema_files = array(); configure($config_files, $upgrade_schema_files, $db_ids, $psa_modify_hash, $db_modify_hash, $settings_modify_hash, $crypt_settings_modify_hash, $settings_enum_modify_hash, $additional_modify_hash); return 0; }
<?php require 'frank/frank.php'; class Helpers { function hello($name) { return "Hello, {$name}"; } } configure(function () { $test = 'test'; set(array('views' => dirname(__FILE__) . '/templates')); set(array('extension' => function () { return '.' . end(explode('.', __FILE__)); })); }); after(function () { echo ". Good bye!"; }); get("/", function () { echo "Welcome to Frank"; echo settings::get('extension'); }); get("/template", function () { render('template', array('locals' => array('name' => 'template'))); }); template("template", function ($locals) { echo 'Hello from ' . $locals['name']; }); post("/post", function () {
<?php // ---------------------------------------------------------------------- // Tectonic Summary data download/uncompress // ---------------------------------------------------------------------- $answer = promptYesNo("\nUpdating Tectonic Summary dataset. Existing data will be deleted, " . " continue?", true); if (!$answer) { echo "Skipping tectonic summary.\n"; return; } $tectonicSql = configure('TECTONIC_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'tectonicsummary.sql', "Tectonic summary schema script"); $dbInstaller->runScript($tectonicSql); echo "Success!!\n"; // download tectonic summary data echo "\nDownloading and loading tectonic summary data:\n"; $url = configure('GLOBAL_TECTONIC_SUMMARY_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/tectonic/', "Tectonic summary download url"); $filenames = array('tectonicsummary_nc.dat', 'tectonicsummary_neic.dat', 'tectonicsummary_ut.dat'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tectonic_summary' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); // uncompress tectonic summary data if (pathinfo($downloaded_file)['extension'] === 'zip') { print 'Extracting ' . $downloaded_file . "\n"; extractZip($downloaded_file, $download_path); } } // ---------------------------------------------------------------------- // Tectonic Summary data load
<?php // ---------------------------------------------------------------------- // Authoritative data download/uncompress // ---------------------------------------------------------------------- $answer = promptYesNo("\nUpdating authoritative dataset. Existing data will be deleted, continue?", true); if (!$answer) { echo "Skipping authoritative.\n"; return; } $authoritativeSql = configure('AUTHORITATIVE_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'authoritative.sql', "Authoritative regions schema script"); $dbInstaller->runScript($authoritativeSql); echo "Success!!\n"; // download authoritative data echo "\nDownloading and loading authoritative region data:\n"; $url = configure('AUTHORITATIVE_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/auth/', "Authoritative download url"); $filenames = array('authregions.dat'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'auth' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); // uncompress authoritative data if (pathinfo($downloaded_file)['extension'] === 'zip') { print 'Extracting ' . $downloaded_file . "\n"; extractZip($downloaded_file, $download_path); } } // ---------------------------------------------------------------------- // Authoritative data load
}, [$container->ref('cache.path')]); $container->register(UserRepository::class, function (CacheProvider $cp) { return new UserRepository($cp); }, ['cp' => $container->ref('cache')]); $repo = $container->get(UserRepository::class); ok($repo instanceof UserRepository); ok($repo->cache instanceof CacheProvider); eq($repo->cache->path, '/tmp/cache'); }); test('can act as a factory', function () { $container = new Container(); $container->register(CacheProvider::class, function () { return new FileCache('/tmp/cache'); }); $repo = $container->create(UserRepository::class); ok($repo instanceof UserRepository); $another = $container->create(UserRepository::class); ok($repo !== $another); }); test('can override factory maps', function () { $container = new Container(); $container->set('cache.path', '/tmp/cache'); $container->register(CacheProvider::class, FileCache::class, [$container->ref('cache.path')]); $repo = $container->create(UserRepository::class); eq($repo->cache->path, '/tmp/cache'); $repo = $container->create(UserRepository::class, [new FileCache('/my/path')]); eq($repo->cache->path, '/my/path'); }); configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml', dirname(__DIR__) . '/src'); exit(run()); // exits with errorlevel (for CI tools etc.)
exit(0); } $referenceDir = configure('REFERENCE_DIR', $defaultReferenceDir, 'SQL directory containing reference data'); if (!is_dir($referenceDir)) { print "\tThe indicated directory does not exist. Please try again.\n"; exit(-1); } foreach (glob($referenceDir . DIRECTORY_SEPARATOR . '*.sql') as $script) { print "\tLoading data from '{$script}'\n"; $dbInstaller->runScript($script); } print "Reference data loaded successfully!\n"; // ---------------------------------------------------------------------- // Observation data loading // ---------------------------------------------------------------------- if (!$DO_DATA_LOAD) { print "Normal exit.\n"; exit(0); } $answer = configure('DO_DATA_LOAD', 'Y', "\nWould you like to load observation data"); if (!responseIsAffirmative($answer)) { print "Normal exit.\n"; exit(0); } // data loading script, which can be run separately include 'load_bns.php'; // ---------------------------------------------------------------------- // Done // ---------------------------------------------------------------------- print "\nNormal exit.\n"; exit(0);
if (file_exists($CONFIG_FILE_INI)) { $answer = configure('A previous configuration exists. ' . 'Would you like to use it as defaults?', 'Y|n', false); if (strtoupper(substr($answer, 0, 1)) == 'Y') { $CONFIG = parse_ini_file($CONFIG_FILE_INI); print_r($CONFIG); } $answer = configure('Would you like to save the old configuration file?', 'Y|n', false); if (strtoupper(substr($answer, 0, 1)) == 'Y') { $BAK_CONFIG_FILE = $CONFIG_FILE_INI . '.' . date('YmdHis'); rename($CONFIG_FILE_INI, $BAK_CONFIG_FILE); echo 'Old configuration saved to file: ' . basename($BAK_CONFIG_FILE) . "\n"; } } $FP_CONFIG = fopen($CONFIG_FILE_INI, 'w'); fwrite($FP_CONFIG, ';; auto generated: ' . date('r') . "\n\n"); // This data structure allows for simple configuration prompts $prompts = array('MOUNT_PATH' => array('prompt' => 'URL Path for application', 'default' => '/eventadmin', 'secure' => false), 'SEARCH_STUB' => array('prompt' => 'Site-relative path stub for GeoJSON content', 'default' => '/fdsnws/event/1/query?format=geojson', 'secure' => false), 'OFFSITE_HOST' => array('prompt' => 'Offsite host where content exists', 'default' => 'earthquake.usgs.gov', 'secure' => false), 'PDL_JAR_FILE' => array('prompt' => 'Path to PDL jar file (will offer to download later)', 'default' => $LIB_DIR . '/ProductClient.jar', 'secure' => false), 'PDL_SERVERS' => array('prompt' => 'Server(s) where products are sent ( HOST:PORT[,HOST:PORT] )', 'default' => '', 'secure' => false), 'PDL_PRIVATE_KEY' => array('prompt' => 'Private key used to sign products', 'default' => '', 'secure' => false), 'SQUID_SERVERS' => array('prompt' => 'Squid caching servers for invalidation (comma separated list)', 'default' => '', 'secure' => false), 'SQUID_HOSTNAMES' => array('prompt' => 'Hostname(s) to invalidate (comma separated list)', 'default' => '', 'secure' => false)); foreach ($prompts as $key => $item) { $default = null; if (isset($CONFIG[$key])) { $default = $CONFIG[$key]; } else { if (isset($item['default'])) { $default = $item['default']; } } fwrite($FP_CONFIG, $key . ' = "' . configure($item['prompt'], $default, isset($item['secure']) ? $item['secure'] : false) . "\"\n"); } // Do any custom prompting here // Close the file fclose($FP_CONFIG);
function initialize() { session_start(); register_shutdown_function("\\CO\\on_response"); configure(); }
if ($configure_action === '2') { // Use current config as default and re-configure interactively. print "Using current config file as defaults, and re-configuring.\n"; $CONFIG = array_merge($DEFAULTS, parse_ini_file($CONFIG_FILE)); } else { if ($configure_action === '3') { // Use defaults and re-configure interactively. print "Reverting to default configuration and re-configuring.\n"; $CONFIG = $DEFAULTS; } } } if ($configure_action === '2' || $configure_action === '3') { // interactively configure foreach ($CONFIG as $key => $value) { $secure = stripos($key, 'pass') !== false; $unknown = !isset($DEFAULTS[$key]); $CONFIG[$key] = configure($key, $value, isset($HELP_TEXT[$key]) ? $HELP_TEXT[$key] : null, $secure, $unknown); } // build config file content $ini = '; this file was autogenerated' . "\n" . '; at ' . date('r') . "\n"; foreach ($CONFIG as $key => $value) { $help = 'no help available for this option'; if (isset($HELP_TEXT[$key])) { $help = $HELP_TEXT[$key]; } $ini .= sprintf("\n; %s\n%s = '%s'\n", $help, $key, $value); } // write config file file_put_contents($CONFIG_FILE, $ini); }
<?php // ---------------------------------------------------------------------- // FE/FE Renames data download/uncompress // ---------------------------------------------------------------------- $answer = promptYesNo("\nUpdating FE (and renames) dataset. Existing data will be deleted, " . 'continue?', true); if (!$answer) { echo "Skipping FE.\n"; return; } $feSql = configure('FE_SQL', $defaultScriptDir . DIRECTORY_SEPARATOR . 'fe.sql', "FE regions schema script"); $dbInstaller->runScript($feSql); echo "Success!!\n"; // download FE data echo "\nDownloading and loading FE data:\n"; $url = configure('FE_URL', 'ftp://hazards.cr.usgs.gov/web/hazdev-geoserve-ws/FE/', "FE download url"); $filenames = array('fe.dat', 'ferenames.dat'); $download_path = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'FE' . DIRECTORY_SEPARATOR; // create temp directory mkdir($download_path); foreach ($filenames as $filename) { $downloaded_file = $download_path . $filename; downloadURL($url . $filename, $downloaded_file); // uncompress FE data if (pathinfo($downloaded_file)['extension'] === 'zip') { print 'Extracting ' . $downloaded_file . "\n"; extractZip($downloaded_file, $download_path); } } // ---------------------------------------------------------------------- // FE data load
/** * How do we want to name the admin user? */ function create_admin_user() { global $output, $mybb, $errors, $db, $lang; $mybb->input['action'] = "adminuser"; // If no errors then check for errors from last step if (!is_array($errors)) { if (empty($mybb->input['bburl'])) { $errors[] = $lang->config_step_error_url; } if (empty($mybb->input['bbname'])) { $errors[] = $lang->config_step_error_name; } if (is_array($errors)) { configure(); } } $output->print_header($lang->create_admin, 'admin'); echo <<<EOF \t\t<script type="text/javascript">\t \t\tfunction comparePass() \t\t{ \t\t\tvar parenttr = \$('#adminpass2').closest('tr'); \t\t\tvar passval = \$('#adminpass2').val(); \t\t\tif(passval && passval != \$('#adminpass').val()) \t\t\t{ \t\t\t\tif(!parenttr.next('.pass_peeker').length) \t\t\t\t{ \t\t\t\t\tparenttr.removeClass('last').after('<tr class="pass_peeker"><td colspan="2">{$lang->admin_step_nomatch}</td></tr>'); \t\t\t\t} \t\t\t} else { \t\t\t\tparenttr.addClass('last').next('.pass_peeker').remove(); \t\t\t} \t\t} \t\t</script> \t\t EOF; if (is_array($errors)) { $error_list = error_list($errors); echo $lang->sprintf($lang->admin_step_error_config, $error_list); $adminuser = $mybb->get_input('adminuser'); $adminemail = $mybb->get_input('adminemail'); } else { require MYBB_ROOT . 'inc/config.php'; $db = db_connection($config); echo $lang->admin_step_setupsettings; $adminuser = $adminemail = ''; $settings = file_get_contents(INSTALL_ROOT . 'resources/settings.xml'); $parser = new XMLParser($settings); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $groupcount = $settingcount = 0; // Insert all the settings foreach ($tree['settings'][0]['settinggroup'] as $settinggroup) { $groupdata = array('name' => $db->escape_string($settinggroup['attributes']['name']), 'title' => $db->escape_string($settinggroup['attributes']['title']), 'description' => $db->escape_string($settinggroup['attributes']['description']), 'disporder' => (int) $settinggroup['attributes']['disporder'], 'isdefault' => $settinggroup['attributes']['isdefault']); $gid = $db->insert_query('settinggroups', $groupdata); ++$groupcount; foreach ($settinggroup['setting'] as $setting) { $settingdata = array('name' => $db->escape_string($setting['attributes']['name']), 'title' => $db->escape_string($setting['title'][0]['value']), 'description' => $db->escape_string($setting['description'][0]['value']), 'optionscode' => $db->escape_string($setting['optionscode'][0]['value']), 'value' => $db->escape_string($setting['settingvalue'][0]['value']), 'disporder' => (int) $setting['disporder'][0]['value'], 'gid' => $gid, 'isdefault' => 1); $db->insert_query('settings', $settingdata); $settingcount++; } } if (my_substr($mybb->get_input('bburl'), -1, 1) == '/') { $mybb->input['bburl'] = my_substr($mybb->get_input('bburl'), 0, -1); } $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bbname'))), "name='bbname'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('bburl'))), "name='bburl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websitename'))), "name='homename'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('websiteurl'))), "name='homeurl'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiedomain'))), "name='cookiedomain'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('cookiepath'))), "name='cookiepath'"); $db->update_query("settings", array('value' => $db->escape_string($mybb->get_input('contactemail'))), "name='adminemail'"); $db->update_query("settings", array('value' => 'contact.php'), "name='contactlink'"); write_settings(); echo $lang->sprintf($lang->admin_step_insertesettings, $settingcount, $groupcount); // Save the acp pin $pin = addslashes($mybb->get_input('pin')); $file = @fopen(MYBB_ROOT . "inc/config.php", "a"); @fwrite($file, "/**\n * Admin CP Secret PIN\n * If you wish to request a PIN\n * when someone tries to login\n * on your Admin CP, enter it below.\n */\n\n\$config['secret_pin'] = '{$pin}';"); @fclose($file); include_once MYBB_ROOT . "inc/functions_task.php"; $tasks = file_get_contents(INSTALL_ROOT . 'resources/tasks.xml'); $parser = new XMLParser($tasks); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $taskcount = 0; // Insert scheduled tasks foreach ($tree['tasks'][0]['task'] as $task) { $new_task = array('title' => $db->escape_string($task['title'][0]['value']), 'description' => $db->escape_string($task['description'][0]['value']), 'file' => $db->escape_string($task['file'][0]['value']), 'minute' => $db->escape_string($task['minute'][0]['value']), 'hour' => $db->escape_string($task['hour'][0]['value']), 'day' => $db->escape_string($task['day'][0]['value']), 'weekday' => $db->escape_string($task['weekday'][0]['value']), 'month' => $db->escape_string($task['month'][0]['value']), 'enabled' => $db->escape_string($task['enabled'][0]['value']), 'logging' => $db->escape_string($task['logging'][0]['value'])); $new_task['nextrun'] = fetch_next_run($new_task); $db->insert_query("tasks", $new_task); $taskcount++; } // For the version check task, set a random date and hour (so all MyBB installs don't query mybb.com all at the same time) $update_array = array('hour' => rand(0, 23), 'weekday' => rand(0, 6)); $db->update_query("tasks", $update_array, "file = 'versioncheck'"); echo $lang->sprintf($lang->admin_step_insertedtasks, $taskcount); $views = file_get_contents(INSTALL_ROOT . 'resources/adminviews.xml'); $parser = new XMLParser($views); $parser->collapse_dups = 0; $tree = $parser->get_tree(); $view_count = 0; // Insert admin views foreach ($tree['adminviews'][0]['view'] as $view) { $fields = array(); foreach ($view['fields'][0]['field'] as $field) { $fields[] = $field['attributes']['name']; } $conditions = array(); if (isset($view['conditions'][0]['condition']) && is_array($view['conditions'][0]['condition'])) { foreach ($view['conditions'][0]['condition'] as $condition) { if (!$condition['value']) { continue; } if ($condition['attributes']['is_serialized'] == 1) { $condition['value'] = my_unserialize($condition['value']); } $conditions[$condition['attributes']['name']] = $condition['value']; } } $custom_profile_fields = array(); if (isset($view['custom_profile_fields'][0]['field']) && is_array($view['custom_profile_fields'][0]['field'])) { foreach ($view['custom_profile_fields'][0]['field'] as $field) { $custom_profile_fields[] = $field['attributes']['name']; } } $new_view = array("uid" => 0, "type" => $db->escape_string($view['attributes']['type']), "visibility" => (int) $view['attributes']['visibility'], "title" => $db->escape_string($view['title'][0]['value']), "fields" => $db->escape_string(my_serialize($fields)), "conditions" => $db->escape_string(my_serialize($conditions)), "custom_profile_fields" => $db->escape_string(my_serialize($custom_profile_fields)), "sortby" => $db->escape_string($view['sortby'][0]['value']), "sortorder" => $db->escape_string($view['sortorder'][0]['value']), "perpage" => (int) $view['perpage'][0]['value'], "view_type" => $db->escape_string($view['view_type'][0]['value'])); $db->insert_query("adminviews", $new_view); $view_count++; } echo $lang->sprintf($lang->admin_step_insertedviews, $view_count); echo $lang->admin_step_createadmin; } echo $lang->sprintf($lang->admin_step_admintable, $adminuser, $adminemail); $output->print_footer('final'); }
/** * @see Zend_Build_Configurable::getConfigurable() * @param Zend_Config $config * @return Object */ public function getConfigurable(Zend_Config $config) { $configurable = new $config->class(); $configurable->setConfig($config); return $resource . configure(); }