From ece183526a9796d83abce425b785f0b2ce60a53a Mon Sep 17 00:00:00 2001 From: Giam Teck Choon Date: Tue, 27 Aug 2024 21:48:11 +0800 Subject: [PATCH 6/9] vm/vm.interface.php - Replace old constructor with new one so that it can support new version of PHP. Signed-off-by: Giam Teck Choon --- vm/vm.interface.php | 72 ++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/vm/vm.interface.php b/vm/vm.interface.php index b62e1f9..c622cbe 100644 --- a/vm/vm.interface.php +++ b/vm/vm.interface.php @@ -30,11 +30,11 @@ class vmailmgr { var $response; /* public: constructor */ - function vmailmgr($domain, $pass) { + function __construct($domain, $pass) { $this->domain = $domain; $this->pass = $pass; } - + /* private: return argument length in 2 bytes */ function arglen($a) { return chr((strlen($a) >> 8) & 255) . chr(strlen($a) & 255); @@ -47,11 +47,11 @@ class vmailmgr { /* command */ $vmcmd .= $this->arglen($cmd) . $cmd; - + /* arguments */ for($i=0; $iarglen($args[$i]) . $args[$i]; - + /* finally prepend protocol version (2) and total length of data */ $vmcmd = chr(2) . $this->arglen($vmcmd) . $vmcmd; @@ -59,7 +59,7 @@ class vmailmgr { if(($response = $this->send($vmcmd)) === false) return false; - /* parse response */ + /* parse response */ $response_code = ord($response[$i=0]); $response_length = (ord($response[++$i]) << 8) + ord($response[++$i]); @@ -68,7 +68,7 @@ class vmailmgr { /* validate response */ return $response_code === 0; } - + /* private: send data to socket and receive response */ function send($data) { if(isset($this->tcp_host)) { @@ -77,23 +77,23 @@ class vmailmgr { else if(isset($this->unix_socket)) { $sock = fsockopen($this->unix_socket, 0); } - + if(!$sock) { return false; } - + @fputs($sock, $data); - + $response = ''; while(!feof($sock) && ($buf=@fread($sock, 4096)) !== false) $response .= $buf; - - fclose($sock); - return $response; + fclose($sock); + + return $response; } - /* public: list all users */ + /* public: list all users */ function list_users() { if(!$this->raw("listdomain", array($this->domain, $this->pass))) return false; @@ -111,7 +111,7 @@ class vmailmgr { /* go through every element */ $element = substr($response, $i+1, $length); - + /* remainder (also skip one leading 0x00 (+1) two length bytes (+2)) */ $response = substr($response, $length + 3); @@ -128,7 +128,7 @@ class vmailmgr { $record_format_ver = ord($element[++$f]); - while($f < strlen($element) - 1) { + while($f < strlen($element) - 1) { $flag_num = ord($element[++$f]); $flag_val = ord($element[++$f]); @@ -141,11 +141,11 @@ class vmailmgr { case 1: $info[$count]['flags']['pass'] = ($flag_val == 1); break; - + case 2: $info[$count]['flags']['dest'] = ($flag_val == 1); break; - + case 3: $info[$count]['flags']['hardquota'] = ($flag_val == 1); break; @@ -176,7 +176,7 @@ class vmailmgr { case 10: $info[$count]['flags']['has_mailbox'] = ($flag_val == 1); - break; + break; } } @@ -220,10 +220,10 @@ class vmailmgr { with record format version (0x02). */ $record_format_ver = ord($response[0]); - + $f=0; - - while($f < strlen($response) - 1) { + + while($f < strlen($response) - 1) { $flag_num = ord($response[++$f]); $flag_val = ord($response[++$f]); @@ -236,11 +236,11 @@ class vmailmgr { case 1: $info['flags']['pass'] = ($flag_val == 1); break; - + case 2: $info['flags']['dest'] = ($flag_val == 1); break; - + case 3: $info['flags']['hardquota'] = ($flag_val == 1); break; @@ -271,7 +271,7 @@ class vmailmgr { case 10: $info['flags']['has_mailbox'] = ($flag_val == 1); - break; + break; } } @@ -280,12 +280,12 @@ class vmailmgr { $list = explode(chr(0), $response); $info['username'] = $user; - $info['password'] = ($list[$i=0] != '*'); + $info['password'] = ($list[$i=0] != '*'); $info['mailboxdir'] = $list[++$i]; while($list[++$i] !== '') $info['forwards'][] = $list[$i]; - + $info['personal'] = $list[++$i]; $info['hardquota'] = $list[++$i]; $info['softquota'] = $list[++$i]; @@ -305,7 +305,7 @@ class vmailmgr { function add_alias($user, $pass="", $forwards=array()) { return $this->raw("adduser2", array_merge(array($this->domain, $user, $this->pass, $pass, ""), $forwards)); } - + function delete_user($user) { return $this->raw("deluser", array($this->domain, $user, $this->pass)); } @@ -317,7 +317,7 @@ class vmailmgr { function set_forwards($user, $forwards=NULL) { if(!isset($forwards) || count($forwards) == 0) $forwards = ''; - + return $this->raw("chattr", array_merge(array($this->domain, $user, $this->pass, 2), $forwards)); } @@ -334,7 +334,7 @@ class vmailmgr { } function set_messagecount($user, $count='-') { - return $this->raw("chattr", array($this->domain, $user, $this->pass, 6, trim($count) == '' ? '-' : $count)); + return $this->raw("chattr", array($this->domain, $user, $this->pass, 6, trim($count) == '' ? '-' : $count)); } function set_expiry($user, $timestamp='-') { @@ -346,7 +346,7 @@ class vmailmgr { } function set_personal($user, $text='') { - return $this->raw("chattr", array($this->domain, $user, $this->pass, 9, $text)); + return $this->raw("chattr", array($this->domain, $user, $this->pass, 9, $text)); } function set_catchall($user=NULL) { @@ -383,7 +383,7 @@ class vmailmgr { } /* the response consists of: autoresponder text, 0x00, two length bytes, response text */ - if(!$this->raw("autoresponse", array($this->domain, $user, $this->pass, "read"))) + if(!$this->raw("autoresponse", array($this->domain, $user, $this->pass, "read"))) return false; /* make copy */ @@ -400,7 +400,7 @@ class vmailmgr { if(!$status) { $this->autoresponse_set_enabled($user, $status); } - + return $message; } @@ -412,10 +412,10 @@ class vmailmgr { $this->raw("autoresponse", array($this->domain, $user, $this->pass, "status")); return $this->response === 'enabled'; } - + function autoresponse_parse($message) { if(preg_match("/(.*?)\r?\n\r?\n(.*)/s", $message, $matches)) { - $result['body'] = $matches[2]; + $result['body'] = $matches[2]; $headers = preg_split("/\r?\n/", $matches[1]); @@ -428,10 +428,10 @@ class vmailmgr { else { $result['body'] = $message; } - + return $result; } - + /* return vmailmgr's last text message */ function last_response() { return $this->response; -- 2.34.1