/**
 * Validate command arguments
 *
 * @return void
 */
function validateCommands()
{
    if (!isset($_SERVER['argv'][1]) || 'install' !== $_SERVER['argv'][1]) {
        echo usage();
        exit;
    }
}
function main($argv)
{
    $cmd = array_shift($argv);
    if (count($argv) == 0) {
        usage($cmd);
        exit(2);
    }
    foreach ($argv as $arg) {
        if ($arg == "--help") {
            usage($cmd);
            exit(2);
        }
    }
    $dbname = $argv[0];
    $collectionName = count($argv) >= 2 ? $argv[1] : "languages";
    $data = parse_registry("language-subtag-registry.txt");
    echo "Writing language data to collection \"{$collectionName}\" in Mongo database \"{$dbname}\"... ";
    $m = new MongoClient();
    $db = $m->{$dbname};
    $coll = $db->{$collectionName};
    $coll->drop();
    // Replace old data with new, don't append
    $coll->batchInsert($data);
    echo "done.\n";
}
Beispiel #3
0
/**
 * Returns a new configuration object
 *
 * @param array $confPaths List of configuration paths from the bootstrap object
 * @param array $options Associative list of configuration options as key/value pairs
 * @return \Aimeos\MW\Config\Iface Configuration object
 */
function getConfig(array $confPaths, array $options)
{
    $config = array();
    if (isset($options['config'])) {
        foreach ((array) $options['config'] as $path) {
            if (is_file($path)) {
                $config = array_replace_recursive($config, require $path);
            } else {
                $confPaths[] = $path;
            }
        }
    }
    $conf = new \Aimeos\MW\Config\PHPArray($config, $confPaths);
    $conf = new \Aimeos\MW\Config\Decorator\Memory($conf);
    if (isset($options['option'])) {
        foreach ((array) $options['option'] as $option) {
            $parts = explode(':', $option);
            if (count($parts) !== 2) {
                printf("Invalid config option \"%1\$s\"\n", $option);
                usage();
            }
            $conf->set($parts[0], $parts[1]);
        }
    }
    return $conf;
}
Beispiel #4
0
function main($argv, $argc)
{
    if ($argc >= 2 && $argc <= 4) {
        $students = array("add_student", "del_student", "update_student", "show_student", "show_movies", "movies_storing", "show_stat");
        $options_w = array("show_rented_movies", "show_renting_students");
        $rent = array("rent_movie", "return_movie");
        $m = new MongoClient();
        $db = $m->db_etna;
        if (in_array($argv[1], $students)) {
            $argv[1]($db, $argv);
        } else {
            if (in_array($argv[1], $options_w) && $argc == 2) {
                $argv[1]($db);
            } else {
                if (in_array($argv[1], $rent) && $argc == 4) {
                    $argv[1]($db, $argv);
                } else {
                    echo "Error: Commande non definie.\n";
                    return 0;
                }
            }
        }
    } else {
        echo "Error: Nombre d'arguments incorrect.\n";
        usage();
    }
}
Beispiel #5
0
/**
 * Finds the next value of input flags, returns it and advances i
 *
 * @param   int    $i    The flag counter
 * @param   array  $argv The array with cli flags.
 * @returns string       The value of the switch at i.
 */
