0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-20 03:36:20 +02:00

scripts/shells/* (alias.php, domain.php, mailbox.php):

- delete AddTask and UpdateTask classes - obsoleted by model/CliEdit.php


git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1448 a1433add-5e2c-0410-b055-b7f2511e0802
This commit is contained in:
Christian Boltz 2013-04-01 17:03:25 +00:00
parent 7276276ba2
commit e3731dc89d
3 changed files with 0 additions and 473 deletions

View File

@ -51,135 +51,7 @@ class PostfixAdminAlias extends Shell {
}
class AddTask extends Shell {
/**
* Execution method always used for tasks
*
* @access public
*/
function execute() {
if (empty($this->args)) {
$this->__interactive();
}
if (!empty($this->args[0])) {
$this->__handle($this->args[0], $this->args[1]);
}
}
/**
* Interactive
*
* @access private
*/
function __interactive() {
while(0==0) {
$question = "Enter address:";
$address = $this->in($question);
if(preg_match("/^((?:(?:(?:[a-zA-Z0-9][\.\-\+_]?)*)[a-zA-Z0-9])+)\@((?:(?:(?:[a-zA-Z0-9][\.\-_]?){0,62})[a-zA-Z0-9])+)\.([a-zA-Z0-9]{2,6})$/", $address) == 1)
break;
$this->err("Invalid emailaddress");
}
while(0==0) {
$question = "Forward to:";
$goto = $this->in($question);
if(preg_match("/^((?:(?:(?:[a-zA-Z0-9][\.\-\+_]?)*)[a-zA-Z0-9])+)\@((?:(?:(?:[a-zA-Z0-9][\.\-_]?){0,62})[a-zA-Z0-9])+)\.([a-zA-Z0-9]{2,6})$/", $address) == 1)
break;
$this->err("Invalid emailaddress");
}
$this->__handle($address, $goto);
}
/**
* Interactive
*
* @access private
*/
function __handle($address, $goto) {
$handler = new AliasHandler(1);
$handler->init($address);
$values = array(
'goto' => explode(',', $goto),
);
if (!$handler->set($values)) {
$this->error("Error:", join("\n", $handler->errormsg));
} elseif (!$handler->store()) {
$this->error("Error:", join("\n", $handler->errormsg));
} else {
$this->out("");
$this->out("Alias ( $address -> $goto ) generated.");
$this->hr();
}
return;
}
/**
* Displays help contents
*
* @access public
*/
function help() {
$this->hr();
$this->out("Usage: postfixadmin-cli alias add <address> <goto>");
$this->hr();
$this->out('Commands:');
$this->out("\n\tadd\n\t\tAdds alias in interactive mode.");
$this->out("\n\tadd <address> <goto>\n\t\tAdds an alias <address> -> <goto>\n\t\t<goto> accepts multiple addresses as comma-separated list.");
$this->out("");
$this->_stop();
}
}
#TODO: implement
class UpdateTask extends Shell {
/**
* Execution method always used for tasks
*
* @access public
*/
function execute() {
if (empty($this->args)) {
$this->help();
//$this->__interactive();
}
if (!empty($this->args[0])) {
$this->help();
}
}
/**
* Interactive
*
* @access private
*/
function __interactive() {
}
/**
* Displays help contents
*
* @access public
*/
function help() {
$this->hr();
$this->out("Not Implemented yet!");
/*$this->out("Usage: postfixadmin-cli user update <args>");
//$this->hr();
//$this->out('Commands:');
//$this->out("\n\tmodel\n\t\tbakes model in interactive mode.");
//$this->out("\n\tmodel <name>\n\t\tbakes model file with no associations or validation");
//$this->out("");*/
$this->_stop();
}
}
class DeleteTask extends Shell {
/**
* Execution method always used for tasks

View File

@ -63,166 +63,6 @@ class PostfixAdminDomain extends Shell {
}
class AddTask extends Shell {
/**
* Execution method always used for tasks
*
* @access public
*/
function execute() {
if (empty($this->args)) {
$this->__interactive();
}
if (!empty($this->args[0])) {
$this->__handle($this->args[0], $this->args[1]);
# TODO: handle the various -* parameters (see help)
}
}
/**
* Interactive
*
* @access private
*/
function __interactive() {
while(0==0) {
$question = "Enter domain:";
$domain = $this->in($question);
if(preg_match("/^((?:(?:(?:[a-zA-Z0-9][\.\-_]?){0,62})[a-zA-Z0-9])+)\.([a-zA-Z0-9]{2,6})$/", $domain) == 1)
break;
$this->err("Invalid domain");
}
$question = "Description:";
$values['description'] = $this->in($question);
$question = "Number of Aliases:";
$values['aliases'] = $this->in($question);
$question = "Numer of Mailboxes:";
$values['mailboxes'] = $this->in($question);
$question = "Max Quota (in MB):";
$values['maxquota'] = $this->in($question);
$question = "Domain Quota (in MB):";
$values['quota'] = $this->in($question);
$handler = new DomainHandler();
$struct = $handler->getStruct();
$transports = $struct['transport']['options'];
$qt[] = 'Choose transport option';
foreach ($transports AS $key => $val) {
//workaround. $this->in hates number 0
$key = $key + 1;
$qt[] = '['.$key.'] - '.$val;
}
$t = $this->in( join("\n", $qt) );
$values['transport'] = $transports[$t-1]; # convert int to transport name
$question = "Add default Aliases:";
$values['default_aliases'] = $this->in($question, array('y','n'));
($values['default_aliases'] == 'y') ? $values['default_aliases'] = true : $values['default_aliases'] = false;
$question = "Use as Backup MX:";
$values['backupmx'] = $this->in($question, array('y','n'));
($values['backupmx'] == 'y') ? $values['backupmx'] = true : $values['backupmx'] = false;
$this->__handle($domain, $values);
}
/**
* Interactive
*
* @access private
*/
function __handle($domain, $values) {
$handler = new DomainHandler(1);
if (!$handler->init($domain)) {
$this->error("Error:",join("\n", $handler->errormsg));
return;
}
if (!$handler->set($values)) {
$this->error("Error:", join("\n", $handler->errormsg));
}
if (!$handler->store()) {
$this->error("Error:", join("\n", $handler->errormsg));
} else {
$this->out("");
$this->out("Domain ( $domain ) generated.");
$this->hr();
}
return;
}
/**
* Displays help contents
*
* @access public
*/
function help() {
# TODO: this is the DOMAIN shell...
$this->hr();
$this->out("Usage: postfixadmin-cli user add <address> [<password>] <name> <quota> [-g]");
$this->hr();
$this->out('Commands:');
$this->out("\n\tadd\n\t\tAdds mailbox in interactive mode.");
$this->out("\n\tadd <address> [<password>] [-g] <name> <quota>\n\t\tAdds mailbox for <address> with password <password> of if -g with rand pw. <quota> in MB.");
$this->out("");
$this->_stop();
}
}
class UpdateTask extends Shell {
/**
* Execution method always used for tasks
*
* @access public
*/
function execute() {
if (empty($this->args)) {
$this->help();
//$this->__interactive();
}
if (!empty($this->args[0])) {
$this->help();
}
}
/**
* Interactive
*
* @access private
*/
function __interactive() {
}
/**
* Displays help contents
*
* @access public
*/
function help() {
$this->hr();
$this->out("Not Implemented yet! ");
/*$this->out("Usage: postfixadmin-cli user update <args>");
$this->hr();
$this->out('Commands:');
$this->out("\n\tmodel\n\t\tbakes model in interactive mode.");
$this->out("\n\tmodel <name>\n\t\tbakes model file with no associations or validation");
$this->out("");*/
$this->_stop();
}
}
class DeleteTask extends Shell {
/**
* Execution method always used for tasks

View File

@ -51,191 +51,6 @@ class PostfixAdminMailbox extends Shell {
}
class AddTask extends Shell {
/**
* Execution method always used for tasks
*
* @access public
*/
# Find one function that matches all executes in shell childclasses.
# Eventually getopts like call in __handle??
function execute() {
if (empty($this->args)) {
$this->__interactive();
}
if (!empty($this->args[0])) {
if (count($this->args) < 3) { # without -g, 4 parameters are needed
$this->error('Error:', 'Not enough parameters!');
}
if (!empty($this->params['g'])) {
$this->__handle($this->args[0], NULL, true, $this->args[1], $this->args[2]);
} else {
$this->__handle($this->args[0], $this->args[1], false, $this->args[2], $this->args[3]);
}
}
}
/**
* Interactive
*
* @access private
*/
function __interactive() {
while(0==0) {
$question = "Enter address:";
$address = $this->in($question);
if(preg_match("/^((?:(?:(?:[a-zA-Z0-9][\.\-\+_]?)*)[a-zA-Z0-9])+)\@((?:(?:(?:[a-zA-Z0-9][\.\-_]?){0,62})[a-zA-Z0-9])+)\.([a-zA-Z0-9]{2,6})$/", $address) == 1)
break;
$this->err("Invalid emailaddress");
}
$question = "Do you want to generate a random password?";
$random = $this->in($question, array('y','n'));
$random == 'y' ? $random = true : $random = false;
$password = NULL;
if ($random == false) {
$question = "Enter the password:";
$password = $this->in($question);
}
$question = "Enter name:";
$name = $this->in($question);
$question = "Enter quota (MB):";
$quota = $this->in($question);
$question1[] = "Do you reallywant to add mailbox with this options?";
$question1[] = "Address: \t$address";
if($random)
$question1[] = "Random Password.";
else
$question1[] = "Password: \t$password";
$question1[] = "Name: \t$name";
$question1[] = "Quota: \t$quota MB";
$create = $this->in(join("\n", $question1), array('y','n'));
$create == 'y' ? $random = true : $random = false;
if ($create)
$this->__handle($address, $password, $random, $name, $quota);
}
/**
* Interactive
*
* @access private
*/
function __handle($address, $password, $gen = false, $name = '', $quota = 0) {
$pw = NULL;
if ($gen) {
$pw = generate_password();
} elseif ($password != NULL) {
$pw = $password;
}
$handler = new MailboxHandler(1);
if (!$handler->init($address)) {
$this->error("Error:", join("\n",$handler->errormsg));
$this->_stop(1);
}
$return = $handler->add($pw, $name, $quota, true, true );
#CHECK!
if ( !empty($this->params['q']) ) {
if( $return == false ) {
$this->_stop(1);
}
} else {
if( $return == false ) {
### When $this->error is used, $this->_stop is useless.
### Changed $this->error to stop with level 1.
### Eventually param q check in $this->error is better!! !Important!
$this->error("Error:", join("\n",$handler->errormsg));
} else {
$this->out("");
if ($name != '')
$this->out("Mailbox for $name generated.");
else
$this->out("Mailbox generated.");
$this->hr();
$this->out(sprintf('Mailaddress: %-20s', $address));
$this->out(sprintf('Password: %-20s',$pw));
$this->out(sprintf('Quota: %-20sMB',$quota));
$this->hr();
}
#CHECK!
}
return;
}
/**
* Displays help contents
*
* @access public
*/
function help() {
$this->hr();
$this->out("Usage: postfixadmin-cli mailbox add <address> [<password>] <name> <quota> [-g]");
$this->hr();
$this->out('Commands:');
$this->out("\n\tadd\n\t\tAdds mailbox in interactive mode.");
$this->out("\n\tadd <address> [<password>] [-g] <name> <quota>\n\t\tAdds mailbox for <address> with password <password> of if -g with rand pw. <quota> in MB.");
$this->out("");
$this->_stop();
}
}
class UpdateTask extends Shell {
/**
* Execution method always used for tasks
*
* @access public
*/
function execute() {
if (empty($this->args)) {
$this->help();
//$this->__interactive();
}
if (!empty($this->args[0])) {
$this->help();
}
}
/**
* Interactive
*
* @access private
*/
function __interactive() {
}
/**
* Displays help contents
*
* @access public
*/
function help() {
$this->hr();
$this->out("Not Implemented yet! If you want to change a password use the password command.");
/*$this->out("Usage: postfixadmin-cli mailbox update <args>");
$this->hr();
$this->out('Commands:');
$this->out("\n\tmodel\n\t\tbakes model in interactive mode.");
$this->out("\n\tmodel <name>\n\t\tbakes model file with no associations or validation");
$this->out("");*/
$this->_stop();
}
}
class DeleteTask extends Shell {
/**
* Execution method always used for tasks