altnick
ident
*/
- public function addZNC($username, $password, $settings, $servers, $modules, $others) {
+ public function addZNC($username, $password, $settings, $servers, $modules, $netmodules, $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]);
$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)) {
+ if(!$this->addNetwork($username, $settings, $servers, $netmodules, $others)) {
return false;
}
return !preg_match("/Invalid Submission/i", $html);
return !preg_match("/Invalid Submission/i", $html);
}
- public function addNetwork($username, $settings, $servers, $other) {
+ public function addNetwork($username, $settings, $servers, $modules, $others) {
$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]);
$post['floodrate'] = '1.0';
$post['floodburst'] = '4';
$post['user'] = $username;
+
+ $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;
}
private function parseHTMLFields($html, &$post) {
- preg_match_all("<input ([^\>]*)>", $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']) {
+ preg_match_all("#<input (.*?)/?>#", $html, $matches);
+ foreach($matches[1] as $input) {
+ if(preg_match("#name=\"(.*?)\"#", $input, $match))
+ $name = $match[1];
+ else
+ $name = null;
+ if(preg_match("#type=\"(.*?)\"#", $input, $match))
+ $type = $match[1];
+ else
+ $type = null;
+ if(preg_match("#value=\"(.*?)\"#", $input, $match))
+ $value = $match[1];
+ else
+ $value= null;
+ switch($type) {
case "text":
case "hidden":
- $value = $cfields['value'];
break;
case "checkbox":
- if($cfields['checked']) {
- $value = ($cfields['value'] ? $cfields['value'] : "1");
+ if(preg_match("# checked=#", $input, $match)) {
+ $value = ($value ? $value : "1");
} else
$value = null;
break;
default:
$value = null;
}
- if($name && $value) {
+ if($name && $value !== null) {
if(array_key_exists($name, $post)) {
if(!is_array($post[$name])) {
$cvalue = $post[$name];
if($new_servers) {
$post['servers'] = implode("\n", $new_servers);
}
- foreach($add_modules as $name => $args) {
- $post['loadmod'][] = $name;
- if($args != "")
- $post['modargs_'.$name] = $args;
+ if($add_modules) {
+ foreach($add_modules as $name => $args) {
+ $post['loadmod'][] = $name;
+ if($args != "")
+ $post['modargs_'.$name] = $args;
+ }
}
- foreach($del_modules as $name => $args) {
- foreach($post['loadmod'] as $index => $mod) {
- if(strtolower($mod) == strtolower($name))
- unset($post['loadmod'][$index]);
+ if($del_modules) {
+ foreach($del_modules as $name => $args) {
+ foreach($post['loadmod'] as $index => $mod) {
+ if(strtolower($mod) == strtolower($name))
+ unset($post['loadmod'][$index]);
+ }
}
}
- foreach($others as $name => $value) {
- $post[$name] = $value;
+ if($others) {
+ foreach($others as $name => $value) {
+ $post[$name] = $value;
+ }
}
$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;
$this->connector->post("http://".$this->host.":".$this->port."/mods/global/webadmin/addchan?user=".$username.'&network=default', $post);
}
+ public function getUserInfo($username, $loadNetInfos = false) {
+ $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;
+ $info = array();
+ $info['loadmod'] = array();
+ $this->parseHTMLFields($html, $info);
+
+ { // parse network list
+ $info['networks'] = array();
+ $netlist = explode("<h3>Networks</h3>", $html);
+ $netlist = explode("<tbody>", $netlist[1], 2);
+ $netlist = explode("</tbody>", $netlist[1], 2);
+ $netlist = explode("</tr>", $netlist[0]);
+ foreach($netlist as $net) {
+ if(preg_match_all("#<td>(.*?)</td>#sm", $net, $matches)) {
+ $network = array();
+ $network['name'] = $matches[1][1];
+ $network['clients'] = $matches[1][2];
+ $network['server'] = $matches[1][3];
+ $network['nick'] = $matches[1][4];
+
+ if($loadNetInfos) {
+ $html2 = $this->connector->get("http://".$this->host.":".$this->port."/mods/global/webadmin/editnetwork?user=".$username."&network=".$network['name']);
+ if(!preg_match("/No such username/i", $html2)) {
+ $settings = array();
+ $settings['loadmod'] = array();
+ $this->parseHTMLFields($html2, $settings);
+ $network['settings'] = $settings;
+ }
+ }
+
+ $info['networks'][] = $network;
+ }
+ }
+ }
+
+ return $info;
+ }
+
}
?>
\ No newline at end of file