Mercurial > hg > fapweb
diff createdb.php @ 50:184a4188555c
Move CLI helper functions to createdb.php, as they are now only used there.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 05 Oct 2013 04:14:21 +0300 |
parents | 73123e322133 |
children | 30385b66ca1c |
line wrap: on
line diff
--- a/createdb.php Sat Oct 05 04:09:05 2013 +0300 +++ b/createdb.php Sat Oct 05 04:14:21 2013 +0300 @@ -3,8 +3,43 @@ require "mconfig.inc.php"; require "msite.inc.php"; -// We don't want to be run from anywhere else than commandline -stCheckCLIOrDie(); +// +// CLI utility helper functions +// +function stCArg($index) +{ + global $argc, $argv; + if ($index < $argc) + return $argv[$index]; + else + return FALSE; +} + +function stCArgLC($index) +{ + global $argc, $argv; + if ($index < $argc) + return strtolower($argv[$index]); + else + return FALSE; +} + + +function stCSQLError($sql) +{ + global $db; + die("Error executing SQL query: ".implode("; ", $db->errorInfo())." in statement \"".$sql."\"\n"); + exit; +} + + +// Check if we are running from commandline or not +if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) +{ + header("Status: 404 Not Found"); + die(); +} + // The defaults we put in