. */ $classinfo = array( "name" => "ZNCServerV0", "version" => 0.000, ); class ZNCServerV0 { private $host, $port; private $connector; public function ZNCServerV0($host, $port, $connector = NULL) { $this->host = $host; $this->port = $port; if($connector == NULL) $connector = new HTTPConnector(); $this->connector = $connector; } 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/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['clients'] = $exp2[0]; $exp2 = explode('', $exp[4]); $userdata['server'] = $exp2[0]; $exp2 = explode('', $exp[5]); $userdata['nick'] = $exp2[0]; $userlist[] = $userdata; } return $userlist; } public function getSeenList() { $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/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/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['servers'] = implode("\n", $servers); $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/webadmin/adduser", $post); return !preg_match("/Invalid Submission/i", $html); } public function delZNC($username) { $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/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/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("