]>
Commit | Line | Data |
---|---|---|
562c96c0 BM |
1 | UnrealIRCd RPC |
2 | ============== | |
3 | ||
4 | This allows PHP scripts to control [UnrealIRCd](https://www.unrealircd.org/) | |
5 | via the [JSON-RPC interface](https://www.unrealircd.org/docs/JSON-RPC). | |
6 | ||
13d5df3b BM |
7 | This library is used by the |
8 | [UnrealIRCd webpanel](https://github.com/unrealircd/unrealircd-webpanel/). | |
f228c2d5 | 9 | |
66eda38d | 10 | If you are interested in helping out or would like to discuss API |
13d5df3b | 11 | capabilities, join us at `#unreal-webpanel` at `irc.unrealircd.org` |
66eda38d BM |
12 | (IRC with TLS on port 6697). |
13 | ||
562c96c0 BM |
14 | Installation |
15 | ------------ | |
16 | ```bash | |
27d8a778 | 17 | composer require unrealircd/unrealircd-rpc:dev-main |
562c96c0 BM |
18 | ``` |
19 | ||
66eda38d BM |
20 | UnrealIRCd setup |
21 | ----------------- | |
13d5df3b BM |
22 | UnrealIRCd 6.0.6 or later is needed and you need to enable |
23 | [JSON-RPC](https://www.unrealircd.org/docs/JSON-RPC) in it. | |
f228c2d5 | 24 | After doing that, be sure to rehash the IRCd. |
66eda38d | 25 | |
562c96c0 BM |
26 | Usage |
27 | ----- | |
e3d9bcad | 28 | For this example, create a file like `src/rpctest.php` with: |
562c96c0 BM |
29 | ```php |
30 | <?php | |
31 | require dirname(__DIR__) . '/vendor/autoload.php'; | |
32 | ||
66eda38d | 33 | use UnrealIRCd\Connection; |
562c96c0 | 34 | |
66eda38d | 35 | $api_login = 'api:apiPASSWORD'; // same as in the rpc-user block in UnrealIRCd |
562c96c0 | 36 | |
c2f6f705 | 37 | $rpc = new UnrealIRCd\Connection("wss://127.0.0.1:8600/", |
562c96c0 BM |
38 | $api_login, |
39 | Array("tls_verify"=>FALSE)); | |
40 | ||
66eda38d | 41 | $bans = $rpc->serverban()->getAll(); |
93f8a3ee | 42 | foreach ($bans as $ban) |
66eda38d BM |
43 | echo "There's a $ban->type on $ban->name\n"; |
44 | ||
45 | $users = $rpc->user()->getAll(); | |
93f8a3ee | 46 | foreach ($users as $user) |
66eda38d BM |
47 | echo "User $user->name\n"; |
48 | ||
49 | $channels = $rpc->channel()->getAll(); | |
93f8a3ee | 50 | foreach ($channels as $channel) |
66eda38d | 51 | echo "Channel $channel->name ($channel->num_users user[s])\n"; |
562c96c0 | 52 | ``` |
1ba139aa | 53 | Then, run it on the command line with `php src/rpctest.php` |
e3d9bcad | 54 | |
66eda38d BM |
55 | If the example does not work, then make sure you have configured your |
56 | UnrealIRCd correctly, with the same API username and password you use | |
1ba139aa | 57 | here, with an allowed IP, and changing the `wss://127.0.0.1:8600/` too |
66eda38d | 58 | if needed. |