Example #1
0
 public function shutdown()
 {
     $f3 = \Base::instance();
     // @todo handle different shutdown for cli / web
     self::function_debug(__CLASS__, __FUNCTION__);
     self::dump_errors();
     cli::release_lockfile();
     My::info(self::$exit_code == 0 ? "Script exited successfully" : "Script exited with errors");
     exit(self::$exit_code);
 }
Example #2
0
 public function go()
 {
     cli::init();
     $cli_opts = cli::$cli_opts;
     $mode = -1;
     foreach ($cli_opts as $opt => $val) {
         if (in_array($opt, array_keys(data::$elements))) {
             $mode = $opt;
         }
     }
     if ($mode === -1) {
         echo "No action!" . PHP_EOL;
         exit(1);
     }
     subsys::run($mode);
     global $report;
     file_put_contents("./report.txt", $report->report);
 }
// Check initial password and e-mail address before we install
try {
    $institutionname = $cli->get_cli_param('institution');
    $excludelist = $cli->get_cli_param('exclude');
    $includelist = $cli->get_cli_param('include');
    // Overriding the value from config-defaults for this script
    $CFG->auth_ldap_debug_sync_cron = $cli->get_cli_param('verbose');
    $onlycontexts = $cli->get_cli_param('contexts');
    $searchsub = $cli->get_cli_param('searchsub');
    $grouptype = $cli->get_cli_param('grouptype');
    // If they supplied a grouptype, only allow it to be 'course' or 'standard'
    if ($grouptype != -1) {
        if ($grouptype !== 'course') {
            $grouptype = 'standard';
        }
    }
    $nocreate = $cli->get_cli_param('nocreate');
    $nestedgroups = $cli->get_cli_param('nestedgroups');
    $groupclass = $cli->get_cli_param('groupclass');
    $groupattribute = $cli->get_cli_param('groupattribute');
    $dryrun = $cli->get_cli_param('dryrun');
    auth_ldap_sync_groups($institutionname, true, $excludelist == -1 ? null : $excludelist, $includelist == -1 ? null : $includelist, $onlycontexts == -1 ? null : $onlycontexts, $searchsub == -1 ? null : $searchsub, $grouptype == -1 ? null : $grouptype, $nocreate == -1 ? null : !$nocreate, $nestedgroups == -1 ? null : $nestedgroups, $groupclass == -1 ? null : $groupclass, $groupattribute == -1 ? null : $groupattribute, false, null, null, $dryrun);
} catch (Exception $e) {
    $USER->logout();
    // important
    cli::cli_exit($e->getMessage(), true);
}
$USER->logout();
// important
cli::cli_exit('---------- ended at ' . date('r', time()) . ' ----------', true);
$options['adminemail']->description = get_string('cliadminemail', 'admin');
$options['adminemail']->required = true;
$settings = new stdClass();
$settings->options = $options;
$settings->info = get_string('cliinstallerdescription', 'admin');
$cli->setup($settings);
// Check whether we need to do anything
if (table_exists(new XMLDBTable('config'))) {
    cli::cli_exit(get_string('maharainstalled', 'admin'), false);
}
// Check initial password and e-mail address before we install
try {
    $adminpassword = $cli->get_cli_param('adminpassword');
    $adminemail = $cli->get_cli_param('adminemail');
} catch (ParameterException $e) {
    cli::cli_exit($e->getMessage(), true);
}
// Determine what we will install
$upgrades = check_upgrades();
$upgrades['firstcoredata'] = true;
$upgrades['localpreinst'] = true;
$upgrades['lastcoredata'] = true;
$upgrades['localpostinst'] = true;
// Actually perform the installation
log_info(get_string('cliinstallingmahara', 'admin'));
upgrade_mahara($upgrades);
// Set initial password and e-mail address
$userobj = new User();
$userobj = $userobj->find_by_username('admin');
$userobj->email = $adminemail;
$userobj->commit();
 * @copyright  (C) 2011 Andrew Nicols <*****@*****.**>
 *
 */
