date_default_timezone_set('Europe/London'); ob_implicit_flush(); set_time_limit(0); // signal handling declare (ticks=1); $must_exit = 0; pcntl_signal(SIGTERM, "signal_handler"); pcntl_signal(SIGINT, "signal_handler"); $argc = $_SERVER["argc"]; $argv = $_SERVER["argv"]; //$argv is an array if ($argc == 0) { error(usage()); } $args = parse_args($argc, $argv); if (isset($args['d'])) { $debug = $args['d']; } elseif (isset($args['debug'])) { $debug = $args['debug']; } else { $debug = 0; } function signal_handler($signo) { global $must_exit; switch ($signo) { case SIGTERM: $must_exit = 'SIGTERM'; break; case SIGINT:
/** * returns a BenchmarkArchiver object based on command line arguments * @return BenchmarkArchiver */ public static function &getArchiver() { $archiver = NULL; $options = parse_args(array('store:', 'store_container:', 'store_endpoint:', 'store_insecure', 'store_key:', 'store_prefix:', 'store_public', 'store_region:', 'store_secret:', 'v' => 'verbose'), NULL, 'save_'); merge_options_with_config($options, BenchmarkDb::BENCHMARK_DB_CONFIG_FILE); $impl = 'BenchmarkArchiver'; switch ($options['store']) { case 'azure': $impl .= 'Azure'; break; case 'google': $impl .= 'Google'; break; case 's3': $impl .= 'S3'; break; default: $err = '--store ' . $options['store'] . ' is not valid'; break; } // invalid --store argument if (isset($err)) { print_msg($err, isset($options['verbose']), __FILE__, __LINE__, TRUE); return $archiver; } require_once sprintf('%s/%s.php', dirname(__FILE__), $impl); $archiver = new $impl($options); $archiver->options = $options; if (!$archiver->validate()) { $archiver = NULL; } return $archiver; }
/** * Parse the given input into an array, and then backfill * with the contents of $defaults, if given. * @param mixed $in Accepts querystrings, arrays, and objects * @param mixed $defaults Accepts querystrings, arrays, and objects, or simply null * @return array Hashmap of input */ function parse_args($in, $defaults = null) { if (!$in && !$defaults) { return array(); } else { if (!$in) { return $defaults; } } if (is_array($in)) { $in_arr = $in; } else { if (is_object($in)) { $in_arr = get_object_vars($in); } else { parse_str($in, $in_arr); } } if (!is_array($in_arr)) { throw new Exception("Failed to parse String input into an array: " . $in); } if (!is_null($defaults)) { $defaults = parse_args($defaults); } return $defaults && count($defaults) ? array_merge($defaults, $in_arr) : $in_arr; }
/** * Constructor * * @param $path * @param $controller_root * @param $view_root * @param $use_routes * @param $force_routes */ public function __construct($path = null, $controller_root = null, $view_root = null, $use_routes = true, $force_routes = false) { $args = parse_args(); $switches = parse_switches(); $path = $path ? $path : $args[0]; array_shift($args); $controller_root = $controller_root ? $controller_root : PATH_APP . 'shell/controller/'; $view_root = $view_root ? $view_root : PATH_APP . 'shell/view/'; parent::__construct($path, $controller_root, $view_root, $use_routes, $force_routes); $this->segments = $args; }
function selectmarkedhash($name, $hash, $options = "") { $opts = array_merge(parse_args("salt=NaCl"), parse_args($options)); $result = "<select name=\"{$name}\" {$hash['extra']}>\n"; while (list($key, $val) = each($hash)) { $selected = $key == $opts[marked] ? "selected" : ""; $result = $result . "<option value=\"{$key}\" {$selected}>{$val}\n"; } $result = $result . "</select>\n"; # the array keys as a CSV $keys = implode(",", array_keys($hash)); # determine salted encrypt hash + BASE64 encode it # @ suppresses the "empty IV" error // $encrypt = @mcrypt_ecb(MCRYPT_RIJNDAEL_256,$opts[salt],$keys,MCRYPT_ENCRYPT); // $encrypt = base64_encode($encrypt); # and return a hidden field for it // $result=$result."<input type='hidden' name='salt[$name]' value='$encrypt'>"; return $result; }
function parse_args($args) { $result = []; foreach ($args as $key => $item) { switch (true) { case is_object($item): $value = sprintf('<em>object</em>(%s)', parse_class(get_class($item))); break; case is_array($item): if (count($item) > 3) { $value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3))); } else { $value = sprintf('[%s]', parse_args($item)); } break; case is_string($item): if (strlen($item) > 20) { $value = sprintf('\'<a class="toggle" title="%s">%s...</a>\'', htmlentities($item), htmlentities(substr($item, 0, 20))); } else { $value = sprintf("'%s'", htmlentities($item)); } break; case is_int($item): case is_float($item): $value = $item; break; case is_null($item): $value = '<em>null</em>'; break; case is_bool($item): $value = '<em>' . ($item ? 'true' : 'false') . '</em>'; break; case is_resource($item): $value = '<em>resource</em>'; break; default: $value = htmlentities(str_replace("\n", '', var_export(strval($item), true))); break; } $result[] = is_int($key) ? $value : "'{$key}' => {$value}"; } return implode(', ', $result); }
} if (!defined('MODX_CORE_PATH') || !defined('MODX_CONFIG_KEY')) { print message("Could not load MODX.\n" . "MODX_CORE_PATH or MODX_CONFIG_KEY undefined in\n" . "{$dir}/config.core.php", 'ERROR'); die(2); } if (!file_exists(MODX_CORE_PATH . 'model/modx/modx.class.php')) { print message("modx.class.php not found at " . MODX_CORE_PATH . 'model/modx/modx.class.php', 'ERROR'); die(3); } // fire up MODX require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php'; require_once MODX_CORE_PATH . 'model/modx/modx.class.php'; $modx = new modX(); $modx->initialize('mgr'); // get args from cli $params = parse_args($argv); if ($params['help']) { show_help(); exit; } // Validate the args: if ($params['count'] <= 0) { print message("--count must be greater than 0", 'ERROR'); die; } if (!$params['remove'] && !$params['classname']) { print message("--classname is required for insert operations.", 'ERROR'); die; } if ($params['classname'] && !in_array($params['classname'], array_keys($supported_classnames))) { print message("Unsupported classname.", 'ERROR');
/** * Our main entry point. */ function main($argv) { $params = parse_args($argv); if (!sort($params["files"])) { $error = "sort() failed"; throw new Exception($error); } $hashes = ""; foreach ($params["files"] as $key => $value) { $sha1 = get_sha1($value); $hashes .= $sha1 . "\n"; printf("SHA1 of %40s: %s\n", $value, $sha1); debug(""); debug("---"); debug(""); } $sha1 = sha1($hashes); printf("SHA1 of %40s: %s\n", "ALL OF THE ABOVE", $sha1); }
/** * Invokes an http request and returns the status code (or response body if * $retBody is TRUE) on success, NULL on failure or FALSE if the response code * is not within the $success range * @param string $url the target url * @param string $method the http method * @param array $headers optional request headers to include (hash or array) * @param string $file optional file to pipe into the curl process as the * body * @param string $auth optional [user]:[pswd] to use for http authentication * @param string $success the http response code/range that consistitutes * a successful request. defaults to 200 to 299. This parameter may be a comma * separated list of values or ranges (e.g. "200,404" or "200-299,404") * @param boolean $retBody whether or not to return the response body. If * FALSE (default), the status code is returned * @return mixed */ function ch_curl($url, $method = 'HEAD', $headers = NULL, $file = NULL, $auth = NULL, $success = '200-299', $retBody = FALSE) { global $ch_curl_options; if (!isset($ch_curl_options)) { $ch_curl_options = parse_args(array('v' => 'verbose')); } if (!is_array($headers)) { $headers = array(); } $ofile = $retBody ? '/tmp/' . rand() : '/dev/null'; $curl = sprintf('curl -s -X %s%s -w "%s\\n" -o %s', $method, $method == 'HEAD' ? ' -I' : '', '%{http_code}', $ofile); if ($auth) { $curl .= sprintf(' -u "%s"', $auth); } if (is_array($headers)) { foreach ($headers as $header => $val) { $curl .= sprintf(' -H "%s%s"', is_numeric($header) ? '' : $header . ':', $val); } } // input file if (($method == 'POST' || $method == 'PUT') && file_exists($file)) { $curl .= sprintf(' --data-binary @%s', $file); if (!isset($headers['Content-Length']) && !isset($headers['content-length'])) { $curl .= sprintf(' -H "Content-Length:%d"', filesize($file)); } if (!isset($headers['Content-Type']) && !isset($headers['content-type'])) { $curl .= sprintf(' -H "Content-Type:%d"', get_mime_type($file)); } } $curl .= sprintf(' "%s"', $url); $ok = array(); foreach (explode(',', $success) as $range) { if (is_numeric($range)) { $ok[$range * 1] = TRUE; } else { if (preg_match('/^([0-9]+)\\s*\\-\\s*([0-9]+)$/', $range, $m) && $m[1] <= $m[2]) { for ($i = $m[1]; $i <= $m[2]; $i++) { $ok[$i] = TRUE; } } } } $ok = array_keys($ok); sort($ok); $cmd = sprintf('%s 2>/dev/null;echo $?', $curl); print_msg(sprintf('Invoking curl request: %s (expecting response %s)', $curl, $success), isset($ch_curl_options['verbose']), __FILE__, __LINE__); // execute curl $result = shell_exec($cmd); $output = explode("\n", trim($result)); $response = NULL; // interpret callback response if (count($output) == 2) { $status = $output[0] * 1; $ecode = $output[1] * 1; if ($ecode) { print_msg(sprintf('curl failed with exit code %d', $ecode), isset($ch_curl_options['verbose']), __FILE__, __LINE__, TRUE); } else { if (in_array($status, $ok)) { print_msg(sprintf('curl successful with status code %d', $status), isset($ch_curl_options['verbose']), __FILE__, __LINE__); $response = $retBody && file_exists($ofile) ? file_get_contents($ofile) : $status; } else { $response = FALSE; print_msg(sprintf('curl failed because to status code %d in not in allowed range %s', $status, $success), isset($ch_curl_options['verbose']), __FILE__, __LINE__, TRUE); } } } if ($retBody && file_exists($ofile)) { unlink($ofile); } return $response; }
/** * returns run options represents as a hash * @return array */ public static function getRunOptions() { // default run argument values $sysInfo = get_sys_info(); $ini = get_benchmark_ini(); $defaults = array('active_range' => 100, 'collectd_rrd_dir' => '/var/lib/collectd/rrd', 'fio' => 'fio', 'fio_options' => array('direct' => TRUE, 'ioengine' => 'libaio', 'refill_buffers' => FALSE, 'scramble_buffers' => TRUE), 'font_size' => 9, 'highcharts_js_url' => 'http://code.highcharts.com/highcharts.js', 'highcharts3d_js_url' => 'http://code.highcharts.com/highcharts-3d.js', 'jquery_url' => 'http://code.jquery.com/jquery-2.1.0.min.js', 'meta_compute_service' => 'Not Specified', 'meta_cpu' => $sysInfo['cpu'], 'meta_instance_id' => 'Not Specified', 'meta_memory' => $sysInfo['memory_gb'] > 0 ? $sysInfo['memory_gb'] . ' GB' : $sysInfo['memory_mb'] . ' MB', 'meta_os' => $sysInfo['os_info'], 'meta_provider' => 'Not Specified', 'meta_storage_config' => 'Not Specified', 'meta_test_sw' => isset($ini['meta-id']) ? 'ch-' . $ini['meta-id'] . (isset($ini['meta-version']) ? ' ' . $ini['meta-version'] : '') : '', 'oio_per_thread' => 64, 'output' => trim(shell_exec('pwd')), 'precondition_passes' => 2, 'ss_max_rounds' => 25, 'ss_verification' => 10, 'test' => array('iops'), 'threads' => '{cpus}', 'threads_per_core_max' => 2, 'threads_per_target_max' => 8, 'timeout' => 86400, 'wd_test_duration' => 60); $opts = array('active_range:', 'collectd_rrd', 'collectd_rrd_dir:', 'fio:', 'font_size:', 'highcharts_js_url:', 'highcharts3d_js_url:', 'jquery_url:', 'meta_compute_service:', 'meta_compute_service_id:', 'meta_cpu:', 'meta_drive_interface:', 'meta_drive_model:', 'meta_drive_type:', 'meta_instance_id:', 'meta_memory:', 'meta_os:', 'meta_notes_storage:', 'meta_notes_test:', 'meta_provider:', 'meta_provider_id:', 'meta_region:', 'meta_resource_id:', 'meta_run_id:', 'meta_storage_config:', 'meta_storage_vol_info:', 'meta_test_id:', 'meta_test_sw:', 'no3dcharts', 'nojson', 'nopdfreport', 'noprecondition', 'nopurge', 'norandom', 'noreport', 'nosecureerase', 'notrim', 'nozerofill', 'oio_per_thread:', 'output:', 'precondition_passes:', 'randommap', 'savefio', 'secureerase_pswd:', 'sequential_only', 'skip_blocksize:', 'skip_workload:', 'ss_max_rounds:', 'ss_verification:', 'target:', 'target_skip_not_present', 'test:', 'threads:', 'threads_per_core_max:', 'threads_per_target_max:', 'timeout:', 'trim_offset_end:', 'v' => 'verbose', 'wd_test_duration:', 'wd_sleep_between:'); $options = parse_args($opts, array('skip_blocksize', 'skip_workload', 'target', 'test')); $verbose = isset($options['verbose']) && $options['verbose']; // explicit fio command foreach ($defaults as $key => $val) { if (!isset($options[$key])) { $options[$key] = $val; } } // target/test argument (expand comma separated values) foreach (array('target', 'test') as $key) { if (isset($options[$key])) { $targets = array(); foreach ($options[$key] as $temp) { foreach (explode(',', $temp) as $target) { $targets[] = trim($target); } } $options[$key] = $targets; } } foreach (get_prefixed_params('fio_') as $key => $val) { $options['fio_options'][$key] = $val; } // don't use random IO if (isset($options['norandom']) && $options['norandom']) { if (isset($options['fio']['refill_buffers'])) { unset($options['fio']['refill_buffers']); } if (isset($options['fio']['scramble_buffers'])) { unset($options['fio']['scramble_buffers']); } } // implicit nosecureerase if (!isset($options['secureerase_pswd'])) { $options['nosecureerase'] = TRUE; } // implicit nopurge if (isset($options['nosecureerase']) && $options['nosecureerase'] && isset($options['notrim']) && $options['notrim'] && isset($options['nozerofill']) && $options['nozerofill']) { $options['nopurge'] = TRUE; } // threads is based on number of CPUs if (isset($options['threads']) && preg_match('/{cpus}/', $options['threads'])) { $options['threads'] = str_replace(' ', '', str_replace('{cpus}', BlockStorageTest::getCpuCount(), $options['threads'])); // expression if (preg_match('/[\\*\\+\\-\\/]/', $options['threads'])) { eval(sprintf('$options["threads"]=%s;', $options['threads'])); } $options['threads'] *= 1; if ($options['threads'] <= 0) { $options['threads'] = 1; } } // remove targets that are not present if (isset($options['target_skip_not_present']) && isset($options['target']) && count($options['target']) > 1) { print_msg(sprintf('Checking targets %s because --target_skip_not_present argument was set', implode(', ', $options['target'])), $verbose, __FILE__, __LINE__); $targets = array(); foreach ($options['target'] as $i => $target) { if (!is_dir($target) && !file_exists($target)) { print_msg(sprintf('Skipped test target %s because it does not exist and the --target_skip_not_present argument was set', $target), $verbose, __FILE__, __LINE__); } else { $targets[] = $target; } } $options['target'] = $targets; print_msg(sprintf('Adjusted test targets is %s', implode(', ', $options['target'])), $verbose, __FILE__, __LINE__); } // adjust threads for number of targets if (isset($options['target']) && count($options['target']) > 1) { $options['threads'] = round($options['threads'] / count($options['target'])); if ($options['threads'] == 0) { $options['threads'] = 1; } } // adjust for threads_per_target_max if (isset($options['threads_per_target_max']) && $options['threads'] > $options['threads_per_target_max']) { $threads = $options['threads']; $options['threads'] = $options['threads_per_target_max']; print_msg(sprintf('Reduced threads from %d to %d for threads_per_target_max constraint %d', $threads, $options['threads'], $options['threads_per_target_max']), $verbose, __FILE__, __LINE__); } $options['threads_total'] = $options['threads'] * count($options['target']); // adjust for threads_per_core_max if (isset($options['threads_per_core_max']) && $options['threads_total'] > $options['threads_per_core_max'] * BlockStorageTest::getCpuCount()) { $threads_total = $options['threads_total']; $threads = $options['threads']; $options['threads'] = round($options['threads_per_core_max'] * BlockStorageTest::getCpuCount() / count($options['target'])); if (!$options['threads']) { $options['threads'] = 1; } $options['threads_total'] = round($options['threads'] * count($options['target'])); if ($threads != $options['threads']) { print_msg(sprintf('Reduced total threads from %d to %d [threads per target from %d to %s] for threads_per_core_max constraint %d, %d CPU cores, and %d targets', $threads_total, $options['threads_total'], $threads, $options['threads'], $options['threads_per_core_max'], BlockStorageTest::getCpuCount(), count($options['target'])), $verbose, __FILE__, __LINE__); } else { print_msg(sprintf('Ignoring threads_per_core_max constraint %d because at least 1 thread per target is required', $options['threads_per_core_max']), $verbose, __FILE__, __LINE__); } } return $options; }
/** * returns run options represents as a hash * @return array */ public function getRunOptions() { if (!isset($this->options)) { if ($this->dir) { $this->options = self::getSerializedOptions($this->dir); $this->verbose = isset($this->options['verbose']); } else { // default run argument values $sysInfo = get_sys_info(); $defaults = array('collectd_rrd_dir' => '/var/lib/collectd/rrd', 'dns_retry' => 2, 'dns_samples' => 10, 'dns_timeout' => 5, 'geo_regions' => 'us_west us_central us_east canada eu_west eu_central eu_east oceania asia america_south africa', 'latency_interval' => 0.2, 'latency_samples' => 100, 'latency_timeout' => 3, 'meta_cpu' => $sysInfo['cpu'], 'meta_memory' => $sysInfo['memory_gb'] > 0 ? $sysInfo['memory_gb'] . ' GB' : $sysInfo['memory_mb'] . ' MB', 'meta_os' => $sysInfo['os_info'], 'output' => trim(shell_exec('pwd')), 'spacing' => 200, 'test' => 'latency', 'throughput_size' => 5, 'throughput_threads' => 2, 'throughput_uri' => '/web-probe'); $opts = array('abort_threshold:', 'collectd_rrd', 'collectd_rrd_dir:', 'discard_fastest:', 'discard_slowest:', 'dns_one_server', 'dns_retry:', 'dns_samples:', 'dns_tcp', 'dns_timeout:', 'geoiplookup', 'geo_regions:', 'latency_interval:', 'latency_samples:', 'latency_skip:', 'latency_timeout:', 'max_runtime:', 'max_tests:', 'meta_compute_service:', 'meta_compute_service_id:', 'meta_cpu:', 'meta_instance_id:', 'meta_location:', 'meta_memory:', 'meta_os:', 'meta_provider:', 'meta_provider_id:', 'meta_region:', 'meta_resource_id:', 'meta_run_id:', 'meta_test_id:', 'min_runtime:', 'min_runtime_in_save', 'output:', 'params_url:', 'params_url_service_type:', 'params_url_header:', 'randomize', 'same_continent_only', 'same_country_only', 'same_geo_region', 'same_provider_only', 'same_region_only', 'same_service_only', 'same_state_only', 'service_lookup', 'sleep_before_start:', 'spacing:', 'suppress_failed', 'test:', 'test_endpoint:', 'test_instance_id:', 'test_location:', 'test_private_network_type:', 'test_provider:', 'test_provider_id:', 'test_region:', 'test_service:', 'test_service_id:', 'test_service_type:', 'throughput_header:', 'throughput_https', 'throughput_inverse', 'throughput_keepalive', 'throughput_same_continent:', 'throughput_same_country:', 'throughput_same_geo_region:', 'throughput_same_provider:', 'throughput_same_region:', 'throughput_same_service:', 'throughput_same_state:', 'throughput_samples:', 'throughput_size:', 'throughput_slowest_thread', 'throughput_small_file', 'throughput_threads:', 'throughput_time', 'throughput_timeout:', 'throughput_uri:', 'throughput_use_mean', 'throughput_webpage:', 'throughput_webpage_check', 'traceroute', 'v' => 'verbose'); $this->options = parse_args($opts, array('latency_skip', 'params_url_service_type', 'params_url_header', 'test', 'test_endpoint', 'test_instance_id', 'test_location', 'test_provider', 'test_provider_id', 'test_region', 'test_service', 'test_service_id', 'test_service_type', 'throughput_header', 'throughput_webpage')); $this->options['run_start'] = time(); $this->verbose = isset($this->options['verbose']); // set default same size constraints if --throughput_size is not set if (!isset($this->options['throughput_size'])) { foreach (array('throughput_same_continent' => 10, 'throughput_same_country' => 20, 'throughput_same_geo_region' => 30, 'throughput_same_provider' => 10, 'throughput_same_region' => 100, 'throughput_same_state' => 50) as $k => $v) { $defaults[$k] = $v; } } foreach ($defaults as $key => $val) { if (!isset($this->options[$key])) { $this->options[$key] = $val; $this->defaultsSet[] = $key; } } if (isset($this->options['throughput_size']) && $this->options['throughput_size'] == 0) { $this->options['throughput_time'] = TRUE; } if (!isset($this->options['throughput_samples'])) { $this->options['throughput_samples'] = isset($this->options['throughput_small_file']) || isset($this->options['throughput_time']) ? 10 : 5; } if (!isset($this->options['throughput_timeout'])) { $this->options['throughput_timeout'] = isset($this->options['throughput_small_file']) || isset($this->options['throughput_time']) ? 5 : 180; } // expand geo_regions if (isset($this->options['geo_regions'])) { $geoRegions = array(); foreach (explode(',', $this->options['geo_regions']) as $r1) { foreach (explode(' ', $r1) as $r2) { $r2 = strtolower(trim($r2)); if ($r2 && !in_array($r2, $geoRegions)) { $geoRegions[] = $r2; } } } if ($geoRegions) { $this->options['geo_regions'] = $geoRegions; } } // expand tests if (!is_array($this->options['test'])) { $this->options['test'] = array($this->options['test']); } foreach ($this->options['test'] as $i => $test) { $tests = array(); foreach (explode(',', $test) as $t1) { foreach (explode(' ', $t1) as $t2) { $t2 = strtolower(trim($t2)); if ($t2 && !in_array($t2, $tests)) { $tests[] = $t2; } } } if ($tests) { $this->options['test'][$i] = $tests; } else { unset($this->options['test'][$i]); } } // get parameters from a URL if (isset($this->options['params_url'])) { $headers = array(); if (isset($this->options['params_url_header'])) { foreach ($this->options['params_url_header'] as $header) { if (preg_match('/^(.*):(.*)$/', $header, $m)) { $headers[trim($m[1])] = trim($m[2]); } else { print_msg(sprintf('Skipping header %s because it is not properly formatted ([key]:[val])', $header), $this->verbose, __FILE__, __LINE__, TRUE); } } } if ($params = json_decode($json = ch_curl($this->options['params_url'], 'GET', $headers, NULL, NULL, '200-299', TRUE), TRUE)) { print_msg(sprintf('Successfully retrieved %d runtime parameters from the URL %s', count($params), $this->options['params_url']), $this->verbose, __FILE__, __LINE__); foreach ($params as $key => $val) { if (!isset($this->options[$key]) || in_array($key, $this->defaultsSet)) { print_msg(sprintf('Added runtime parameter %s=%s from --params_url', $key, is_array($val) ? implode(',', $val) : $val), $this->verbose, __FILE__, __LINE__); $this->options[$key] = $val; } else { print_msg(sprintf('Skipping runtime parameter %s=%s from --params_url because it was set on the command line', $key, $val), $this->verbose, __FILE__, __LINE__); } } // remove test endpoints that are not of the --params_url_service_type // specified if (isset($this->options['params_url_service_type'])) { foreach ($this->options['test_endpoint'] as $i => $endpoint) { if (!isset($this->options['test_service_type'][$i]) || !in_array($this->options['test_service_type'][$i], $this->options['params_url_service_type'])) { print_msg(sprintf('Removing test endpoint %s because it is not included in the allowed service types: %s', $endpoint, implode(', ', $this->options['params_url_service_type'])), $this->verbose, __FILE__, __LINE__); unset($this->options['test_endpoint'][$i]); } } } } else { return array('params_url' => is_string($json) ? sprintf('Response from --params_url %s is not valid JSON: %s', $this->options['params_url'], $json) : sprintf('Unable to retrieve data from --params_url %s', $this->options['params_url'])); } } // expand test endpoints: first element is public hostname/IP; second is private if (isset($this->options['test_endpoint'])) { foreach ($this->options['test_endpoint'] as $i => $endpoint) { $endpoints = array(); foreach (explode(',', $endpoint) as $e1) { foreach (explode(' ', $e1) as $e2) { $e2 = trim($e2); if ($e2 && !in_array($e2, $endpoints)) { $endpoints[] = $e2; } if (count($endpoints) == 2) { break; } } if (count($endpoints) == 2) { break; } } if ($endpoints) { $this->options['test_endpoint'][$i] = $endpoints; } else { unset($this->options['test_endpoint'][$i]); } } } // perform service lookups using CloudHarmony 'Identify Service' API if (isset($this->options['service_lookup'])) { foreach ($this->options['test_endpoint'] as $i => $endpoints) { $hostname = str_replace('*', rand(), get_hostname($endpoints[0])); if (!isset($this->options['test_service_id'][$i]) && ($response = get_service_info($hostname, $this->verbose))) { if (!isset($this->options['test_provider_id'][$i])) { $this->options['test_provider_id'][$i] = $response['providerId']; } if (!isset($this->options['test_service_id'][$i])) { $this->options['test_service_id'][$i] = $response['serviceId']; } if (!isset($this->options['test_service_type'][$i])) { $this->options['test_service_type'][$i] = $response['serviceType']; } if (!isset($this->options['test_region'][$i]) && isset($response['region'])) { $this->options['test_region'][$i] = $response['region']; } if (!isset($this->options['test_location'][$i]) && isset($response['country'])) { $this->options['test_location'][$i] = sprintf('%s%s', isset($response['state']) ? $response['state'] . ',' : '', $response['country']); } } } if (!isset($this->options['meta_compute_service_id']) && ($hostname = trim(shell_exec('hostname'))) && ($response = get_service_info($hostname, $this->verbose))) { if (!isset($this->options['meta_provider_id'])) { $this->options['meta_provider_id'] = $response['providerId']; } if (!isset($this->options['meta_compute_service_id'])) { $this->options['meta_compute_service_id'] = $response['serviceId']; } if (!isset($this->options['meta_region']) && isset($response['region'])) { $this->options['meta_region'] = $response['region']; } if (!isset($this->options['meta_location']) && isset($response['country'])) { $this->options['meta_location'] = sprintf('%s%s', isset($response['state']) ? $response['state'] . ',' : '', $response['country']); } } } // perform geo ip lookups to determine endpoint locations if (isset($this->options['geoiplookup'])) { foreach ($this->options['test_endpoint'] as $i => $endpoints) { $hostname = str_replace('*', rand(), get_hostname($endpoints[0])); if (!isset($this->options['test_location'][$i]) && (!isset($this->options['test_service_type'][$i]) || $this->options['test_service_type'][$i] != 'cdn' && $this->options['test_service_type'][$i] != 'dns') && ($geoip = geoiplookup($hostname, $this->verbose))) { $this->options['test_location'][$i] = sprintf('%s%s', isset($geoip['state']) ? $geoip['state'] . ', ' : '', $geoip['country']); } } if (!isset($this->options['meta_location']) && ($hostname = trim(shell_exec('hostname'))) && ($geoip = geoiplookup($hostname, $this->verbose))) { $this->options['meta_location'] = sprintf('%s%s', isset($geoip['state']) ? $geoip['state'] . ', ' : '', $geoip['country']); } } // expand meta_location to meta_location_country and meta_location_state if (isset($this->options['meta_location'])) { $pieces = explode(',', $this->options['meta_location']); $this->options['meta_location_country'] = strtoupper(trim($pieces[count($pieces) - 1])); if (count($pieces) > 1) { $this->options['meta_location_state'] = trim($pieces[0]); } } // expand test_location to test_location_country and test_location_state if (isset($this->options['test_location'])) { $this->options['test_location_country'] = array(); $this->options['test_location_state'] = array(); foreach ($this->options['test_location'] as $i => $location) { $pieces = explode(',', $location); $this->options['test_location_country'][$i] = strtoupper(trim($pieces[count($pieces) - 1])); $this->options['test_location_state'][$i] = count($pieces) > 1 ? trim($pieces[0]) : NULL; } } // expand throughput_webpage if (isset($this->options['throughput_webpage'])) { foreach ($this->options['throughput_webpage'] as $i => $resource) { $resources = array(); foreach (explode(',', $resource) as $e1) { foreach (explode(' ', $e1) as $e2) { $e2 = trim($e2); $resources[] = $e2; } } if ($resources) { $this->options['throughput_webpage'][$i] = $resources; } else { unset($this->options['throughput_webpage'][$i]); } } } // set meta_geo_region if (isset($this->options['meta_location'])) { $pieces = explode(',', $this->options['meta_location']); $this->options['meta_location_country'] = strtoupper(trim($pieces[count($pieces) - 1])); $this->options['meta_location_state'] = count($pieces) > 1 ? trim($pieces[0]) : NULL; if ($geoRegion = $this->getGeoRegion($this->options['meta_location_country'], isset($this->options['meta_location_state']) ? $this->options['meta_location_state'] : NULL)) { $this->options['meta_geo_region'] = $geoRegion; } } } } return $this->options; }
* * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); $shortoptions = 'f:d:u:'; $helptext = <<<END_OF_SITEMAP_HELP Script for creating sitemaps files per http://sitemaps.org/ -f <indexfile> Use <indexfile> as output file -d <outputdir> Use <outputdir> for new sitemaps -u <outputurl> Use <outputurl> as root for URLs END_OF_SITEMAP_HELP; require_once INSTALLDIR . '/scripts/commandline.inc'; $output_paths = parse_args(); standard_map(); notices_map(); user_map(); index_map(); // ------------------------------------------------------------------------------ // Main functions: get data out and turn them into sitemaps // ------------------------------------------------------------------------------ // Generate index sitemap of all other sitemaps. function index_map() { global $output_paths; $output_dir = $output_paths['output_dir']; $output_url = $output_paths['output_url']; foreach (glob("{$output_dir}*.xml") as $file_name) { // Just the file name please.
<?php /* This is a script which generates simple PHPT test cases from the name of the function. * It works using the {{{ proto for the function PHP source code. The test cases that it generates * are simple, however you can also give it the name of a file with PHP code in and it will turn this * into the right format for a PHPT test. * This script will not generate expected output. * Further quidance on how to use it can be found on qa.php.net, or by using the -h command line option. */ //read the command line input and parse it, do some basic checks to make sure that it's correct $opt = initialise_opt(); $opt = parse_args($argv, $opt); check_source($opt['source_loc']); check_fname($opt['name']); check_testcase($opt['error_gen'], $opt['basic_gen'], $opt['variation_gen']); if ($opt['include_block'] != NULL) { check_file($opt['include_block']); } //Get a list of all the c funtions in the source tree $all_c = array(); $c_file_count = 0; dirlist($opt['source_loc'], $c_file_count, $all_c); //Search the list of c functions for the function prototype, quit if can't find it or if the function is an alias $test_info = get_loc_proto($all_c, $opt['name'], $opt['source_loc']); if (!$test_info['found']) { echo "\nExiting: Unable to find implementation of {$opt['name']} in {$opt['source_loc']}\n"; if ($test_info['falias']) { //But it may be aliased to something else echo "\n{$test_info['name']}() is an alias of {$test_info['alias']}() --- Write test cases for this instead \n"; } exit;
// You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * saves results based on the arguments defined in ../run.sh */ require_once dirname(__FILE__) . '/NetworkTest.php'; require_once dirname(__FILE__) . '/benchmark/save/BenchmarkDb.php'; $status = 1; $args = parse_args(array('iteration:', 'nostore_rrd', 'nostore_traceroute', 'params_file:', 'recursive_order:', 'recursive_count:', 'v' => 'verbose'), array('params_file'), 'save_'); $verbose = isset($args['verbose']); print_msg(sprintf('Initiating save with arguments [%s]', implode(', ', array_keys($args))), $verbose, __FILE__, __LINE__); // save to multiple repositories (multiple --params_file parameters) if (isset($args['params_file']) && count($args['params_file']) > 1) { $cmd = __FILE__; for ($i = 1; $i < count($argv); $i++) { if ($argv[$i] != '--params_file' && !in_array($argv[$i], $args['params_file'])) { $cmd .= ' ' . $argv[$i]; } } foreach ($args['params_file'] as $i => $pfile) { $pcmd = sprintf('%s --params_file %s --recursive_order %d --recursive_count %d', $cmd, $pfile, $i + 1, count($args['params_file'])); print $pcmd . "\n\n"; passthru($pcmd); }
/** * returns a BenchmarkDb object based on command line arguments. returns NULL * if there are any problems with the command line arguments * @return BenchmarkDb */ public static function &getDb() { $db = NULL; $options = parse_args(array('db:', 'db_and_csv:', 'db_callback_header:', 'db_host:', 'db_librato_aggregate', 'db_librato_color:', 'db_librato_count:', 'db_librato_description:', 'db_librato_display_max:', 'db_librato_display_min:', 'db_librato_display_name:', 'db_librato_display_units_long:', 'db_librato_display_units_short:', 'db_librato_display_stacked', 'db_librato_display_transform:', 'db_librato_max:', 'db_librato_min:', 'db_librato_measure_time:', 'db_librato_name:', 'db_librato_period:', 'db_librato_source:', 'db_librato_sum:', 'db_librato_summarize_function:', 'db_librato_sum_squares:', 'db_librato_type:', 'db_librato_value:', 'db_mysql_engine:', 'db_name:', 'db_port:', 'db_pswd:', 'db_prefix:', 'db_suffix:', 'db_user:'******'output:', 'params_file:', 'remove:', 'skip_validations', 'store:', 'v' => 'verbose'), $aparams = array('db_librato_aggregate', 'db_librato_color', 'db_librato_count', 'db_librato_description', 'db_librato_display_max', 'db_librato_display_min', 'db_librato_display_name', 'db_librato_display_units_long', 'db_librato_display_units_short', 'db_librato_display_stacked', 'db_librato_display_transform', 'db_librato_max', 'db_librato_min', 'db_librato_measure_time', 'db_librato_name', 'db_librato_period', 'db_librato_source', 'db_librato_sum', 'db_librato_summarize_function', 'db_librato_sum_squares', 'db_librato_type', 'db_librato_value', 'remove'), 'save_'); // merge settings with config file $cfile = BenchmarkDb::BENCHMARK_DB_CONFIG_FILE; if (isset($options['params_file']) && !file_exists($options['params_file']) && !file_exists($options['params_file'] = trim(shell_exec('pwd')) . '/' . $options['params_file'])) { print_msg(sprintf('--params_file %s is not a valid file', $options['params_file']), TRUE, __FILE__, __LINE__, TRUE); } else { if (isset($options['params_file'])) { $cfile = $options['params_file']; } } merge_options_with_config($options, $cfile); // convert array parameters found in config file foreach ($aparams as $aparam) { if (isset($options[$aparam]) && !is_array($options[$aparam])) { $p = array(); foreach (explode(',', $options[$aparam]) as $v) { if (preg_match('/^"(.*)"$/', $v) || preg_match("/^'(.*)'\$/", $v)) { $p[] = strip_quotes($v); } else { foreach (explode(' ', trim($v)) as $v) { $p[] = trim($v); } } } $options[$aparam] = $p; } } if (!isset($options['remove'])) { $options['remove'] = array(); } // output directory if (!isset($options['output'])) { $options['output'] = trim(shell_exec('pwd')); } // default table suffix if (!isset($options['db_suffix']) && ($ini = get_benchmark_ini()) && isset($ini['meta-version'])) { $options['db_suffix'] = '_' . str_replace('.', '_', $ini['meta-version']); } $impl = 'BenchmarkDb'; if (isset($options['db'])) { switch ($options['db']) { case 'bigquery': $impl .= 'BigQuery'; break; case 'callback': $impl .= 'Callback'; break; case 'librato': $impl .= 'Librato'; break; case 'mysql': $impl .= 'MySql'; break; case 'postgresql': $impl .= 'PostgreSql'; break; default: $err = '--db ' . $options['db'] . ' is not valid'; break; } // invalid --db argument if (isset($err)) { print_msg($err, isset($options['verbose']), __FILE__, __LINE__, TRUE); return $db; } } if ($impl != 'BenchmarkDb') { require_once sprintf('%s/%s.php', dirname(__FILE__), $impl); } $db = new $impl($options); $db->options = $options; $db->dir = $options['output']; if (!$db->validateDependencies()) { $db = NULL; } else { if (!isset($options['skip_validations']) && !$db->validate()) { $db = NULL; } } if ($db && isset($options['store'])) { require_once 'BenchmarkArchiver.php'; $db->archiver =& BenchmarkArchiver::getArchiver(); if (!$db->archiver) { $db = NULL; } } return $db; }
} } // // Begin Main Function // // $main_timer = timer_init(); if (file_exists(platform_getConfigFile())) { read_config_file(); } else { setup_default_config(); } if (isset($config_values['Settings']['Verbose'])) { $verbosity = $config_values['Settings']['Verbose']; } parse_args(); _debug(date("F j, Y, g:i a") . "\n", 0); if (isset($config_values['Feeds'])) { load_feeds($config_values['Feeds'], 1); feeds_perform_matching($config_values['Feeds']); } if (_isset($config_values['Settings'], 'Run Torrentwatch', FALSE) and !$test_run and $config_values['Settings']['Watch Dir']) { global $hit; $hit = 0; foreach ($config_values['Favorites'] as $fav) { $guess = guess_match(html_entity_decode($_GET['title'])); $name = trim(strtr($guess['key'], "._", " ")); if ($name == $fav['Name']) { $downloadDir = $fav['Save In']; } }
function main($argc, $argv) { /// parse args $tuple = parse_args($argc, $argv, "hp", "n"); $options = $tuple[0]; $properties = $tuple[1]; $filenames = $tuple[2]; /// help $command = basename($argv[0]); if ($options['h'] || array_key_exists('help', $properties)) { echo usage($command); return 0; } /// set values $ntimes = $options['n'] ? 0 + $options['n'] : 1000; if (!$filenames) { //$filenames = split(' ', 'tenjin tenjin_reuse smarty smarty_reuse php php_nobuf'); $filenames = split(' ', 'tenjin tenjin_reuse smarty smarty_reuse php'); } /// load context data //$context = load_yaml_file('bench_context.yaml'); $context = load_datafile('bench_context.php'); //var_export($context); /// create smarty template $templates = array(); $templates['smarty'] = 'bench_smarty.tpl'; $s = '{literal}' . file_get_contents('templates/_header.html') . '{/literal}' . file_get_contents("templates/_" . $templates['smarty']) . file_get_contents('templates/_footer.html'); file_put_contents("templates/" . $templates['smarty'], $s); /// create php template file $templates['php'] = 'templates/bench_php.php'; $s = file_get_contents('templates/_header.html') . file_get_contents('templates/_bench_php.php') . file_get_contents('templates/_footer.html'); $s = preg_replace('/^<\\?xml/', '<<?php ?>?xml', $s); file_put_contents($templates['php'], $s); /// create php template file $templates['tenjin'] = 'templates/bench_tenjin.phtml'; $s = file_get_contents('templates/_header.html') . file_get_contents('templates/_bench_tenjin.phtml') . file_get_contents('templates/_footer.html'); file_put_contents($templates['tenjin'], $s); /// load smarty library //define('SMARTY_DIR', '/usr/local/lib/php/Smarty/'); $flag_smarty = @(include_once 'Smarty.class.php'); /// load tenjin library $flag_tenjin = @(include_once 'Tenjin.php'); /// invoke benchmark function fprintf(STDERR, "*** ntimes={$ntimes}\n"); fprintf(STDERR, "%-20s%10s %10s %10s %10s\n", ' ', 'user', 'system', 'total', 'real'); foreach ($filenames as $name) { if (preg_match('/smarty/', $name) && !$flag_smarty || preg_match('/tenjin/', $name) && !$flag_tenjin) { fprintf(STDERR, "%-20s (not installed)\n", $name); continue; } $func = 'bench_' . preg_replace('/-/', '_', $name); $key = null; foreach (array('smarty', 'tenjin', 'php') as $s) { if (strpos($name, $s) !== false) { $key = $s; break; } } if (!array_key_exists($key, $templates)) { throw new Exception("{$name}: invalid target."); } // $filename = $templates[$key]; $start_microtime = microtime(true); $start_time = posix_times(); $output = $func($ntimes, $filename, $context); $stop_time = posix_times(); $stop_microtime = microtime(true); // $utime = ($stop_time['utime'] - $start_time['utime']) / 100.0; $stime = ($stop_time['stime'] - $start_time['stime']) / 100.0; $total = $utime + $stime; $real = $stop_microtime - $start_microtime; // fprintf(STDERR, "%-20s%10.5f %10.4f %10.4f %10.4f\n", $name, $utime, $stime, $total, $real); // if ($options['p']) { file_put_contents("output.{$name}", $output); } } return 0; }
return intval(trim(readline())); } function parse_args() { $shortopts = ""; $shortopts .= "h::"; /* Optional host */ $shortopts .= "p::"; /* Optional port */ $shortopts .= "a"; /* Optionally annotate output with code */ $longopts = array("host::", "port::", "annotate", "help"); $options = getopt($shortopts, $longopts); return $options; } $args = parse_args(); if (isset($args["help"])) { echo colorize("php program.php [-hHOST] [-pPORT] [-a]\n", 'black', true); echo " or\n"; echo colorize("php program.php [--host=HOST] [--port=PORT] [--annotate]\n", 'black', true); global $has_pygmentize; if (!$has_pygmentize) { echo "for syntax highlighting please install Pygmentize\n"; } exit(1); } $HOST_ADDR = isset($args["h"]) ? (string) $args["h"] : (isset($args["host"]) ? (string) $args["host"] : "127.0.0.1"); $HOST_PORT = isset($args["p"]) ? (int) $args["p"] : (isset($args["port"]) ? (string) $args["port"] : 3000); if (isset($args['a']) || isset($args['annotate'])) { $annotate = true; } else {
define( RM_STATE_READING_HEADER, 1 ); define( RM_STATE_READING_FROM, 2 ); define( RM_STATE_READING_SUBJECT,3 ); define( RM_STATE_READING_SENDER, 4 ); define( RM_STATE_READING_BODY, 5 ); $GLOBALS["ROUTER-MODE"]=false; if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["VERBOSE"]=true;echo "verbose=true;\n";} if($argv[1]=='--disclaimer-domain'){CheckDisclaimerTest($argv[2]);die();} if($argv[1]=='--disclaimer-uid'){CheckDisclaimerTestUid($argv[2]);die();} if($argv[1]=='--vacation-uid'){CheckOutOfOffice($argv[2],$argv[3]);die();} if($GLOBALS["VERBOSE"]){events("receive: " . implode(" ",$argv),"main",__LINE__);} $options = parse_args( array( 's', 'r', 'c', 'h', 'u','i','z' ), $_SERVER['argv']); //getopt("s:r:c:h:u:"); if (!array_key_exists('r', $options) || !array_key_exists('s', $options)) { fwrite(STDOUT, "Usage is $argv[0] -s sender@domain -r recip@domain\n"); exit(EX_TEMPFAIL); } $tmpfname = tempnam( "/var/lib/artica/mail/filter", 'IN.' ); $tmpf = @fopen($tmpfname, "w"); if( !$tmpf ) { writelogs("Error: Could not open $tempfname for writing: ".php_error(), "main",__FILE__,__LINE__); exit(EX_TEMPFAIL); } $GLOBALS["sender"]= strtolower($options['s']);
if ($argv[1] == '--disclaimer-domain') { CheckDisclaimerTest($argv[2]); die; } if ($argv[1] == '--disclaimer-uid') { CheckDisclaimerTestUid($argv[2]); die; } if ($argv[1] == '--vacation-uid') { CheckOutOfOffice($argv[2], $argv[3]); die; } if ($GLOBALS["VERBOSE"]) { events("receive: " . implode(" ", $argv), "main", __LINE__); } $options = parse_args(array('s', 'r', 'c', 'h', 'u', 'i', 'z'), $_SERVER['argv']); //getopt("s:r:c:h:u:"); if (!array_key_exists('r', $options) || !array_key_exists('s', $options)) { fwrite(STDOUT, "Usage is {$argv['0']} -s sender@domain -r recip@domain\n"); exit(EX_TEMPFAIL); } $tmpfname = tempnam("/var/lib/artica/mail/filter", 'IN.'); $tmpf = @fopen($tmpfname, "w"); if (!$tmpf) { writelogs("Error: Could not open {$tempfname} for writing: " . php_error(), "main", __FILE__, __LINE__); exit(EX_TEMPFAIL); } $GLOBALS["sender"] = strtolower($options['s']); $GLOBALS["recipients"] = $options['r']; $GLOBALS["original_recipient"] = $options['r']; $GLOBALS["POSTFIX_INSTANCE"] = $options['i'];
function parse_args(array $args) { $str = '('; $i = 0; foreach ($args as $arg) { if ($i > 0) { $str .= ', '; } switch (gettype($arg)) { case 'object': $str .= '<em>object</em>(' . short(get_class($arg)) . ')'; break; case 'array': $str .= '<em>array</em>(' . parse_args($arg) . ')'; break; case 'string': $str .= "'" . $arg . "'"; break; case 'NULL': $str .= 'null'; break; default: $str .= $arg; } $i++; } $str .= ')'; return $str; }
* Man pages * Central OS controlled config which is conpatible with core software upgrades, e.g. user is prompted by package installer before any config is overwritten * Examples * Web Front End * Individual user config files in users home directories * Other package based features... Candidates can also customise/fix and extend the code itself, this may help them fill the changelog with items. No marks are awarded for any complex customisations unless these are directly related to making a better package. Candidates are encorages to record their changes (maybe as a changelog or in the package documentation) and submit these along with the completed package. */ # Read config from STDIN if ($argc > 1) { $config = parse_args($argv); } # Read config from file if (@(!$config)) { $config_file = '/etc/cw1-6005-nm4e11/feeds.conf'; if (file_exists($config_file)) { $config = conf_from_file($config_file); } } if (@$config["help"]) { print_help(); exit(1); } if (@count($config["feeds"]) < 1) { echo "No Feeds Specified\n"; exit(1);
// You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * saves results based on the arguments defined in ../run.sh */ require_once dirname(__FILE__) . '/BlockStorageTest.php'; require_once dirname(__FILE__) . '/save/BenchmarkDb.php'; $status = 1; $args = parse_args(array('iteration:', 'nosave_fio', 'nostore_json', 'nostore_pdf', 'nostore_rrd', 'nostore_zip', 'v' => 'verbose')); // get result directories => each directory stores 1 iteration of results $dirs = array(); $dir = count($argv) > 1 && is_dir($argv[count($argv) - 1]) ? $argv[count($argv) - 1] : trim(shell_exec('pwd')); if (is_dir(sprintf('%s/1', $dir))) { $i = 1; while (is_dir($sdir = sprintf('%s/%d', $dir, $i++))) { $dirs[] = $sdir; } } else { $dirs[] = $dir; } if ($db =& BenchmarkDb::getDb()) { $db->tablePrefix = 'block_storage_'; // get results from each directory foreach ($dirs as $i => $dir) {
// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * Renders results as key/value pairs. Keys are suffixed with a numeric * value that is unique for each test (if more than 1 test performed) */ require_once dirname(__FILE__) . '/NetworkTest.php'; $status = 1; $dir = count($argv) > 1 && is_file($argv[count($argv) - 1]) ? dirname($argv[count($argv) - 1]) : trim(shell_exec('pwd')); $test = new NetworkTest($dir); $options = parse_args(array('v' => 'verbose')); if ($rows = $test->getResults()) { foreach ($rows as $i => $results) { $status = 0; $suffix = count($rows) > 1 ? $i + 1 : ''; foreach ($results as $key => $val) { printf("%s%s=%s\n", $key, $suffix, $val); } } } exit($status);
function main() { $options = parse_args(); if (array_key_exists('version', $options)) { print 'Plugin version: ' . VERSION; fullusage(); nagios_exit('', STATUS_OK); } check_environment(); check_domain($options); }