X-Git-Url: http://git.pk910.de/?p=ZNCAdmin.git;a=blobdiff_plain;f=zncadmin%2FZNCServer.class.php;h=d5d4badbc6ff85050cb1eaf12abfebaaada96d7d;hp=35724a1c1994628cfa283a2a8c4b84872a71ce1c;hb=6cd66f219f6024ce6400f25b7b0165d37449e49f;hpb=d8a263cc8a2dda8ac9ac4932dc74af598a67d4a2 diff --git a/zncadmin/ZNCServer.class.php b/zncadmin/ZNCServer.class.php index 35724a1..d5d4bad 100644 --- a/zncadmin/ZNCServer.class.php +++ b/zncadmin/ZNCServer.class.php @@ -16,6 +16,11 @@ * along with this program. If not, see . */ +define("ERR_OK", 0); +define("ERR_UNKNOWN", 1); +define("ERR_MODULE_NOT_FOUND", 2); +define("ERR_USER_NOT_FOUND", 3); + class ZNCServer { private $host, $port; private $connector; @@ -135,11 +140,7 @@ class ZNCServer { $this->connector->post("http://".$this->host.":".$this->port."/mods/webadmin/deluser", $post); } - public function editZNC($username, $password = NULL, $new_servers = NULL, $add_modules = NULL, $del_modules = NULL, $others = NULL) { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/webadmin/edituser?user=".$username); - if(preg_match("/No such username/i", $html)) return false; - $post = array(); - $post['loadmod'] = array(); + private function parseHTMLFields($html, &$post) { preg_match_all("]*)>", $html, $matches); foreach($matches[0] as $input) { $fields = array(0 => ""); @@ -208,6 +209,14 @@ class ZNCServer { $content = $content[0]; $post[$name] = $content; } + } + + public function editZNC($username, $password = NULL, $new_servers = NULL, $add_modules = NULL, $del_modules = NULL, $others = NULL) { + $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/webadmin/edituser?user=".$username); + if(preg_match("/No such username/i", $html)) return false; + $post = array(); + $post['loadmod'] = array(); + $this->parseHTMLFields($html, $post); if($password) { $post['password'] = $password; $post['password2'] = $password; @@ -233,9 +242,25 @@ class ZNCServer { return !preg_match("/Invalid Submission/i", $html); } - public function simulZNC($username, $raw, $server = true) { + public function blockZNC($username, $block) { + $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/webadmin/edituser?user=".$username); + if(preg_match("/No such username/i", $html)) return ERR_USER_NOT_FOUND; + $post = array(); + $post['loadmod'] = array(); + $this->parseHTMLFields($html, $post); + if(!$post['embed_blockuser_presented']) return ERR_MODULE_NOT_FOUND; + if(!($post['embed_blockuser_block'] xor $block)) return ERR_OK; + $post['embed_blockuser_block'] = ($block ? "1" : null); + if(!$block) { + $post['doconnect'] = 1; + } + $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/webadmin/edituser?user=".$username, $post); + return (preg_match("/Invalid Submission/i", $html) ? ERR_UNKNOWN : ERR_OK); + } + + public function simulZNC($username, $raw, &$errmsg, $server = true) { $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/send_raw/"); - if(preg_match("/Not Found/i", $html)) return false; + if(preg_match("/Not Found/i", $html)) return ERR_MODULE_NOT_FOUND; $exp = explode('name="_CSRF_Check" value="', $html); $exp = explode('"', $exp[1]); $csrf = $exp[0]; @@ -246,6 +271,7 @@ class ZNCServer { $post['send_to'] = ($server ? "server" : "client"); $post['line'] = $raw; $this->connector->post("http://".$this->host.":".$this->port."/mods/send_raw/", $post); + return ERR_OK; } public function addChan($username, $channel, $key = NULL, $buffer = NULL) {