define('INTERNAL', 1);
define('ADMIN', 1);
define('INSTALLER', 1);
define('CLI', 1);
require dirname(dirname(dirname(__FILE__))) . '/init.php';
require get_config('libroot') . 'cli.php';
require get_config('libroot') . 'upgrade.php';
require get_config('docroot') . 'local/install.php';
$cli = get_cli();
$options = array();
$settings = new stdClass();
$settings->options = $options;
$settings->info = get_string('cliupgraderdescription', 'admin');
$cli->setup($settings);
// Check whether Mahara is installed yet
if (!table_exists(new XMLDBTable('config'))) {
    cli::cli_exit(get_string('maharanotinstalled', 'admin'), false);
}
// Check whether we need to do anything
$upgrades = check_upgrades();
if (empty($upgrades['settings']['toupgradecount'])) {
    cli::cli_exit(get_string('noupgrades', 'admin'), false);
}
// Check for issues which would pose problems during upgrade
ensure_upgrade_sanity();
// Actually perform the upgrade
log_info(get_string('cliupgradingmahara', 'admin'));
upgrade_mahara($upgrades);
Example #6
0
#!/usr/bin/php
<?php 
/* UbFoInfo */
/* UbFoInfo is a program to provide good info to online communities and is tailor made for ubuntu */
?>
===========================
==> UbFoInfo V0.1 Alpha <==
===========================
<?php 
include "functions.php";
if ($argc > 1) {
    cli::go();
} else {
    gui::go();
}
exit(0);
Example #7
0
        $console->register("ls")->setDefinition(array())->setDescription("list devices")->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
            $table = new \Symfony\Component\Console\Helper\Table($output);
            $table->setHeaders(array('Start Channel', 'Type', 'status'));
            foreach ($this->dmx->getDevices() as $device) {
                $table->addRow([$device->getStartChannel(), get_class($device), '[' . implode(',', $device->getChannels()) . ']']);
            }
            $table->render();
        });
        $console->register("run")->setDefinition(array(new InputArgument('device', InputArgument::REQUIRED, 'start channel of a device'), new InputArgument('method', InputArgument::REQUIRED, 'method'), new InputArgument('args', InputArgument::IS_ARRAY, 'arguments')))->setDescription("set command")->setCode(function (InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
            $device = null;
            foreach ($this->dmx->getDevices() as $_device) {
                if ($_device->getStartChannel() == $input->getArgument("device")) {
                    $device = $_device;
                    break;
                }
            }
            if ($device === null) {
                $output->writeln("<error>can't find device</error>");
                return 1;
            }
            $method = $input->getArgument("method");
            $args = $input->getArgument("args");
            call_user_func_array([$device, $method], $args);
            $this->dmx->send();
        });
        $console->run();
    }
}
require __DIR__ . '/vendor/autoload.php';
$cli = new cli();
$cli->run();
Example #8
0
    $_l->sprintf(' %s: 0 of %s', $tRow['cat_name'], number_format($tRow['cnt'], 0));
}
$_l->refresh();
foreach ($fields as $cat => $info) {
    $_r->println('Truncate table `cat_' . $cat . '`');
    $_r->refresh();
    F::$dbo->query('TRUNCATE `cat_' . $cat . '`');
    $_r->println('   Collecting RAW data');
    $_r->refresh();
    $q = F::$dbo->query('SELECT id, remote_ip, datetime, data FROM raw_log WHERE cat_name = "' . strtoupper($cat) . '" ORDER BY id ASC');
    $_r->println('   Processing');
    $_r->refresh();
    foreach ($q as $row) {
        $msgRaw = array();
        foreach (explode("\n", $row['data']) as $value) {
            $value = explode('=', $value, 2);
            $msgRaw[$value[0]] = $value[1];
        }
        cli::processCategory($cat, $info['fields'], $row['id'], $row['remote_ip'], $row['datetime'], $msgRaw);
        $fields[$cat]['processed']++;
        $_l->reset();
        foreach ($totals as $tRow) {
            $_l->sprintf('%s%s: %s of %s', strtolower($tRow['cat_name']) == $cat ? '>' : ' ', $tRow['cat_name'], number_format($fields[strtolower($tRow['cat_name'])]['processed'], 0), number_format($tRow['cnt'], 0));
        }
        $_l->refresh();
    }
}
$_r->println('Processing completed. Press any key...');
$_r->refresh();
ncurses_getch();
F::close();
Example #9
0
<?php

