X-Git-Url: http://git.pk910.de/?p=ZNCAdmin.git;a=blobdiff_plain;f=zncadmin%2FZNCServer.class.php;fp=zncadmin%2FZNCServer.class.php;h=fdf3c1e02daa86fc6f9c6cfb4c3bc20f01eea5ee;hp=3964875a3bc9904cfb2de10c29c2bdf3f3410e75;hb=5b22ae7953aac66f146f7d209b86f1e28e2d23c1;hpb=692a879d44c67bf12056fd0ba430ddae227f9be0 diff --git a/zncadmin/ZNCServer.class.php b/zncadmin/ZNCServer.class.php index 3964875..fdf3c1e 100644 --- a/zncadmin/ZNCServer.class.php +++ b/zncadmin/ZNCServer.class.php @@ -1,19 +1,19 @@ . + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ define("ERR_OK", 0); @@ -22,74 +22,74 @@ define("ERR_MODULE_NOT_FOUND", 2); define("ERR_USER_NOT_FOUND", 3); 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; - } - + 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]; + $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; - } - + $exp2 = explode('', $exp[3]); + $userdata['info'] = $exp2[0]; + $seenlist[] = $userdata; + } + return $seenlist; + } + /* $settings array elements: nick @@ -98,7 +98,7 @@ class ZNCServer { */ 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('name="_CSRF_Check" value="', $html); $exp = explode('"', $exp[1]); $csrf = $exp[0]; $post = array(); @@ -118,13 +118,13 @@ class ZNCServer { 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); - + if(!preg_match("/Invalid Submission/i", $html)) { if(!$this->addNetwork($username, $settings, $servers, $other)) { return false; @@ -133,7 +133,7 @@ class ZNCServer { } 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); @@ -152,18 +152,18 @@ class ZNCServer { $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('name="_CSRF_Check" value="', $html); $exp = explode('"', $exp[1]); $csrf = $exp[0]; $post = array(); @@ -172,7 +172,7 @@ class ZNCServer { $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) { @@ -213,7 +213,7 @@ class ZNCServer { case "checkbox": if($cfields['checked']) { $value = ($cfields['value'] ? $cfields['value'] : "1"); - } else + } else $value = null; break; default: @@ -287,7 +287,7 @@ class ZNCServer { } } } - + 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/global/webadmin/edituser?user=".$username); if(preg_match("/No such username/i", $html)) return false; @@ -318,7 +318,7 @@ class ZNCServer { $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/edituser?user=".$username, $post); return !preg_match("/Invalid Submission/i", $html); } - + public function blockZNC($username, $block) { $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/edituser?user=".$username); $handle = fopen('/home/srvx/neonserv/log.txt', 'a'); @@ -341,11 +341,11 @@ class ZNCServer { fclose($handle); 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/user/send_raw/"); if(preg_match("/Not Found/i", $html)) return ERR_MODULE_NOT_FOUND; - $exp = explode('name="_CSRF_Check" value="', $html); + $exp = explode('name="_CSRF_Check" value="', $html); $exp = explode('"', $exp[1]); $csrf = $exp[0]; $post = array(); @@ -357,16 +357,17 @@ class ZNCServer { $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/user/send_raw/", $post); return ERR_OK; } - + public function addChan($username, $channel, $key = NULL, $buffer = NULL) { - $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/addchan?user=".$username); + $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/addchan?user=".$username.'&network=default'); if(preg_match("/No such username/i", $html)) return false; - $exp = explode('name="_CSRF_Check" value="', $html); + $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['user'] = $username; $post['name'] = $channel; $exp = explode('name="key" value="', $html); @@ -377,10 +378,12 @@ class ZNCServer { $exp = explode('"', $exp[1]); $default_buffer = $exp[0]; $post['buffercount'] = ($buffer ? $buffer : $default_buffer); + $post['defmodes'] = ''; $post['save'] = 'true'; + $post['autoclearchanbuffer'] = 'true'; $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/addchan?user=".$username, $post); } - + } ?> \ No newline at end of file