+bind znc_whois NeonServ.extscript php scripts/zncadmin.php search $1 $2- %1+
+bind znc_seen NeonServ.extscript php scripts/zncadmin.php seen $1 $2 %1+
+bind znc_simul NeonServ.extscript php scripts/zncadmin.php simul $1 $2 $3- %1+
+ +bind znc_block NeonServ.extscript php scripts/zncadmin.php block $1 $2 %1+
+ +bind znc_unblock NeonServ.extscript php scripts/zncadmin.php unblock $1 $2 %1+
+bind znc_stats NeonServ.extscript php scripts/zncadmin.php stats $1 %1+
You may also bind the "admin commands" (override the protected option)
+bind znc_admin_del NeonServ.extscript php scripts/zncadmin.php force del $1 $2 %1+
+bind znc_admin_resetpass NeonServ.extscript php scripts/zncadmin.php force resetpass $1 $2 %1+
+bind znc_admin_simul NeonServ.extscript php scripts/zncadmin.php force simul $1 $2 $3- %1+
+ +bind znc_admin_block NeonServ.extscript php scripts/zncadmin.php force block $1 $2 %1+
+ +bind znc_admin_unblock NeonServ.extscript php scripts/zncadmin.php force unblock $1 $2 %1+
4) DO NOT FORGET TO SET THE PERMISSIONS!
External Scripts do not have own permission requirements. You need to set them manually using +modcmd
case "simul":
zncadmin_simul();
break;
+ case "block":
+ zncadmin_block();
+ break;
+ case "unblock":
+ zncadmin_unblock();
+ break;
case "stats":
zncadmin_stats();
break;
error("Access denied\n");
} else {
$deluser = $delusers[0];
- $deluser['server']['conn']->simulZNC($deluser['user']['user'], $raw);
- echo "Simuled \002".$deluser['user']['user']."\002 on Server ".$deluser['server']['name'].": ".$raw."\n";
- echo"/log\n";
+ $ret = $deluser['server']['conn']->simulZNC($deluser['user']['user'], $raw);
+ if($ret == ERR_MODULE_NOT_FOUND) {
+ error("send_raw module is not installed or not activated for user ".$deluser['server']['auser']." on ".$deluser['server']['name']);
+ } else {
+ echo "Simuled \002".$deluser['user']['user']."\002 on Server ".$deluser['server']['name'].": ".$raw."\n";
+ echo"/log\n";
+ }
+ }
+}
+
+//SUBCOMMAND: block
+function zncadmin_block() {
+ global $argv, $zncservers, $force;
+ $username = strtolower($argv[2]);
+ $server = strtolower($argv[3]);
+ if(!$username) {
+ error("missing username");
+ return;
+ }
+ $delusers = array();
+ foreach($zncservers as $zncserver) {
+ if($server && (strtolower($server) != strtolower($zncserver['name']))) continue;
+ if($username == strtolower($zncserver['auser'])) continue;
+ $zncserver['conn'] = new ZNCServer($zncserver['host'], $zncserver['port']);
+ $zncserver['conn']->login($zncserver['auser'], $zncserver['apass']);
+ foreach($zncserver['conn']->getUserList() as $user) {
+ if(strtolower($user['user']) == $username) {
+ $delusers[] = array("server" => $zncserver, "user" => $user);
+ }
+ }
+ }
+ if(count($delusers) > 1) {
+ error($argv[2]." exists on multiple servers! please add the server name the user should be blocked on.");
+ echo"Found User on following Servers:\n";
+ foreach($delusers as $server) {
+ echo "\002".$server['server']['name']."\002 Server: ".$server['user']['server']." Nick: ".$server['user']['nick']." Clients: ".$server['user']['clients']."\n";
+ }
+ } else if(count($delusers) == 0) {
+ error("Couldn't find an user called \002".$argv[2]."\002.");
+ } else if($delusers[0]['server']['protected'] && !$force) {
+ error("Access denied\n");
+ } else {
+ $deluser = $delusers[0];
+ $ret = $deluser['server']['conn']->blockZNC($deluser['user']['user'], true);
+ if($ret == ERR_MODULE_NOT_FOUND) {
+ error("blockuser module is not installed or not activated on ".$deluser['server']['name']);
+ } else {
+ echo "Blocked \002".$deluser['user']['user']."\002 on Server ".$deluser['server']['name'].".\n";
+ echo"/log\n";
+ }
+ }
+}
+
+//SUBCOMMAND: unblock
+function zncadmin_unblock() {
+ global $argv, $zncservers, $force;
+ $username = strtolower($argv[2]);
+ $server = strtolower($argv[3]);
+ if(!$username) {
+ error("missing username");
+ return;
+ }
+ $delusers = array();
+ foreach($zncservers as $zncserver) {
+ if($server && (strtolower($server) != strtolower($zncserver['name']))) continue;
+ if($username == strtolower($zncserver['auser'])) continue;
+ $zncserver['conn'] = new ZNCServer($zncserver['host'], $zncserver['port']);
+ $zncserver['conn']->login($zncserver['auser'], $zncserver['apass']);
+ foreach($zncserver['conn']->getUserList() as $user) {
+ if(strtolower($user['user']) == $username) {
+ $delusers[] = array("server" => $zncserver, "user" => $user);
+ }
+ }
+ }
+ if(count($delusers) > 1) {
+ error($argv[2]." exists on multiple servers! please add the server name the user should be unblocked on.");
+ echo"Found User on following Servers:\n";
+ foreach($delusers as $server) {
+ echo "\002".$server['server']['name']."\002 Server: ".$server['user']['server']." Nick: ".$server['user']['nick']." Clients: ".$server['user']['clients']."\n";
+ }
+ } else if(count($delusers) == 0) {
+ error("Couldn't find an user called \002".$argv[2]."\002.");
+ } else if($delusers[0]['server']['protected'] && !$force) {
+ error("Access denied\n");
+ } else {
+ $deluser = $delusers[0];
+ $ret = $deluser['server']['conn']->blockZNC($deluser['user']['user'], false);
+ if($ret == ERR_MODULE_NOT_FOUND) {
+ error("blockuser module is not installed or not activated on ".$deluser['server']['name']);
+ } else {
+ echo "Unblocked \002".$deluser['user']['user']."\002 on Server ".$deluser['server']['name'].".\n";
+ echo"/log\n";
+ }
}
}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+define("ERR_OK", 0);
+define("ERR_UNKNOWN", 1);
+define("ERR_MODULE_NOT_FOUND", 2);
+define("ERR_USER_NOT_FOUND", 3);
+
class ZNCServer {
private $host, $port;
private $connector;
$this->connector->post("http://".$this->host.":".$this->port."/mods/webadmin/deluser", $post);
}
- 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/webadmin/edituser?user=".$username);
- if(preg_match("/No such username/i", $html)) return false;
- $post = array();
- $post['loadmod'] = array();
+ private function parseHTMLFields($html, &$post) {
preg_match_all("<input ([^\>]*)>", $html, $matches);
foreach($matches[0] as $input) {
$fields = array(0 => "");
$content = $content[0];
$post[$name] = $content;
}
+ }
+
+ 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/webadmin/edituser?user=".$username);
+ if(preg_match("/No such username/i", $html)) return false;
+ $post = array();
+ $post['loadmod'] = array();
+ $this->parseHTMLFields($html, $post);
if($password) {
$post['password'] = $password;
$post['password2'] = $password;
return !preg_match("/Invalid Submission/i", $html);
}
- public function simulZNC($username, $raw, $server = true) {
+ public function blockZNC($username, $block) {
+ $html = $this->connector->get("http://".$this->host.":".$this->port."/mods/webadmin/edituser?user=".$username);
+ if(preg_match("/No such username/i", $html)) return ERR_USER_NOT_FOUND;
+ $post = array();
+ $post['loadmod'] = array();
+ $this->parseHTMLFields($html, $post);
+ if(!$post['embed_blockuser_presented']) return ERR_MODULE_NOT_FOUND;
+ if(!($post['embed_blockuser_block'] xor $block)) return ERR_OK;
+ $post['embed_blockuser_block'] = ($block ? "1" : null);
+ if(!$block) {
+ $post['doconnect'] = 1;
+ }
+ $html = $this->connector->post("http://".$this->host.":".$this->port."/mods/webadmin/edituser?user=".$username, $post);
+ 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/send_raw/");
- if(preg_match("/Not Found/i", $html)) return false;
+ if(preg_match("/Not Found/i", $html)) return ERR_MODULE_NOT_FOUND;
$exp = explode('name="_CSRF_Check" value="', $html);
$exp = explode('"', $exp[1]);
$csrf = $exp[0];
$post['send_to'] = ($server ? "server" : "client");
$post['line'] = $raw;
$this->connector->post("http://".$this->host.":".$this->port."/mods/send_raw/", $post);
+ return ERR_OK;
}
public function addChan($username, $channel, $key = NULL, $buffer = NULL) {