require "php_resources/settings.php";
require "php_resources/character.php";
require "php_resources/chk.php";
require "php_resources/cli.php";
require "php_resources/player.php";
require "php_resources/webInteract.php";
require "php_resources/commandInterpreter.php";
//require "vendor/autoload.php"
$cli = new cli();
//$cli = new cli();
$chk = new chk($cli);
$commandInterpreter = new commandInterpreter($cli, $settings["commandList"]);
$knettenba = new character($cli, "CAT", "Cat", 22, "Bugger all.");
$arraything = $commandInterpreter->sliceInput($cli->out("You have a spanner, there is a nut.", "p"));
$commandInterpreter->whichCommand($arraything);
$arraything = $commandInterpreter->sliceInput($cli->out("You have a spanner, there is a nut.", "p"));
$commandInterpreter->whichCommand($arraything);
$arraything = $commandInterpreter->sliceInput($cli->out("You have a spanner, there is a nut.", "p"));
$commandInterpreter->whichCommand($arraything);
$arraything = $commandInterpreter->sliceInput($cli->out("You have a spanner, there is a nut.", "p"));
$commandInterpreter->whichCommand($arraything);
$arraything = $commandInterpreter->sliceInput($cli->out("You have a spanner, there is a nut.", "p"));
$commandInterpreter->whichCommand($arraything);
/*
$flibble = $knettenba->ask("I SPEeAAK. MROWL.");
echo $flibble;

$knettenba->say("Hello, my name is ".$knettenba->getVar("name").".");
Example #10
0
        return $this->{$varName};
    }
    public function updateVar($varName, $newVal)
    {
        if ($varName == "name" || $varName == "descrpition" || $varname == "speices" || $varName == "hp" || $varName == "itemsCarried") {
            $this->{$varName} = $newVal;
            return true;
        } else {
            return false;
        }
    }
}
class player extends character
{
}
$cli = new cli();
$chk = new chk();
$knettenba = new character($cli, "CAT", "Cat", 22, "Bugger all.");
$knettenba->ask("I SPEeAAK. MROWL.");
$knettenba->say("Hello, my name is " . $knettenba->getVar("name") . ".");
$knettenba->updateVar("name", "TWAT");
$knettenba->say("Hello, my name is " . $knettenba->getVar("name") . ".");
//cho $cli->out("", "p");
//while(
$chk->inpContains("What are birds?", array(1 => array("We just don't know", "don't know,", "I don't know")), array("BOLLOCKS!", "We just don't know."))["outputKey"];
/*
$chk->inpContains(
	"You walk into x room. In the room is a table. On the table is a loaf of BREAD.",
	array(array("eat","bread"), array("leave", "exit"),array("knife", "cut", "chop", "slice"))
	array(0 => "NONSENSE", 1 => "You eat the bread. OMNOMNOM", "You f**k RIGHT OFF. You have no interest in this silly room.", "You realise kthere is a bread knife! Such fun! You carefully slice the bread and eat it. OM TO THE NOM TO THE NOM. Yes. Good."));
*/
Example #11
0
#!/usr/bin/php
<?php 
define('DIR_KIT', dirname(__FILE__) . '/');
$f = DIR_KIT . 'cli-init.php';
if (is_file($f)) {
    include $f;
}
class cli
{
    function __construct($argv)
    {
        $this->cmd = new command($argv);
    }
    function go()
    {
        $method = 'do' . ucfirst($this->cmd->getArg(0));
        if (strlen($this->cmd->getArg(0)) and method_exists($this, $method)) {
            $this->{$method}($this->cmd->getArg(1), $this->cmd->getArg(2), $this->cmd->getArg(3), $this->cmd->getArg(4), $this->cmd->getArg(5));
        } else {
            $this->doHelp();
        }
    }
    function doMd5($s)
    {
        // recommendation is to manually put the string instead of passing it by argument
        // so that it does not get stashed in bash history or anything else
        echo md5($s) . "\n";
    }
}
$cli = new cli($argv);
$cli->go();
Example #12
0
                $_wLeft->println('  ' . $tbl . ': ' . $info);
            }
        }
        $mem = number_format(memory_get_usage(), 0, '.', ',');
        $peak = number_format(memory_get_peak_usage(), 0, '.', ',');
        $peakR = number_format(memory_get_peak_usage(true), 0, '.', ',');
        $_wLeft->println(str_pad('=[Stats]', 23, '='));
        $_wLeft->println('  Mem: ' . $mem . ' bytes');
        $_wLeft->println('  Peak: ' . $peak . ' bytes');
        $_wLeft->println('  Real: ' . $peakR . ' bytes');
        $_wLeft->refresh();
        $_wRight->refresh();
        foreach ($gc as $cat => $time) {
            if ($gc[$cat] + cli::GARBAGE_COLLECTING_INTERVAL <= $curTime) {
                F::$dbo->resetTimer();
                $gc[$cat] = cli::cleanGarbage($cat, $curTime);
                $gcTimings[$cat] = F::$dbo->getTimer();
                break;
            }
        }
        gc_collect_cycles();
        if ($key == NCURSES_KEY_F10) {
            break;
        }
    }
    // while
} catch (Exception $e) {
    unset($_wLeft);
    unset($_wRight);
    print_r($e->getMessage());
}
Example #13
0
<?php