function flagval(&$i, $argv)
{
    if (empty($argv[$i + 1])) {
        usage();
    }
    return $argv[++$i];
}
Beispiel #6
0
function parse_arguments()
{
    global $args;
    $opts = getopt('f:p:s:d:lh');
    foreach ($opts as $k => $v) {
        switch ($k) {
            case 'f':
                $args->future = $v;
                break;
            case 'p':
                $args->near_past = $v;
                break;
            case 's':
                $_SERVER['SERVER_NAME'] = $v;
                break;
            case 'd':
                $args->debug = true;
                $debugging = explode(',', $v);
                break;
            case 'l':
                $args->set_last = true;
                break;
            case 'h':
                usage();
                break;
            default:
                $args->{$k} = $v;
        }
    }
}
Beispiel #7
0
function main()
{
    $args = $_SERVER['argv'];
    $script = array_shift($args);
    if (!count($args)) {
        usage($script);
    }
    $current = array_shift($args);
    if (!count($args)) {
        echo PHP_EOL;
    }
    $components = explode(',', array_shift($args));
    $paths = array();
    $base = dirname(dirname(dirname(dirname(dirname(__FILE__)))));
    foreach ($components as $component) {
        if ($current == '-') {
            $parts = array('', 'tmp', 'tagfiles');
        } else {
            $parts = array($base, $component);
        }
        $parts[] = $component . '.tagfile.xml';
        $path = implode(DIRECTORY_SEPARATOR, $parts);
        $paths[$path] = $current == '-' ? '../../' . $component . '/html' : dirname($path) . DIRECTORY_SEPARATOR . 'docs' . DIRECTORY_SEPARATOR . 'api' . DIRECTORY_SEPARATOR . 'html';
    }
    foreach ($paths as $tagfile => $relative) {
        echo "\"{$tagfile}={$relative}\" ";
    }
    echo PHP_EOL;
    exit(0);
}
Beispiel #8
0
function process_parameters(&$a, &$b, &$c)
{
    global $argc, $argv;
    $a = null;
    $b = null;
    $c = null;
    if ($argc != 4) {
        // first is executable file
        usage();
    }
    for ($i = 1; $i < $argc; $i++) {
        if (strpos($argv[$i], "a=") === 0) {
            $la = substr($argv[$i], 2);
        } else {
            if (strpos($argv[$i], "b=") === 0) {
                $lb = substr($argv[$i], 2);
            } else {
                if (strpos($argv[$i], "c=") === 0) {
                    $lc = substr($argv[$i], 2);
                }
            }
        }
    }
    if (!isset($la) || !isset($lb) || !isset($lc)) {
        usage();
    }
    $a = $la;
    $b = $lb;
    $c = $lc;
}
function verify_changelog($filename)
{
    if (!file_exists($filename)) {
        echo "Missing ChangeLog file!\n";
        echo "Need pre-populated {$filename}\n";
        echo "Did you forget to run \$ make ChangeLog ?\n";
        usage();
    }
}
function main()
{
    $opts = getopt("cath");
    if (isset($opts['h']) || !isset($opts['a']) && !isset($opts['t'])) {
        usage();
    }
    if (isset($opts['a']) && isset($opts['t'])) {
        fatal("can't use -a and -t together");
    }
    $mode = isset($opts['t']) ? 'tx' : 'address';
    if (isset($opts['c'])) {
        switch ($mode) {
            case "tx":
                echo <<<'EOD'

DROP TABLE t_shortlinks;
CREATE TABLE t_shortlinks (
    shortcut bytea NOT NULL PRIMARY KEY,
    hash bytea NOT NULL REFERENCES transactions
);

ALTER TABLE public.t_shortlinks OWNER TO blockupdate;
GRANT SELECT ON TABLE t_shortlinks TO "www-data";

EOD;
                break;
            case "address":
                echo <<<'EOD'

DROP TABLE a_shortlinks;
CREATE TABLE a_shortlinks (
    shortcut bytea NOT NULL PRIMARY KEY,
    hash160 bytea NOT NULL REFERENCES keys
);

ALTER TABLE public.a_shortlinks OWNER TO blockupdate;
GRANT SELECT ON TABLE a_shortlinks TO "www-data";

EOD;
                break;
        }
    }
    $fh = fopen("php://stdin", "r");
    while ($line = trim(fgets($fh))) {
        $arr = explode(" ", $line);
        if ($mode == "tx") {
            $shortcut_hex = decodeBase58($arr[0]);
            $tx_hex = $arr[1];
            echo "INSERT INTO t_shortlinks(shortcut, hash) VALUES (decode('{$shortcut_hex}', 'hex'), decode('{$tx_hex}', 'hex'));\n";
        } elseif ($mode == "address") {
            $shortcut_hex = decodeBase58($arr[0]);
            $hash160_hex = addressToHash160($arr[1]);
            echo "INSERT INTO a_shortlinks(shortcut, hash160) VALUES (decode('{$shortcut_hex}', 'hex'), decode('{$hash160_hex}', 'hex'));\n";
        }
    }
}
Beispiel #11
0
 public function parseArgs()
 {
     global $argc, $argv;
     if ($argc != 2) {
         usage();
         return false;
     }
     $this->scriptsXmlFile = $argv[1];
     return true;
 }
