From d21bf2e82de5d2f25638f86e0a85d232a9a97d7b Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sun, 13 Feb 2011 23:01:44 +0000 Subject: [PATCH] DomainHandler.php: proofreading results: various small changes - use $this->username for the domain name (I know the variable name is confusing, but I'd like to be consistent with the other classes) - remove $domain parameter in add() and view(), use $this->username instead - escape domain in view() for select query - removed unused "global $config" in view() - remove superfluous created/modified arrays in db_insert calls - added some TODO notes - changed db_log to 'CONSOLE' instead of $this-username for consistency with other classes. Long-term fix is to remove the first parameter of db_log and let it detect the username automatically. - various whitespace fixes git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@958 a1433add-5e2c-0410-b055-b7f2511e0802 --- model/DomainHandler.php | 62 ++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/model/DomainHandler.php b/model/DomainHandler.php index c05a24d3..8c8c96f2 100644 --- a/model/DomainHandler.php +++ b/model/DomainHandler.php @@ -5,7 +5,7 @@ */ class DomainHandler { - private $username = null; + private $username = null; # actually it's the domain - variable name kept for consistence with the other classes public $errormsg = array(); @@ -17,70 +17,62 @@ class DomainHandler { } public function getTransports() { - return Config::read('transport_options'); + return Config::read('transport_options'); } public function getTransport($id) { - $transports = Config::read('transport_options'); - return $transports[$id-1]; + $transports = Config::read('transport_options'); + return $transports[$id-1]; } - public function add($domain, $desc, $a, $m, $t, $q, $default, $backup){ + public function add($desc, $a, $m, $t, $q, $default, $backup) { - ($backup == true) ? $backup = db_get_boolean(true) : $backup = db_get_boolean(false); + ($backup == true) ? $backup = db_get_boolean(true) : $backup = db_get_boolean(false); - $arr = array( - 'domain' => $domain, + $arr = array( + 'domain' => $this->username, 'description' => $desc, 'aliases' => $a, 'mailboxes' => $m, 'maxquota' => $q, 'transport' => $this->getTransport($t), 'backupmx' => $backup, - ); + ); - $result = db_insert('domain', $arr, array('created', 'modified') ); - if ($result != 1) - { + $result = db_insert('domain', $arr); + if ($result != 1) { $this->errormsg[] = Lang::read('pAdminCreate_domain_result_error') . "\n($domain)\n"; return 1; - } - else - { - if ($default) - { - foreach (Config::read('default_aliases') as $address=>$goto) - { + } else { + if ($default) { + foreach (Config::read('default_aliases') as $address=>$goto) { $address = $address . "@" . $domain; + # TODO: use AliasHandler->add instead of writing directly to the alias table $arr = array( 'address' => $address, 'goto' => $goto, 'domain' => $domain, - ); - $result = db_insert ('alias', $arr, array('created', 'modified') ); + ); + $result = db_insert ('alias', $arr); } } $tMessage = Lang::read('pAdminCreate_domain_result_success') . "
($domain)
"; } - if (!domain_postcreation($domain)) - { - $tMessage = Lang::read('pAdminCreate_domain_error'); + if (!domain_postcreation($domain)) { + $tMessage = Lang::read('pAdminCreate_domain_error'); } - db_log($this->username, $domain, 'create_domain', ""); - return 0; + db_log('CONSOLE', $domain, 'create_domain', ""); + return 0; } - public function view ($domain) { - global $config; - - - + public function view () { $table_domain = table_by_key('domain'); - - $result = db_query("SELECT domain, description, aliases, mailboxes, maxquota, quota, transport, backupmx, DATE_FORMAT(created, '%d.%m.%y') AS created, DATE_FORMAT(modified, '%d.%m.%y') AS modified, active FROM $table_domain WHERE domain='$domain'"); + + $E_domain = escape_string($this->username); + $result = db_query("SELECT domain, description, aliases, mailboxes, maxquota, quota, transport, backupmx, DATE_FORMAT(created, '%d.%m.%y') AS created, DATE_FORMAT(modified, '%d.%m.%y') AS modified, active FROM $table_domain WHERE domain='$E_domain'"); if ($result['rows'] != 0) { - $this->return = db_array($result['result']); - return 0; + $this->return = db_array($result['result']); + return 0; } $this->errormsg = $result['error']; return 1;