require "../vendor/autoload.php";
use JVZ\CLI\Utils as CLI;
CLI::line();
CLI::title("Utils");
CLI::line();
$name = CLI::ask("What's your name?", "Vincenzo");
$isTrue = CLI::askYN("Is it true?", "y");
CLI::newLine();
CLI::line();
cli::_echo('Your name is ' . $name);
if ($isTrue) {
    cli::_echo("and it's true");
} else {
    cli::_echo("but it's false");
}
Example #14
0
 /**
  * Main request singleton instance. If no URI is provided, the URI will
  * be automatically detected using PATH_INFO, REQUEST_URI, or PHP_SELF.
  *
  * @param   string   URI of the request
  * @return  Request
  */
 public static function instance(&$uri = FALSE)
 {
     if (Request::$instance === NULL) {
         if (Kohana::$is_cli) {
             // Default protocol for command line is cli://
             Request::$protocol = 'cli';
             // Get the command line options
             $options = cli::options('uri', 'method', 'get', 'post');
             if (isset($options['uri'])) {
                 // Use the specified URI
                 $uri = $options['uri'];
             }
             if (isset($options['method'])) {
                 // Use the specified method
                 Request::$method = strtoupper($options['method']);
             }
             if (isset($options['get'])) {
                 // Overload the global GET data
                 parse_str($options['get'], $_GET);
             }
             if (isset($options['post'])) {
                 // Overload the global POST data
                 parse_str($options['post'], $_POST);
             }
         } else {
             if (isset($_SERVER['REQUEST_METHOD'])) {
                 // Use the server request method
                 Request::$method = $_SERVER['REQUEST_METHOD'];
             }
             if (!empty($_SERVER['HTTPS']) and filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN)) {
                 // This request is secure
                 Request::$protocol = 'https';
             }
             if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
                 // This request is an AJAX request
                 Request::$is_ajax = TRUE;
             }
             if (isset($_SERVER['HTTP_REFERER'])) {
                 // There is a referrer for this request
                 Request::$referrer = $_SERVER['HTTP_REFERER'];
             }
             if (Request::$method !== 'GET' and Request::$method !== 'POST') {
                 // Methods besides GET and POST do not properly parse the form-encoded
                 // query string into the $_POST array, so we overload it manually.
                 parse_str(file_get_contents('php://input'), $_POST);
             }
             if ($uri === FALSE) {
                 if (isset($_SERVER['PATH_INFO'])) {
                     // PATH_INFO is most realiable way to handle routing, as it
                     // does not include the document root or index file
                     $uri = $_SERVER['PATH_INFO'];
                 } else {
                     // REQUEST_URI and PHP_SELF both provide the full path,
                     // including the document root and index file
                     if (isset($_SERVER['REQUEST_URI'])) {
                         $uri = $_SERVER['REQUEST_URI'];
                     } elseif (isset($_SERVER['PHP_SELF'])) {
                         $uri = $_SERVER['PHP_SELF'];
                     }
                     if (isset($_SERVER['SCRIPT_NAME']) and strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
                         // Remove the document root and index file from the URI
                         $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
                     }
                 }
             }
         }
         // Create the instance singleton
         Request::$instance = new Request($uri);
     }
     return Request::$instance;
 }