Beispiel #12
0
function check_input_parameters($options)
{
    if (!count($options) || isset($options['h']) || isset($options['help'])) {
        usage();
    }
    if (!isset($options['bucket']) || !isset($options['file']) || !isset($options['to'])) {
        print "Error: Missing mandatory parameter !\n";
        usage();
    }
}
Beispiel #13
0
function main()
{
    if ($_SERVER['argc'] <= 1 || false === is_dir($_SERVER['argv'][1])) {
        echo usage();
        exit(-1);
    } else {
        setup();
        init($_SERVER['argv'][1]);
    }
}
 public function parseArgs()
 {
     global $argc, $argv;
     if ($argc != 4) {
         usage();
         return false;
     }
     $this->beanDescriptorsDir = $argv[1];
     $this->templetsDir = $argv[2];
     $this->beansOutputDir = $argv[3];
     return true;
 }
Beispiel #15
0
function trax()
{
    global $search, $replace, $quiet;
    //  Get command line argument, if any
    if (!array_key_exists('argc', $GLOBALS) || $GLOBALS['argc'] < 2) {
        usage();
        // print Usage message and exit
    }
    $first_param_is_option = substr($GLOBALS['argv'][1], 0, 1) == "-" ? true : false;
    //  Check for excess arguments
    if ($GLOBALS['argc'] > 3 && !$first_param_is_option) {
        echo "unrecognized command argument " . $GLOBALS['argv'][2] . "\n";
        usage();
    }
    if ($first_param_is_option) {
        foreach ($GLOBALS['argv'] as $arg) {
            if ($arg == '-v' || $arg == '--version') {
                include dirname(__FILE__) . "/vendor/trax/trax.php";
                echo "Trax " . Trax::version() . "\n";
                exit;
            } elseif ($arg == '-h' || $arg == '--help') {
                usage();
            }
        }
    } else {
        //  Destination directory on command line
        $dstdir = $GLOBALS['argv'][1];
        if ($GLOBALS['argv'][2] == '-q' || $GLOBALS['argv'][2] == '--quiet') {
            $quiet = true;
        }
    }
    //  Guarantee it ends with DIRECTORY_SEPARATOR
    if (substr($dstdir, -1, 1) != DIRECTORY_SEPARATOR) {
        $dstdir .= DIRECTORY_SEPARATOR;
    }
    if (!create_dir($dstdir)) {
        return;
    }
    //  Assign real values for symbol substitution
    $replace[0] = realpath($dstdir) . '/config';
    // actual value of
    // the full filesystem path to the
    // Trax config/ directory in the
    // user's work area
    //  copy source directory to destination directory
    copy_dir(SOURCE_DIR, $dstdir);
    $dstdir .= 'vendor/trax/';
    if (!create_dir($dstdir)) {
        return;
    }
    // copy trax core code to vendor folder of project
    copy_dir(TRAX_SOURCE_DIR, $dstdir);
}
function parse_arguments(&$argv)
{
    // Default options
    $defaults = array('i' => 'localhost', 'p' => '8000', "mime-file" => "/etc/mime.types", "wp-root" => ".", "wp-version" => "latest", "show-errors" => 'E_ALL', "show-assets" => false, "show-hooks" => '', "show-everything" => false, "wordpresses" => $_SERVER['HOME'] . "/.cache/whippet/wordpresses", "cb-cache" => $_SERVER['HOME'] . "/.cache/whippet/callback-cache", "multisite" => false);
    // Are there some options in a config file? Check them in order.
    if (file_exists("/etc/whippetrc")) {
        $defaults = array_merge($defaults, parse_ini_file("/etc/whippetrc"));
    }
    if (!empty($_SERVER['HOME']) && file_exists($_SERVER['HOME'] . "/.whippetrc")) {
        $defaults = array_merge($defaults, parse_ini_file($_SERVER['HOME'] . "/.whippetrc"));
    }
    $optparser = new OptionParser();
    $optparser->addRule('h|help');
    $optparser->addRule('i::');
    $optparser->addRule('p::');
    $optparser->addRule('siteurl::');
    $optparser->addRule('q');
    $optparser->addRule('multisite');
    $optparser->addRule('mime-file::');
    $optparser->addRule('no-sql');
    $optparser->addRule('no-templates');
    $optparser->addRule('no-params');
    $optparser->addRule('no-scripts');
    $optparser->addRule('show-assets');
    $optparser->addRule('show-wp-errors');
    $optparser->addRule('show-wp-queries');
    $optparser->addRule('show-wp-hooks');
    $optparser->addRule('show-errors::');
    $optparser->addRule('show-everything');
    $optparser->addRule('wp-version::');
    $optparser->addRule('show-hooks::');
    $optparser->addRule('wordpresses::');
    try {
        $argv = $optparser->parse();
    } catch (Exception $e) {
        echo Colours::fg('red') . "Error: " . Colours::fg("white") . $e->getMessage() . "\n\n";
        usage();
        exit(0);
    }
    $arguments = $optparser->getAllOptions();
    if (!isset($arguments->siteurl)) {
        $i = isset($arguments['i']) ? $arguments['i'] : $defaults['i'];
        $p = isset($arguments['p']) ? $arguments['p'] : $defaults['p'];
        if ($p == 80) {
            $defaults['siteurl'] = "http://{$i}/";
        } else {
            $defaults['siteurl'] = "http://{$i}:{$p}/";
        }
    }
    return array_merge($defaults, $arguments);
}
/**
 * procc the request
 */
