Browse Source
Quite big CLI cleanup (and more)
Quite big CLI cleanup (and more)
model/CliHelp.php: - new class, used for "postfixadmin-cli $module help" - replaces the PostfixAdmin* classes in scripts/shells/*.php model/PFAHandler.php - add public $taskNames with the list of supported CLI commands scripts/postfixadmin-cli.php - dispatch(): - directly set the classes to load instead of using shell->loadTasks() - when "postfixadmin-cli $module" is called, display help instead of error message about "invalid command ''" - make it more readable by moving error checks to the beginning (replaces deeply nested if's with return statements) - remove unused code parts scripts/shells/*.php: - remove PostfixAdmin* classes (obsoleted by CliHelp) - remove $tasks (now in PFAHandler) - delete alias.php and domain.php because nothing is left - mailbox.php still contains PasswordTask scripts/shells/shell.php: - remove $taskNames (moved to PFAHandler) - remove loadTasks() (integrated in postfixadmin-cli.php's dispatch()) git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1575 a1433add-5e2c-0410-b055-b7f2511e0802pull/2/head
7 changed files with 120 additions and 303 deletions
-
65model/CliHelp.php
-
3model/PFAHandler.php
-
112scripts/postfixadmin-cli.php
-
54scripts/shells/alias.php
-
66scripts/shells/domain.php
-
50scripts/shells/mailbox.php
-
73scripts/shells/shell.php
@ -0,0 +1,65 @@ |
|||
<?php |
|||
|
|||
class CliHelp extends Shell { |
|||
|
|||
public $handler_to_use = "__not_set__"; |
|||
|
|||
/** |
|||
* Show help for this shell. |
|||
* |
|||
* @access public |
|||
*/ |
|||
public function execute() { |
|||
$this->help(); |
|||
} |
|||
|
|||
public function help() { |
|||
|
|||
$handler = new $this->handler_to_use; |
|||
# TODO: adjust help text according to $handler->taskNames
|
|||
|
|||
$module = preg_replace('/Handler$/', '', $this->handler_to_use); |
|||
$module = strtolower($module); |
|||
|
|||
$this->out( |
|||
"Usage:
|
|||
|
|||
postfixadmin-cli $module <task> [<address>] [--option value] |
|||
");
|
|||
/* |
|||
View $module in interactive mode. |
|||
|
|||
- or - |
|||
|
|||
postfixadmin-cli $module view <address> |
|||
|
|||
View $module <address> in non-interactive mode. |
|||
"); */
|
|||
|
|||
|
|||
|
|||
$head = "Usage: postfixadmin-cli $module <task> [<address>] [--option value] [--option value]\n"; |
|||
$head .= "-----------------------------------------------\n"; |
|||
$head .= "Parameters:\n\n"; |
|||
|
|||
$commands = array( |
|||
'task' => "\t<task>\n" . |
|||
"\t\tAvailable values:\n\n". |
|||
"\t\t".sprintf("%-20s %s", "view: ", "View an existing $module.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "add: ", "Add a $module.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "update: ", "Update a $module.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "delete: ", "Delete a $module")."\n". |
|||
"\t\t".sprintf("%-20s %s", "password: ", "Changes the password for a $module")."\n", |
|||
'address' => "\t[<address>]\n" . |
|||
"\t\tA address of recipient.\n", |
|||
); |
|||
|
|||
foreach ($commands as $cmd) { |
|||
$this->out("{$cmd}\n\n"); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ |
|||
@ -1,54 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
class PostfixAdminAlias extends Shell { |
|||
|
|||
/** |
|||
* Contains tasks to load and instantiate |
|||
* |
|||
* @var array |
|||
* @access public |
|||
*/ |
|||
var $tasks = array('Add', 'Update', 'Delete', 'View'); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* Show help for this shell. |
|||
* |
|||
* @access public |
|||
*/ |
|||
function help() { |
|||
$head = "Usage: postfixadmin-cli alias <task> [<address>] [] [-m <method>]\n"; |
|||
$head .= "-----------------------------------------------\n"; |
|||
$head .= "Parameters:\n\n"; |
|||
|
|||
$commands = array( |
|||
'task' => "\t<task>\n" . |
|||
"\t\tAvailable values:\n\n". |
|||
"\t\t".sprintf("%-20s %s", "view: ", "View an existing alias.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "add: ", "Adds an alias.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "update: ", "Updates an alias.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "delete: ", "Deletes an alias")."\n", |
|||
'address' => "\t[<address>]\n" . |
|||
"\t\tA address of recipient.\n", |
|||
); |
|||
|
|||
$this->out($head); |
|||
if (!isset($this->args[1])) { |
|||
foreach ($commands as $cmd) { |
|||
$this->out("{$cmd}\n\n"); |
|||
} |
|||
} elseif (isset($commands[strtolower($this->args[1])])) { |
|||
$this->out($commands[strtolower($this->args[1])] . "\n\n"); |
|||
} else { |
|||
$this->out("Command '" . $this->args[1] . "' not found"); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ |
|||
@ -1,66 +0,0 @@ |
|||
<?php |
|||
|
|||
|
|||
class PostfixAdminDomain extends Shell { |
|||
|
|||
/** |
|||
* Contains tasks to load and instantiate |
|||
* |
|||
* @var array |
|||
* @access public |
|||
*/ |
|||
var $tasks = array('Add', 'Update', 'Delete', 'View'); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* Show help for this shell. |
|||
* |
|||
* @access public |
|||
*/ |
|||
function help() { |
|||
$head = "Usage: postfixadmin-cli domain <task> [<domain>] [-desc \"<description>\"] [-a <aliases>] [-m <mailboxes>] [-q <quota in MB>] [-t <transport>] [-default] [-backup]\n"; |
|||
$head .= "-----------------------------------------------\n"; |
|||
$head .= "Parameters:\n\n"; |
|||
|
|||
$commands = array( |
|||
'task' => "\t<task>\n" . |
|||
"\t\tAvailable values:\n\n". |
|||
"\t\t".sprintf("%-20s %s", "view: ", "View an existing domain.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "add: ", "Adds a domain.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "update: ", "Updates an domain.")."\n". |
|||
"\t\t".sprintf("%-20s %s", "delete: ", "Deletes a domain")."\n", |
|||
'domain' => "\t[<domain>]\n" . |
|||
"\t\tA address of recipient.\n", |
|||
'a' => "\t[<aliaes>]\n" . |
|||
"\t\tNumber of max aliases. -1 = disable | 0 = unlimited\n", |
|||
'm' => "\t[<mailboxes>]\n" . |
|||
"\t\tNumber of max mailboxes. -1 = disable | 0 = unlimited\n", |
|||
'q' => "\t[<quota in MB>]\n" . |
|||
"\t\tMax Quota in MB. -1 = disable | 0 = unlimited\n", |
|||
'd' => "\t[<domain quota in MB>]\n" . |
|||
"\t\tDomain Quota in MB. -1 = disable | 0 = unlimited\n", |
|||
't' => "\t[<transport>]\n" . |
|||
"\t\tTransport options from config.inc.php.\n", |
|||
'default' => "\t\tSet to add default Aliases.\n", |
|||
'backup' => "\t\tSet if mailserver is backup MX.\n", |
|||
); |
|||
|
|||
$this->out($head); |
|||
if (!isset($this->args[1])) { |
|||
foreach ($commands as $cmd) { |
|||
$this->out("{$cmd}\n\n"); |
|||
} |
|||
} elseif (isset($commands[strtolower($this->args[1])])) { |
|||
$this->out($commands[strtolower($this->args[1])] . "\n\n"); |
|||
} else { |
|||
$this->out("Command '" . $this->args[1] . "' not found"); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue