]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - Classes/class-rpc.php
Small README updates. Assume subdirectory and some warning about
[irc/unrealircd/unrealircd-webpanel.git] / Classes / class-rpc.php
CommitLineData
709b97f3 1<?php
26971737
VP
2/**
3 * RPC Functionality for UnrealIRCd Admin Webpanel
4 * License: GPLv3 or later
02c4da66
VP
5 * Author: ValwareIRC
6 * GitHub URI: ValwareIRC/unrealircd-webpanel
26971737
VP
7 * 2023
8 */
9
709b97f3 10if (!defined('UPATH'))
3e57758a 11 die("Access denied");
709b97f3 12
03ddd26b 13require UPATH . '/vendor/autoload.php';
709b97f3 14
03ddd26b 15use UnrealIRCd\Connection;
709b97f3
VP
16
17class RPC_List
18{
3e57758a
VP
19 static $user = [];
20 static $channel = [];
21 static $tkl = [];
22 static $spamfilter = [];
709b97f3
VP
23
24 static $opercount = 0;
25 static $services_count = 0;
26 static $most_populated_channel = NULL;
27 static $channel_pop_count = 0;
28}
29
30function rpc_pop_lists()
31{
03ddd26b 32 GLOBAL $rpc;
709b97f3
VP
33
34 /* Get the user list */
03ddd26b
BM
35 $ret = $rpc->query("user.list");
36 // TODO: error checking
709b97f3 37
03ddd26b 38 foreach($ret->list as $r)
709b97f3 39 {
03ddd26b
BM
40 RPC_List::$user[] = $r;
41 if (strpos($r->user->modes,"o") !== false && strpos($r->user->modes,"S") == false)
42 RPC_List::$opercount++;
43 elseif (strpos($r->user->modes,"S") !== false)
44 RPC_List::$services_count++;
709b97f3
VP
45 }
46
47 /* Get the channels list */
03ddd26b
BM
48 $ret = $rpc->query("channel.list");
49 foreach($ret->list as $r)
709b97f3 50 {
03ddd26b
BM
51 RPC_List::$channel[] = $r;
52 if ($r->num_users > RPC_List::$channel_pop_count)
709b97f3 53 {
03ddd26b
BM
54 RPC_List::$channel_pop_count = $r->num_users;
55 RPC_List::$most_populated_channel = $r->name;
709b97f3 56 }
709b97f3
VP
57 }
58
709b97f3 59 /* Get the tkl list */
03ddd26b
BM
60 $ret = $rpc->query("server_ban.list");
61 foreach($ret->list as $r)
62 RPC_List::$tkl[] = $r;
709b97f3 63
03ddd26b
BM
64 /* Get the spamfilter list */
65 $ret = $rpc->query("spamfilter.list");
66 foreach($ret->list as $r)
67 RPC_List::$spamfilter[] = $r;
709b97f3 68
76200e36
VP
69}
70
71
26971737
VP
72/** RPC TKL Add */
73function rpc_tkl_add($name, $type, $expiry, $reason) : bool
74{
03ddd26b
BM
75 GLOBAL $rpc;
76
77 $params = ["name" => $name, "type" => $type, "reason" => $reason, "duration_string" => $expiry];
78 $result = $rpc->query("server_ban.add", $params);
79 if ($result->error)
26971737 80 {
03ddd26b 81 $msg = "The $type could not be added: $name - ".$result->error->message . " (" . $result->error->code . ")";
26971737
VP
82 Message::Fail($msg);
83 return false;
84 }
85 return true;
86}
87
88
76200e36
VP
89/** RPC TKL Delete */
90function rpc_tkl_del($name, $type) : bool
91{
03ddd26b
BM
92 GLOBAL $rpc;
93
94 $params = ["name" => $name, "type" => $type];
95 $result = $rpc->query("server_ban.del", $params);
96 if ($result->error)
26971737 97 {
03ddd26b 98 $msg = "The $type could not be deleted: $name - ".$result->error->message . " (" . $result->error->code . ")";
26971737
VP
99 Message::Fail($msg);
100 return false;
101 }
102 return true;
103}
104
105/** RPC Spamfilter Delete
106 *
107 */
108function rpc_sf_del($name, $mtype, $targets, $action) : bool
109{
03ddd26b
BM
110 GLOBAL $rpc;
111
112 $params = ["name" => $name, "match_type" => $mtype, "spamfilter_targets" => $targets, "ban_action" => $action, "set_by" => "YoMama"];
113 $result = $rpc->query("spamfilter.del", $params);
114 if ($result->error)
26971737
VP
115 {
116 $msg = "The spamfilter entry could not be deleted: $name - ".$result['error']['message'] . " (" . $result['error']['code'] . ")";
117 Message::Fail($msg);
118 return false;
119 }
120 else
76200e36 121 {
03ddd26b
BM
122 $r = $result->tkl;
123 Message::Success("Deleted spamfilter entry: ".$r->name." [type: ".$r->match_type."] [targets: ".$r->spamfilter_targets. "] [action: ".$r->ban_action."] [reason: ".$r->reason."] [set by: ".$r->set_by."]");
76200e36
VP
124 }
125 return true;
ffd01497
VP
126}
127
128/** Convert the duration_string */
129function rpc_convert_duration_string($str)
130{
131 $tok = explode("w", $str);
132 $weeks = $tok[0];
133 $tok = explode("d", $tok[1]);
134 $days = $tok[0];
135 $tok = explode("h", $tok[1]);
136 $hours = $tok[0];
137 return "$weeks weeks, $days days and $hours hours";
138
709b97f3 139}