X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=zncadmin%2FZNCServer.class.php;h=21d134bcf81281fe20c78799168ec8977a87a410;hb=bba88abe71fc42f908e82907504d9097a85a2461;hp=d019be005b9925b292bb6ab19a093993e5ff6537;hpb=b35aabd3a108d88fb6c64319c42a19d0d49a7d15;p=ZNCAdmin.git diff --git a/zncadmin/ZNCServer.class.php b/zncadmin/ZNCServer.class.php index d019be0..21d134b 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,76 +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['clients'] = $exp2[0]; - $exp2 = explode('', $exp[4]); - $userdata['server'] = $exp2[0]; - $exp2 = explode('', $exp[5]); - $userdata['nick'] = $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 @@ -100,13 +98,13 @@ 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(); $post['_CSRF_Check'] = $csrf; $post['submitted'] = '1'; - $post['doconnect'] = '1'; + //$post['doconnect'] = '1'; $post['user'] = $username; $post['password'] = $password; $post['password2'] = $password; @@ -114,23 +112,58 @@ class ZNCServer { $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/global/webadmin/adduser", $post); + + 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('name="_CSRF_Check" value="', $html); $exp = explode('"', $exp[1]); $csrf = $exp[0]; $post = array(); @@ -139,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) { @@ -180,7 +213,7 @@ class ZNCServer { case "checkbox": if($cfields['checked']) { $value = ($cfields['value'] ? $cfields['value'] : "1"); - } else + } else $value = null; break; default: @@ -254,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; @@ -285,11 +318,15 @@ 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'); + fwrite($handle, "$html\r\n"); + fclose($handle); if(preg_match("/No such username/i", $html)) return ERR_USER_NOT_FOUND; $post = array(); + $post['user'] = $username; $post['loadmod'] = array(); $this->parseHTMLFields($html, $post); if(!$post['embed_blockuser_presented']) return ERR_MODULE_NOT_FOUND; @@ -298,35 +335,39 @@ class ZNCServer { if(!$block) { $post['doconnect'] = 1; } - $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/edituser?user=".$username, $post); + $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/edituser", $post); + $handle = fopen('/home/srvx/neonserv/log.txt', 'a'); + fwrite($handle, "$html\r\n"); + 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(); $post['_CSRF_Check'] = $csrf; $post['submitted'] = '1'; - $post['user'] = $username; + $post['network'] = $username.'/default'; $post['send_to'] = ($server ? "server" : "client"); $post['line'] = $raw; - $this->connector->post("http://".$this->host.":".$this->port."/mods/user/send_raw/", $post); + $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); @@ -337,10 +378,12 @@ class ZNCServer { $exp = explode('"', $exp[1]); $default_buffer = $exp[0]; $post['buffercount'] = ($buffer ? $buffer : $default_buffer); + $post['defmodes'] = ''; $post['save'] = 'true'; - $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/addchan?user=".$username, $post); + $post['autoclearchanbuffer'] = 'true'; + $this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/addchan?user=".$username.'&network=default', $post); } - + } ?> \ No newline at end of file