function proc_args()
{
    global $args;
    switch ($args[0]) {
        case 'run_scrape':
            $MV_BillScraper = new MV_BillScraper();
            $MV_BillScraper->procArguments();
            $MV_BillScraper->doScrapeInsert();
            break;
        default:
            usage();
            break;
    }
}
Beispiel #18
0
function init($argv, $argc)
{
    print "MySQL replace tool (replace.php)\nCopyright (C) 2012 Nick Bolton\n";
    if ($argc < 5) {
        echo "not enough args\n";
        usage();
        exit(1);
    }
    $context = new stdClass();
    for ($i = 1; $i < $argc - 1; $i++) {
        $arg = $argv[$i];
        switch ($arg) {
            case "--table":
                $context->table = $argv[++$i];
                break;
            case "--field":
                $context->field = $argv[++$i];
                break;
            case "--find":
                $context->find = $argv[++$i];
                break;
            case "--replace":
                $context->replace = $argv[++$i];
                break;
            default:
                echo "invalid arg: {$arg}\n";
                usage();
                exit(2);
        }
    }
    print sprintf("\noptions:\n  table: %s\n  field: %s\n  find: %s\n  replace: %s\n", $context->table, $context->field, $context->find, $context->replace);
    if (!file_exists("settings.ini")) {
        echo "missing: settings.ini";
        exit(3);
    }
    $ini = parse_ini_file("settings.ini", true);
    $host = $ini["db"]["host"];
    $user = $ini["db"]["user"];
    $password = $ini["db"]["password"];
    $database = $ini["db"]["database"];
    $hasPassword = $password != null ? "yes" : "no";
    print "\ndatabase:\n  host: {$host} \n  user: {$user} \n  password: {$hasPassword} \n  database: {$database} \n";
    $sql = new mysqli($host, $user, $password, $database);
    if ($sql->connect_errno) {
        throw new Exception("failed to connect to mysql: " . $sql->connect_error);
    }
    $sql->set_charset("utf8");
    $context->sql = $sql;
    return $context;
}
Beispiel #19
0
function getparam($param, $opt = '')
{
    global $argv;
    foreach ($argv as $value => $key) {
        if ($key == '-' . $param) {
            return $argv[$value + 1];
        }
    }
    if ($opt) {
        usage();
    } else {
        return FALSE;
    }
}
Beispiel #20
0
 function multiargument($flag, $legal_values)
 {
     parent::anyargument($flag);
     if (!$this->set) {
         return;
     }
     $map = array();
     foreach ($legal_values as $value) {
         $map[$value] = true;
     }
     if (!isset($map[$this->value])) {
         usage("{$this->value} is not a valid parameter to --{$flag}!");
         exit(1);
     }
 }
