From: pk910 Date: Sat, 29 Jun 2013 22:37:32 +0000 (+0200) Subject: Merge branch 'ZNCv1' into MixedVersions X-Git-Url: http://git.pk910.de/?p=ZNCAdmin.git;a=commitdiff_plain;h=35d6cfed78a76d9cf7a679faba96df2ccc40a111 Merge branch 'ZNCv1' into MixedVersions --- 35d6cfed78a76d9cf7a679faba96df2ccc40a111 diff --cc zncadmin/ZNCServer.class.php index f85dd56,21d134b..8af0194 --- a/zncadmin/ZNCServer.class.php +++ b/zncadmin/ZNCServer.class.php @@@ -20,82 -20,369 +20,83 @@@ define("ERR_OK", 0) define("ERR_UNKNOWN", 1); define("ERR_MODULE_NOT_FOUND", 2); define("ERR_USER_NOT_FOUND", 3); +define("ERR_UNKNOWN_ZNC_VERSION_OR_METHOD", 4); -class ZNCServer { - private $host, $port; - private $connector; - - public function ZNCServer($host, $port) { - $this->host = $host; - $this->port = $port; - $this->connector = new HTTPConnector(); - } - - public function login($user, $pass) { - $post = array( - "user" => $user, - "pass" => $pass, - "submitted" => "1" - ); - $this->connector->post("http://".$this->host.":".$this->port."/login", $post); - $http = $this->connector->get("http://".$this->host.":".$this->port."/?cookie_check=true"); - $logged_in = !preg_match("/errorbar/i", $http); - - return $logged_in; - } - - public function getUserList() { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/listusers"); - $exp = explode('
', $html); - $exp = explode('
', $exp[1]); - $exp = explode('', $exp[0]); - $exp = explode('', $exp[1]); - $list = explode('', $list[$i]); - $exp2 = explode('', $exp[2]); - $userdata['user'] = $exp2[0]; - $exp2 = explode('', $exp[3]); - $userdata['server'] = $exp2[0]; - $exp2 = explode('', $exp[4]); - $userdata['clients'] = $exp2[0]; - $userlist[] = $userdata; - } - return $userlist; - } - - public function getSeenList() { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/lastseen/"); - $exp = explode('
', $html); - $exp = explode('
', $exp[1]); - $exp = explode('', $exp[0]); - $exp = explode('', $exp[1]); - $list = explode('', $list[$i]); - - $exp2 = explode('', $exp[1]); - $userdata['user'] = $exp2[0]; - $exp2 = explode('', $exp[2]); - $userdata['seen'] = $exp2[0]; - $userdata['seen_unix'] = strtotime($exp2[0]); - $exp2 = explode('', $exp[3]); - $userdata['info'] = $exp2[0]; - $seenlist[] = $userdata; - } - return $seenlist; - } - - /* - $settings array elements: - nick - altnick - ident - */ - public function addZNC($username, $password, $settings, $servers, $modules, $others) { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/adduser"); - $exp = explode('name="_CSRF_Check" value="', $html); - $exp = explode('"', $exp[1]); - $csrf = $exp[0]; - $post = array(); - $post['_CSRF_Check'] = $csrf; - $post['submitted'] = '1'; - //$post['doconnect'] = '1'; - $post['user'] = $username; - $post['password'] = $password; - $post['password2'] = $password; - $post['nick'] = $settings['nick']; - $post['altnick'] = $settings['altnick']; - $post['ident'] = $settings['ident']; - $post['statusprefix'] = '*'; - $post['loadmod'] = array(); - foreach($modules as $name => $args) { - $post['loadmod'][] = $name; - if($args != "") - $post['modargs_'.$name] = $args; - } - - foreach($others as $name => $value) { - $post[$name] = $value; - } - - $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/adduser", $post); +$zncserver_classes = array( + "ZNCServerV0.class.php", ++ "ZNCServerV1.class.php", +); - if(!preg_match("/Invalid Submission/i", $html)) { - if(!$this->addNetwork($username, $settings, $servers, $other)) { - return false; - } - return !preg_match("/Invalid Submission/i", $html); - } - return !preg_match("/Invalid Submission/i", $html); - } - - public function addNetwork($username, $settings, $servers, $other) { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/addnetwork?user=".$username); - $exp = explode('name="_CSRF_Check" value="', $html); - $exp = explode('"', $exp[1]); - $csrf = $exp[0]; - $post = array(); - $post['_CSRF_Check'] = $csrf; - $post['submitted'] = '1'; - $post['network'] = 'default'; - $post['nick'] = $settings['nick']; - $post['altnick'] = $settings['altnick']; - $post['ident'] = $settings['ident']; - $post['servers'] = implode("\n", $servers); - $post['doconnect'] = '1'; - $post['floodprotection'] = '1'; - $post['floodrate'] = '1.0'; - $post['floodburst'] = '4'; - $post['user'] = $username; - - foreach($others as $name => $value) { - $post[$name] = $value; - } - - $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/addnetwork", $post); - return !preg_match("/Invalid Submission/i", $html); - } - - public function delZNC($username) { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/deluser?user=".$username); - $exp = explode('name="_CSRF_Check" value="', $html); - $exp = explode('"', $exp[1]); - $csrf = $exp[0]; - $post = array(); - $post['_CSRF_Check'] = $csrf; - $post['submitted'] = '1'; - $post['user'] = $username; - $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/deluser", $post); - } - - private function parseHTMLFields($html, &$post) { - preg_match_all("]*)>", $html, $matches); - foreach($matches[0] as $input) { - $fields = array(0 => ""); - $esc = false; $str = false; - $fieldid = 0; - for($i = 0; $i < strlen($input); $i++) { - if($esc) { - $esc = false; - $fields[$fieldid] .= $input[$i]; - continue; - } - if($input[$i] == "\\") { - $esc = true; - } - if($input[$i] == "\"") { - $str = !$str; - continue; - } - if($input[$i] == " " && !$str) { - $fields[++$fieldid] = ""; - continue; - } - $fields[$fieldid] .= $input[$i]; - } - $cfields = array(); - foreach($fields as $field) { - $fieldexp = explode("=", $field, 2); - if(count($fieldexp) != 2) continue; - $cfields[$fieldexp[0]] = $fieldexp[1]; - } - $name = $cfields['name']; - switch($cfields['type']) { - case "text": - case "hidden": - $value = $cfields['value']; - break; - case "checkbox": - if($cfields['checked']) { - $value = ($cfields['value'] ? $cfields['value'] : "1"); - } else - $value = null; - break; - default: - $value = null; - } - if($name && $value) { - if(array_key_exists($name, $post)) { - if(!is_array($post[$name])) { - $cvalue = $post[$name]; - $post[$name] = array(); - $post[$name][] = $cvalue; - } - $post[$name][] = $value; - } else - $post[$name] = $value; - } - } - //textareas - $textareas = explode("