Example #15
0
 /**
  * Get a single line of text representing the exception:
  *
  * Error [ Code ]: Message ~ File [ Line ]
  *
  * @param   object  Exception
  * @return  string
  */
 public static function text($e, $full_args = FALSE)
 {
     // Should we use the full argument length or truncate?
     $arg_char_limit = $full_args ? 2500 : 50;
     // Clean up the message a bit
     $message = str_replace(array("<br>", "<br/>", "<br />", "\r\n", "\n", "\r"), '; ', strip_tags($e->getMessage()));
     // How was the request made
     $called = 'Request:' . "\n";
     $method = strtoupper(request::method());
     if ($method == 'CLI') {
         $called .= 'CLI - ' . cli::launch_cmd();
     } else {
         $called .= '[' . $method . '] ' . request::ip() . ' - ' . request::protocol() . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
         if (is_array($_POST) && count($_POST) > 0) {
             $called .= "\n\nBody:\n";
             $called .= var_export($_POST, TRUE);
         }
     }
     return sprintf('%s [ %s ]: %s ~ %s [ %d ]' . "\n\n" . '%s' . "\n\n" . '%s' . "\n", get_class($e), $e->getCode(), $message, Eight_Exception::debug_path($e->getFile()), $e->getLine(), $called, Eight_Exception::trace_string($e->getTrace(), $arg_char_limit));
 }
Example #16
0
    $adminpassword = $cli->get_cli_param('adminpassword');
    $adminemail = $cli->get_cli_param('adminemail');
} catch (ParameterException $e) {
    cli::cli_exit($e->getMessage(), true);
}
// Determine what we will install
$upgrades = check_upgrades();
$upgrades['firstcoredata'] = true;
$upgrades['localpreinst'] = true;
$upgrades['lastcoredata'] = true;
$upgrades['localpostinst'] = true;
// Actually perform the installation
log_info(get_string('cliinstallingmahara', 'admin'));
upgrade_mahara($upgrades);
// Set initial password and e-mail address
$userobj = new User();
$userobj = $userobj->find_by_username('admin');
$userobj->email = $adminemail;
$userobj->commit();
// Ensure that the dummy admin email is changed
update_record('artefact_internal_profile_email', array('email' => $adminemail), array('owner' => $userobj->id));
update_record('artefact', array('title' => $adminemail), array('owner' => $userobj->id, 'artefacttype' => 'email'));
// Password changes should be performed by the authfactory
$authobj = AuthFactory::create($userobj->authinstance);
$authobj->change_password($userobj, $adminpassword, true);
// Set site name
if ($sitename = $cli->get_cli_param('sitename')) {
    if (!set_config('sitename', $sitename)) {
        cli::cli_exit(get_string('cliupdatesitenamefailed', 'admin'), true);
    }
}