Beispiel #21
0
 function main()
 {
     if (count($argv) < 2) {
         usage();
     }
     $cmds = ['myfunc' => 'myfunc'];
     $cmdname = $argv[1];
     if (array_key_exists($cmdname, $cmds)) {
         $src = file_get_contents("php://stdin");
         $cmds[$cmdname]($src);
     } else {
         usage();
     }
     exit(0);
 }
function check_input_parameters()
{
    global $region;
    global $secret;
    global $key;
    global $debug;
    global $clientInfo;
    global $argv;
    // Handle input parameters
    if (!($options = getopt("c:k::s::r::hd"))) {
        usage();
    }
    if (isset($options['h'])) {
        usage();
    }
    if (isset($options['d'])) {
        $debug = true;
    }
    if (isset($options['c'])) {
        $clientConfFile = $options['c'];
        if (!file_exists($clientConfFile)) {
            throw new Exception("The client config file is not valid!");
        }
        if (!($clientInfo = file_get_contents($clientConfFile))) {
            throw new Exception("Unable to read the file");
        }
    } else {
        throw new Exception("Please provide the client config file!");
    }
    if (isset($options['k'])) {
        $key = $options['k'];
    } else {
        $key = getenv("AWS_ACCESS_KEY_ID");
    }
    if (isset($options['s'])) {
        $secret = $options['s'];
    } else {
        $secret = getenv("AWS_SECRET_KEY");
    }
    if (isset($options['r'])) {
        $region = $options['r'];
    } else {
        $region = getenv("AWS_DEFAULT_REGION");
    }
    if (!$region) {
        throw new Exception("Please provide your AWS region as parameter or using AWS_DEFAULT_REGION env var !");
    }
}
function parse_arguments()
{
    global $args;
    $opts = getopt('a:c:o:p:s:dh');
    foreach ($opts as $k => $v) {
        switch ($k) {
            case 'a':
                $args->archive_suffix = $v;
                break;
            case 'c':
                $args->collection = $v;
                break;
            case 'o':
                $args->older = $v;
                break;
            case 'p':
                $args->principal = $v;
                break;
            case 's':
                $_SERVER['SERVER_NAME'] = $v;
                break;
            case 'd':
                $args->debug = true;
                $debugging = explode(',', $v);
                break;
            case 'h':
                usage();
                break;
            default:
                $args->{$k} = $v;
        }
    }
    $bad = false;
    if ($args->principal === false) {
        echo "You must supply a principal.\n";
        $bad = true;
    }
    if ($args->collection === false) {
        echo "You must supply a collection.\n";
        $bad = true;
    }
    if ($bad) {
        usage();
    }
}
Beispiel #24
0
function parse_args()
{
    global $config_values, $argc, $argv, $test_run, $verbosity;
    for ($i = 1; $i < $argc; $i++) {
        switch ($_SERVER['argv'][$i]) {
            case '-c':
                $i++;
                $config_values['Settings']['Cache Dir'] = $_SERVER['argv'][$i];
                break;
            case '-C':
                unset($config_values['Settings']['Cache Dir']);
                break;
            case '-d':
                $config_values['Settings']['Run Torrentwatch'] = 0;
                break;
            case '-D':
                $config_values['Settings']['Run Torrentwatch'] = 1;
                break;
            case '-h':
                usage();
                exit(1);
            case '-nv':
                $verbosity = 0;
                break;
            case '-q':
                $verbosity = -1;
                break;
            case '-t':
                $test_run = 1;
                break;
            case '-v':
                $verbosity = 1;
                break;
            case '-vv':
                $verbosity = 2;
                break;
            default:
                _debug("Unknown command line argument:  " . $_SERVER['argv'][$i] . "\n", 0);
                break;
        }
    }
}
function FixQuotaDovecot($conditions)
{
    global $db;
    $db2 = new DB_System();
    $query = "SELECT mailbox.id,concat(path, '/Maildir/') as dir \n            FROM \n              mailbox \n              join address on address.id = mailbox.address_id \n              join domaines on domaines.id = address.domain_id\n              {$conditions} ;";
    if (!$db->query($query)) {
        usage("failed");
        // FIXME real error
        exit(1);
    }
    while ($db->next_record()) {
        $dir = $db->f("dir");
        $id = $db->f("id");
        $size = exec("/usr/bin/du -sb {$dir}|cut -f1");
        // FIXME check return value
        if (!$db2->query("UPDATE mailbox set bytes=" . intval($size) . " where id=" . intval($id) . ";")) {
            echo "Fail updating quota for mailbox : {$id}\n";
        }
    }
}
/**
 * Main program execution.
 */
