/usr/bin/wicked is in php-horde-wicked 2.0.1-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #!/usr/bin/env php
<?php
/**
* This script interfaces with Wicked via the command-line
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @author Vijay Mahrra <vijay.mahrra@es.easynet.net>
*/
require_once __DIR__ . '/../lib/Application.php';
Horde_Registry::appInit('wicked', array('cli' => true));
$debug = false;
$out = 'screen';
// We accept the user name on the command-line.
$ret = Console_Getopt::getopt(Console_Getopt::readPHPArgv(), 'hu::p::ldg::o::',
array('help', 'username==', 'password==', 'list-pages',
'debug', 'get==', 'out=='));
if ($ret instanceof PEAR_Error) {
$error = _("Couldn't read command-line options.");
Horde::logMessage($error, 'DEBUG');
$cli->fatal($error);
}
list($opts, $args) = $ret;
// Show help and exit if no arguments were set.
if (!count($opts)) {
showHelp();
exit;
}
foreach ($opts as $opt) {
list($optName, $optValue) = $opt;
switch ($optName) {
case 'd':
case '--debug':
$debug = true;
break;
case 'u':
case '--username':
$username = $optValue;
break;
case 'p':
case '--password':
$password = $optValue;
break;
case 'l':
case '--list-pages':
$listpages = true;
break;
case 'g':
case '--get':
$get = $optValue;
break;
case 'o':
case '--out':
$out = $optValue;
break;
default:
case 'h':
case '--help':
showHelp();
exit;
}
}
// Login to horde if username & password are set.
if (!empty($username) && !empty($password)) {
$auth = $injector->getInstance('Horde_Core_Factory_Auth')->create();
if (!$auth->authenticate($username, array('password' => $password))) {
$error = _("Login is incorrect.");
Horde::logMessage($error, 'ERR');
$cli->message($msg, 'cli.error');
} else {
$msg = sprintf(_("Logged in successfully as \"%s\"."), $username);
Horde::logMessage($msg, 'DEBUG');
$cli->message($msg, 'cli.success');
}
}
// list page titles only
if (!empty($listpages)) {
$pages = $wicked->getPages();
foreach ($pages as $page) {
$cli->writeln($page);
}
exit;
}
// retrieve a user-specified page or all of them
if (!is_null($get)) {
try {
$results = $wicked->retrieveByName($get);
} catch (Wicked_Exception $e) {
$cli->message($e->getString, 'cli.error');
exit;
}
} elseif (is_null($get)) {
$results = $wicked->getAllPages();
}
// if we have a list of pages set, output them
switch ($out) {
default:
case 'xml':
if (isset($results) && count($results) > 0) {
$cli->writeln("<wicked:wikipage>");
foreach ($results as $page) {
foreach ($page as $k => $v) {
$cli->writeln(sprintf("<wicked:%s>%s</wicked:%s>", $k, htmlentities($v), $k));
}
}
$cli->writeln("</wicked:wikipage>");
$cli->writeln();
}
break;
}
exit;
/**
* Show the command line arguments that the script accepts.
*/
function showHelp()
{
global $cli;
$cli->writeln(sprintf(_("Usage: %s [OPTIONS]..."), basename(__FILE__)));
$cli->writeln();
$cli->writeln(_("Mandatory arguments to long options are mandatory for short options too."));
$cli->writeln();
$cli->writeln(_("-h, --help Show this help"));
$cli->writeln(_("-d, --debug Run in debug mode (displays extra information)"));
$cli->writeln(_("-l, --list-pages List pages"));
$cli->writeln(_("-g, --get[=pagetitle] Return all pages (unless pagetitle specified)"));
$cli->writeln(_("-o, --out[=type] Output type for results (default:xml)"));
$cli->writeln(_("-u, --username[=username] Horde login username"));
$cli->writeln(_("-p, --password[=password] Horde login password"));
$cli->writeln();
}
|