function main()
{
    load_periodicrypt();
    verify_args();
    $message = getMessage();
    $coding_function = false;
    $coded_message = false;
    switch ($_SERVER['argv'][1]) {
        case 'encode':
            $coding_function = 'HashIt';
            break;
        case 'decode':
            $coding_function = 'UnhashIt';
            break;
        default:
            usage();
    }
    $coded_message = $coding_function($message);
    print $coded_message;
    exit(0);
}
function main($argc, $argv)
{
    sizeof($argv) == 3 or sizeof($argv) == 4 or die(usage());
    $jsonDocs = new JsonDocs(new JsonLoader());
    list($schemaFile, $schemaPointer) = makePath($argv[1]) or die("Invalid schema file\n");
    $schemaDoc = $jsonDocs->loadUri(new Uri($schemaFile));
    $schema = new JsonSchema($schemaDoc);
    print "Schema created from {$schemaFile}\n";
    $target = json_decode(file_get_contents($argv[2])) or die("Invalid JSON file\n");
    print "Target loaded\n";
    if (isset($argv[3])) {
        $target = $jsonDocs::getPointer($target, $argv[3]);
    }
    print "Validate [at {$schemaPointer}]:\n";
    $valid = $schema->validate($target, $schemaPointer);
    if ($valid === true) {
        print "OK\n";
    } else {
        print $valid;
    }
}
Beispiel #28
0
function main()
{
    $args = $_SERVER['argv'];
    $script = array_shift($args);
    $rem_args = array();
    $got_args = FALSE;
    for ($i = 0, $m = count($args); $i < $m; $i++) {
        $arg = $args[$i];
        if (!$got_args && !strncmp($arg, '-', 1)) {
            usage($script);
            exit(1);
        } else {
            $got_args = TRUE;
            $rem_args[] = $arg;
        }
    }
    // Retrieve the path to the repository's toplevel directory.
    $NUL = strncasecmp(PHP_OS, 'Win', 3) ? '/dev/null' : 'NUL';
    exec('git rev-parse --show-toplevel 2>' . $NUL, $output, $exitcode);
    if ($exitcode != 0) {
        fprintf(STDERR, "Could not determine path to .git folder.%s", PHP_EOL);
        exit(1);
    }
    $dir = trim($output[0]);
    $composer = get_composer($dir);
    $type = NULL;
    foreach ($rem_args as $arg) {
        if ($type === NULL && !strncmp($arg, '-', 1)) {
            $type = (string) substr($arg, 1);
            continue;
        } else {
            $type = 'string';
        }
        @settype($arg, $type);
        $composer = $composer[$arg];
        $type = NULL;
    }
    echo $composer . PHP_EOL;
    exit(0);
}
Beispiel #29
0
function readargs()
{
    global $server_id, $thread_nbr, $log;
    for ($i = 1; $i < $_SERVER["argc"]; $i++) {
        $it = explode("=", $_SERVER["argv"][$i]);
        switch ($it[0]) {
            case '--server_id':
                $server_id = $it[1];
                break;
            case '--thread_nbr':
                $thread_nbr = $it[1];
                break;
            case '--nolog':
                fclose($log);
                $log = STDOUT;
                break;
            default:
                usage();
                exit(1);
        }
    }
}
Beispiel #30
0
 function multiargument($flag, $legal_values)
 {
     global $argc, $argv;
     $this->set = false;
     $map = array();
     foreach ($legal_values as $value) {
         $map[$value] = true;
     }
     for ($i = 1; $i < $argc; $i++) {
         if (!preg_match("!--" . $flag . "=(.*)!", $argv[$i], $m)) {
             continue;
         }
         if (isset($map[$m[1]])) {
             $this->value = $m[1];
             $this->set = true;
             return;
         } else {
             usage("{$m[1]} is not a valid parameter to --{$flag}!");
             exit(1);
         }
     }
 }