-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClientCommand.cpp
1559 lines (1297 loc) · 43.1 KB
/
ClientCommand.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2004-2011 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#include "Client.h"
#include "Chan.h"
#include "FileUtils.h"
#include "IRCNetwork.h"
#include "IRCSock.h"
#include "Listener.h"
#include "Server.h"
#include "User.h"
#include "znc.h"
void CClient::UserCommand(CString& sLine) {
if (!m_pUser) {
return;
}
if (sLine.empty()) {
return;
}
NETWORKMODULECALL(OnStatusCommand(sLine), m_pUser, m_pNetwork, this, return);
const CString sCommand = sLine.Token(0);
if (sCommand.Equals("HELP")) {
HelpUser();
} else if (sCommand.Equals("LISTNICKS")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
CString sChan = sLine.Token(1);
if (sChan.empty()) {
PutStatus("Usage: ListNicks <#chan>");
return;
}
CChan* pChan = m_pNetwork->FindChan(sChan);
if (!pChan) {
PutStatus("You are not on [" + sChan + "]");
return;
}
if (!pChan->IsOn()) {
PutStatus("You are not on [" + sChan + "] [trying]");
return;
}
const map<CString,CNick>& msNicks = pChan->GetNicks();
CIRCSock* pIRCSock = m_pNetwork->GetIRCSock();
const CString& sPerms = (pIRCSock) ? pIRCSock->GetPerms() : "";
if (!msNicks.size()) {
PutStatus("No nicks on [" + sChan + "]");
return;
}
CTable Table;
for (unsigned int p = 0; p < sPerms.size(); p++) {
CString sPerm;
sPerm += sPerms[p];
Table.AddColumn(sPerm);
}
Table.AddColumn("Nick");
Table.AddColumn("Ident");
Table.AddColumn("Host");
for (map<CString,CNick>::const_iterator a = msNicks.begin(); a != msNicks.end(); ++a) {
Table.AddRow();
for (unsigned int b = 0; b < sPerms.size(); b++) {
if (a->second.HasPerm(sPerms[b])) {
CString sPerm;
sPerm += sPerms[b];
Table.SetCell(sPerm, sPerm);
}
}
Table.SetCell("Nick", a->second.GetNick());
Table.SetCell("Ident", a->second.GetIdent());
Table.SetCell("Host", a->second.GetHost());
}
PutStatus(Table);
} else if (sCommand.Equals("DETACH")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
CString sChan = sLine.Token(1);
if (sChan.empty()) {
PutStatus("Usage: Detach <#chan>");
return;
}
const vector<CChan*>& vChans = m_pNetwork->GetChans();
vector<CChan*>::const_iterator it;
unsigned int uMatches = 0, uDetached = 0;
for (it = vChans.begin(); it != vChans.end(); ++it) {
if (!(*it)->GetName().WildCmp(sChan))
continue;
uMatches++;
if ((*it)->IsDetached())
continue;
uDetached++;
(*it)->DetachUser();
}
PutStatus("There were [" + CString(uMatches) + "] channels matching [" + sChan + "]");
PutStatus("Detached [" + CString(uDetached) + "] channels");
} else if (sCommand.Equals("VERSION")) {
const char *features = "IPv6: "
#ifdef HAVE_IPV6
"yes"
#else
"no"
#endif
", SSL: "
#ifdef HAVE_LIBSSL
"yes"
#else
"no"
#endif
", c-ares: "
#ifdef HAVE_C_ARES
"yes";
#else
"no";
#endif
PutStatus(CZNC::GetTag());
PutStatus(features);
} else if (sCommand.Equals("MOTD") || sCommand.Equals("ShowMOTD")) {
if (!SendMotd()) {
PutStatus("There is no MOTD set.");
}
} else if (m_pUser->IsAdmin() && sCommand.Equals("Rehash")) {
CString sRet;
if (CZNC::Get().RehashConfig(sRet)) {
PutStatus("Rehashing succeeded!");
} else {
PutStatus("Rehashing failed: " + sRet);
}
} else if (m_pUser->IsAdmin() && sCommand.Equals("SaveConfig")) {
if (CZNC::Get().WriteConfig()) {
PutStatus("Wrote config to [" + CZNC::Get().GetConfigFile() + "]");
} else {
PutStatus("Error while trying to write config.");
}
} else if (sCommand.Equals("LISTCLIENTS")) {
CUser* pUser = m_pUser;
CString sNick = sLine.Token(1);
if (!sNick.empty()) {
if (!m_pUser->IsAdmin()) {
PutStatus("Usage: ListClients");
return;
}
pUser = CZNC::Get().FindUser(sNick);
if (!pUser) {
PutStatus("No such user [" + sNick + "]");
return;
}
}
vector<CClient*> vClients = pUser->GetAllClients();
if (vClients.empty()) {
PutStatus("No clients are connected");
return;
}
CTable Table;
Table.AddColumn("Host");
Table.AddColumn("Network");
for (unsigned int a = 0; a < vClients.size(); a++) {
Table.AddRow();
Table.SetCell("Host", vClients[a]->GetRemoteIP());
if (vClients[a]->GetNetwork()) {
Table.SetCell("Network", vClients[a]->GetNetwork()->GetName());
}
}
PutStatus(Table);
} else if (m_pUser->IsAdmin() && sCommand.Equals("LISTUSERS")) {
const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();
CTable Table;
Table.AddColumn("Username");
Table.AddColumn("Networks");
Table.AddColumn("Clients");
for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); ++it) {
Table.AddRow();
Table.SetCell("Username", it->first);
Table.SetCell("Networks", CString(it->second->GetNetworks().size()));
Table.SetCell("Clients", CString(it->second->GetAllClients().size()));
}
PutStatus(Table);
} else if (m_pUser->IsAdmin() && sCommand.Equals("SetMOTD")) {
CString sMessage = sLine.Token(1, true);
if (sMessage.empty()) {
PutStatus("Usage: SetMOTD <Message>");
} else {
CZNC::Get().SetMotd(sMessage);
PutStatus("MOTD set to [" + sMessage + "]");
}
} else if (m_pUser->IsAdmin() && sCommand.Equals("AddMOTD")) {
CString sMessage = sLine.Token(1, true);
if (sMessage.empty()) {
PutStatus("Usage: AddMOTD <Message>");
} else {
CZNC::Get().AddMotd(sMessage);
PutStatus("Added [" + sMessage + "] to MOTD");
}
} else if (m_pUser->IsAdmin() && sCommand.Equals("ClearMOTD")) {
CZNC::Get().ClearMotd();
PutStatus("Cleared MOTD");
} else if (m_pUser->IsAdmin() && sCommand.Equals("BROADCAST")) {
CZNC::Get().Broadcast(sLine.Token(1, true));
} else if (m_pUser->IsAdmin() && (sCommand.Equals("SHUTDOWN") || sCommand.Equals("RESTART"))) {
bool bRestart = sCommand.Equals("RESTART");
CString sMessage = sLine.Token(1, true);
bool bForce = false;
if (sMessage.Token(0).Equals("FORCE")) {
bForce = true;
sMessage = sMessage.Token(1, true);
}
if (sMessage.empty()) {
sMessage = (bRestart ? "ZNC is being restarted NOW!" : "ZNC is being shut down NOW!");
}
if(!CZNC::Get().WriteConfig() && !bForce) {
PutStatus("ERROR: Writing config file to disk failed! Aborting. Use " +
sCommand.AsUpper() + " FORCE to ignore.");
} else {
CZNC::Get().Broadcast(sMessage);
throw CException(bRestart ? CException::EX_Restart : CException::EX_Shutdown);
}
} else if (sCommand.Equals("JUMP") || sCommand.Equals("CONNECT")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
if (!m_pNetwork->HasServers()) {
PutStatus("You don't have any servers added.");
return;
}
CString sArgs = sLine.Token(1, true);
CServer *pServer = NULL;
if (!sArgs.empty()) {
pServer = m_pNetwork->FindServer(sArgs);
if (!pServer) {
PutStatus("Server [" + sArgs + "] not found");
return;
}
m_pNetwork->SetNextServer(pServer);
// If we are already connecting to some server,
// we have to abort that attempt
Csock *pIRCSock = GetIRCSock();
if (pIRCSock && !pIRCSock->IsConnected()) {
pIRCSock->Close();
}
}
if (GetIRCSock()) {
GetIRCSock()->Quit();
if (pServer)
PutStatus("Connecting to [" + pServer->GetName() + "]...");
else
PutStatus("Jumping to the next server in the list...");
} else {
if (pServer)
PutStatus("Connecting to [" + pServer->GetName() + "]...");
else
PutStatus("Connecting...");
}
m_pUser->SetIRCConnectEnabled(true);
m_pNetwork->CheckIRCConnect();
return;
} else if (sCommand.Equals("DISCONNECT")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
if (GetIRCSock()) {
CString sQuitMsg = sLine.Token(1, true);
GetIRCSock()->Quit(sQuitMsg);
}
m_pUser->SetIRCConnectEnabled(false);
PutStatus("Disconnected from IRC. Use 'connect' to reconnect.");
return;
} else if (sCommand.Equals("ENABLECHAN")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
CString sChan = sLine.Token(1, true);
if (sChan.empty()) {
PutStatus("Usage: EnableChan <channel>");
} else {
const vector<CChan*>& vChans = m_pNetwork->GetChans();
vector<CChan*>::const_iterator it;
unsigned int uMatches = 0, uEnabled = 0;
for (it = vChans.begin(); it != vChans.end(); ++it) {
if (!(*it)->GetName().WildCmp(sChan))
continue;
uMatches++;
if (!(*it)->IsDisabled())
continue;
uEnabled++;
(*it)->Enable();
}
PutStatus("There were [" + CString(uMatches) + "] channels matching [" + sChan + "]");
PutStatus("Enabled [" + CString(uEnabled) + "] channels");
}
} else if (sCommand.Equals("LISTCHANS")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
CUser* pUser = m_pUser;
CIRCNetwork* pNetwork = m_pNetwork;
const CString sNick = sLine.Token(1);
const CString sNetwork = sLine.Token(2);
if (!sNick.empty()) {
if (!m_pUser->IsAdmin()) {
PutStatus("Usage: ListChans");
return;
}
pUser = CZNC::Get().FindUser(sNick);
if (!pUser) {
PutStatus("No such user [" + sNick + "]");
return;
}
pNetwork = pUser->FindNetwork(sNetwork);
if (!pNetwork) {
PutStatus("No such network for user [" + sNetwork + "]");
return;
}
}
const vector<CChan*>& vChans = pNetwork->GetChans();
CIRCSock* pIRCSock = pNetwork->GetIRCSock();
const CString& sPerms = (pIRCSock) ? pIRCSock->GetPerms() : "";
if (!vChans.size()) {
PutStatus("There are no channels defined.");
return;
}
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Status");
Table.AddColumn("Conf");
Table.AddColumn("Buf");
Table.AddColumn("Modes");
Table.AddColumn("Users");
for (unsigned int p = 0; p < sPerms.size(); p++) {
CString sPerm;
sPerm += sPerms[p];
Table.AddColumn(sPerm);
}
unsigned int uNumDetached = 0, uNumDisabled = 0,
uNumJoined = 0;
for (unsigned int a = 0; a < vChans.size(); a++) {
const CChan* pChan = vChans[a];
Table.AddRow();
Table.SetCell("Name", pChan->GetPermStr() + pChan->GetName());
Table.SetCell("Status", ((vChans[a]->IsOn()) ? ((vChans[a]->IsDetached()) ? "Detached" : "Joined") : ((vChans[a]->IsDisabled()) ? "Disabled" : "Trying")));
Table.SetCell("Conf", CString((pChan->InConfig()) ? "yes" : ""));
Table.SetCell("Buf", CString((pChan->KeepBuffer()) ? "*" : "") + CString(pChan->GetBufferCount()));
Table.SetCell("Modes", pChan->GetModeString());
Table.SetCell("Users", CString(pChan->GetNickCount()));
map<char, unsigned int> mPerms = pChan->GetPermCounts();
for (unsigned int b = 0; b < sPerms.size(); b++) {
char cPerm = sPerms[b];
Table.SetCell(CString(cPerm), CString(mPerms[cPerm]));
}
if(pChan->IsDetached()) uNumDetached++;
if(pChan->IsOn()) uNumJoined++;
if(pChan->IsDisabled()) uNumDisabled++;
}
PutStatus(Table);
PutStatus("Total: " + CString(vChans.size()) + " - Joined: " + CString(uNumJoined) +
" - Detached: " + CString(uNumDetached) + " - Disabled: " + CString(uNumDisabled));
} else if (sCommand.Equals("ADDNETWORK")) {
CString sNetwork = sLine.Token(1);
if (sNetwork.empty()) {
PutStatus("Usage: AddNetwork <name>");
return;
}
if (m_pUser->AddNetwork(sNetwork)) {
PutStatus("Network added");
} else {
PutStatus("Unable to add that network");
PutStatus("Perhaps that network is already added");
}
} else if (sCommand.Equals("DELNETWORK")) {
CString sNetwork = sLine.Token(1);
if (sNetwork.empty()) {
PutStatus("Usage: DelNetwork <name>");
return;
}
if (m_pNetwork && m_pNetwork->GetName().Equals(sNetwork)) {
SetNetwork(NULL);
}
if (m_pUser->DeleteNetwork(sNetwork)) {
PutStatus("Network deleted");
} else {
PutStatus("Failed to delete network");
PutStatus("Perhaps this network doesn't exist");
}
} else if (sCommand.Equals("LISTNETWORKS")) {
CUser *pUser = m_pUser;
if (m_pUser->IsAdmin() && !sLine.Token(1).empty()) {
pUser = CZNC::Get().FindUser(sLine.Token(1));
if (!pUser) {
PutStatus("User not found " + sLine.Token(1));
return;
}
}
const vector<CIRCNetwork*>& vNetworks = pUser->GetNetworks();
CTable Table;
Table.AddColumn("Network");
Table.AddColumn("OnIRC");
Table.AddColumn("IRC Server");
Table.AddColumn("IRC User");
Table.AddColumn("Channels");
for (unsigned int a = 0; a < vNetworks.size(); a++) {
CIRCNetwork* pNetwork = vNetworks[a];
Table.AddRow();
Table.SetCell("Network", pNetwork->GetName());
if (pNetwork->IsIRCConnected()) {
Table.SetCell("OnIRC", "Yes");
Table.SetCell("IRC Server", pNetwork->GetIRCServer());
Table.SetCell("IRC User", pNetwork->GetIRCNick().GetNickMask());
Table.SetCell("Channels", CString(pNetwork->GetChans().size()));
} else {
Table.SetCell("OnIRC", "No");
}
}
if (PutStatus(Table) == 0) {
PutStatus("No networks");
}
} else if (sCommand.Equals("JUMPNETWORK")) {
CString sNetwork = sLine.Token(1);
if (sNetwork.empty()) {
PutStatus("No network supplied.");
return;
}
if (m_pNetwork && (m_pNetwork->GetName() == sNetwork)) {
PutStatus("You are already connected with this network.");
return;
}
CIRCNetwork *pNetwork = m_pUser->FindNetwork(sNetwork);
if (pNetwork) {
SetNetwork(pNetwork);
PutStatus("Switched to " + sNetwork);
} else {
PutStatus("You don't have a network named " + sNetwork);
}
} else if (sCommand.Equals("ADDSERVER")) {
CString sServer = sLine.Token(1);
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
if (sServer.empty()) {
PutStatus("Usage: AddServer <host> [[+]port] [pass]");
return;
}
if (m_pNetwork->AddServer(sLine.Token(1, true))) {
PutStatus("Server added");
} else {
PutStatus("Unable to add that server");
PutStatus("Perhaps the server is already added or openssl is disabled?");
}
} else if (sCommand.Equals("REMSERVER") || sCommand.Equals("DELSERVER")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
CString sServer = sLine.Token(1);
unsigned short uPort = sLine.Token(2).ToUShort();
CString sPass = sLine.Token(3);
if (sServer.empty()) {
PutStatus("Usage: RemServer <host> [port] [pass]");
return;
}
if (!m_pNetwork->HasServers()) {
PutStatus("You don't have any servers added.");
return;
}
if (m_pNetwork->DelServer(sServer, uPort, sPass)) {
PutStatus("Server removed");
} else {
PutStatus("No such server");
}
} else if (sCommand.Equals("LISTSERVERS")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
if (m_pNetwork->HasServers()) {
const vector<CServer*>& vServers = m_pNetwork->GetServers();
CServer* pCurServ = m_pNetwork->GetCurrentServer();
CTable Table;
Table.AddColumn("Host");
Table.AddColumn("Port");
Table.AddColumn("SSL");
Table.AddColumn("Pass");
for (unsigned int a = 0; a < vServers.size(); a++) {
CServer* pServer = vServers[a];
Table.AddRow();
Table.SetCell("Host", pServer->GetName() + (pServer == pCurServ ? "*" : ""));
Table.SetCell("Port", CString(pServer->GetPort()));
Table.SetCell("SSL", (pServer->IsSSL()) ? "SSL" : "");
Table.SetCell("Pass", pServer->GetPass());
}
PutStatus(Table);
} else {
PutStatus("You don't have any servers added.");
}
} else if (sCommand.Equals("TOPICS")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
const vector<CChan*>& vChans = m_pNetwork->GetChans();
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Set By");
Table.AddColumn("Topic");
for (unsigned int a = 0; a < vChans.size(); a++) {
CChan* pChan = vChans[a];
Table.AddRow();
Table.SetCell("Name", pChan->GetName());
Table.SetCell("Set By", pChan->GetTopicOwner());
Table.SetCell("Topic", pChan->GetTopic());
}
PutStatus(Table);
} else if (sCommand.Equals("LISTMODS") || sCommand.Equals("LISTMODULES")) {
if (m_pUser->IsAdmin()) {
CModules& GModules = CZNC::Get().GetModules();
if (!GModules.size()) {
PutStatus("No global modules loaded.");
} else {
PutStatus("Global modules:");
CTable GTable;
GTable.AddColumn("Name");
GTable.AddColumn("Arguments");
for (unsigned int b = 0; b < GModules.size(); b++) {
GTable.AddRow();
GTable.SetCell("Name", GModules[b]->GetModName());
GTable.SetCell("Arguments", GModules[b]->GetArgs());
}
PutStatus(GTable);
}
}
CModules& Modules = m_pUser->GetModules();
if (!Modules.size()) {
PutStatus("Your user has no modules loaded.");
} else {
PutStatus("User modules:");
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Arguments");
for (unsigned int b = 0; b < Modules.size(); b++) {
Table.AddRow();
Table.SetCell("Name", Modules[b]->GetModName());
Table.SetCell("Arguments", Modules[b]->GetArgs());
}
PutStatus(Table);
}
if (m_pNetwork) {
CModules& NetworkModules = m_pNetwork->GetModules();
if (NetworkModules.empty()) {
PutStatus("This network has no modules loaded.");
} else {
PutStatus("Network modules:");
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Arguments");
for (unsigned int b = 0; b < NetworkModules.size(); b++) {
Table.AddRow();
Table.SetCell("Name", NetworkModules[b]->GetModName());
Table.SetCell("Arguments", NetworkModules[b]->GetArgs());
}
PutStatus(Table);
}
}
return;
} else if (sCommand.Equals("LISTAVAILMODS") || sCommand.Equals("LISTAVAILABLEMODULES")) {
if (m_pUser->DenyLoadMod()) {
PutStatus("Access Denied.");
return;
}
if (m_pUser->IsAdmin()) {
set<CModInfo> ssGlobalMods;
CZNC::Get().GetModules().GetAvailableMods(ssGlobalMods, CModInfo::GlobalModule);
if (ssGlobalMods.empty()) {
PutStatus("No global modules available.");
} else {
PutStatus("Global modules:");
CTable GTable;
GTable.AddColumn("Name");
GTable.AddColumn("Description");
set<CModInfo>::iterator it;
for (it = ssGlobalMods.begin(); it != ssGlobalMods.end(); ++it) {
const CModInfo& Info = *it;
GTable.AddRow();
GTable.SetCell("Name", (CZNC::Get().GetModules().FindModule(Info.GetName()) ? "*" : " ") + Info.GetName());
GTable.SetCell("Description", Info.GetDescription().Ellipsize(128));
}
PutStatus(GTable);
}
}
set<CModInfo> ssUserMods;
CZNC::Get().GetModules().GetAvailableMods(ssUserMods);
if (!ssUserMods.size()) {
PutStatus("No user modules available.");
} else {
PutStatus("User modules:");
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Description");
set<CModInfo>::iterator it;
for (it = ssUserMods.begin(); it != ssUserMods.end(); ++it) {
const CModInfo& Info = *it;
Table.AddRow();
Table.SetCell("Name", (m_pUser->GetModules().FindModule(Info.GetName()) ? "*" : " ") + Info.GetName());
Table.SetCell("Description", Info.GetDescription().Ellipsize(128));
}
PutStatus(Table);
}
set<CModInfo> ssNetworkMods;
CZNC::Get().GetModules().GetAvailableMods(ssNetworkMods, CModInfo::NetworkModule);
if (!ssNetworkMods.size()) {
PutStatus("No network modules available.");
} else {
PutStatus("Network modules:");
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Description");
set<CModInfo>::const_iterator it;
for (it = ssNetworkMods.begin(); it != ssNetworkMods.end(); ++it) {
const CModInfo& Info = *it;
Table.AddRow();
Table.SetCell("Name", ((m_pNetwork && m_pNetwork->GetModules().FindModule(Info.GetName())) ? "*" : " ") + Info.GetName());
Table.SetCell("Description", Info.GetDescription().Ellipsize(128));
}
PutStatus(Table);
}
return;
} else if (sCommand.Equals("LOADMOD") || sCommand.Equals("LOADMODULE")) {
CModInfo::EModuleType eType;
CString sType = sLine.Token(1);
CString sMod = sLine.Token(2);
CString sArgs = sLine.Token(3, true);
if (sType.Equals("global")) {
eType = CModInfo::GlobalModule;
} else if (sType.Equals("user")) {
eType = CModInfo::UserModule;
} else if (sType.Equals("network")) {
eType = CModInfo::NetworkModule;
} else {
sMod = sType;
sArgs = sLine.Token(2, true);
sType = "default";
// Will be set correctly later
eType = CModInfo::UserModule;
}
if (m_pUser->DenyLoadMod()) {
PutStatus("Unable to load [" + sMod + "]: Access Denied.");
return;
}
if (sMod.empty()) {
PutStatus("Usage: LoadMod [type] <module> [args]");
return;
}
CModInfo ModInfo;
CString sRetMsg;
if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sMod, sRetMsg)) {
PutStatus("Unable to find modinfo [" + sMod + "] [" + sRetMsg + "]");
return;
}
if (sType.Equals("default")) {
eType = ModInfo.GetDefaultType();
}
if (eType == CModInfo::GlobalModule && !m_pUser->IsAdmin()) {
PutStatus("Unable to load global module [" + sMod + "]: Access Denied.");
return;
}
if (eType == CModInfo::NetworkModule && !m_pNetwork) {
PutStatus("Unable to load network module [" + sMod + "] Not connected with a network.");
return;
}
CString sModRet;
bool b = false;
switch (eType) {
case CModInfo::GlobalModule:
b = CZNC::Get().GetModules().LoadModule(sMod, sArgs, eType, NULL, NULL, sModRet);
break;
case CModInfo::UserModule:
b = m_pUser->GetModules().LoadModule(sMod, sArgs, eType, m_pUser, NULL, sModRet);
break;
case CModInfo::NetworkModule:
b = m_pNetwork->GetModules().LoadModule(sMod, sArgs, eType, m_pUser, m_pNetwork, sModRet);
break;
default:
sModRet = "Unable to load module [" + sMod + "]: Unknown module type";
}
if (b)
sModRet = "Loaded module [" + sMod + "] " + sModRet;
PutStatus(sModRet);
return;
} else if (sCommand.Equals("UNLOADMOD") || sCommand.Equals("UNLOADMODULE")) {
CModInfo::EModuleType eType = CModInfo::UserModule;
CString sType = sLine.Token(1);
CString sMod = sLine.Token(2);
if (sType.Equals("global")) {
eType = CModInfo::GlobalModule;
} else if (sType.Equals("user")) {
eType = CModInfo::UserModule;
} else if (sType.Equals("network")) {
eType = CModInfo::NetworkModule;
} else {
sMod = sType;
sType = "default";
}
if (m_pUser->DenyLoadMod()) {
PutStatus("Unable to unload [" + sMod + "] Access Denied.");
return;
}
if (sMod.empty()) {
PutStatus("Usage: UnloadMod [type] <module>");
return;
}
CModInfo ModInfo;
CString sRetMsg;
if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sMod, sRetMsg)) {
PutStatus("Unable to find modinfo [" + sMod + "] [" + sRetMsg + "]");
return;
}
if (sType.Equals("default")) {
eType = ModInfo.GetDefaultType();
}
if (eType == CModInfo::GlobalModule && !m_pUser->IsAdmin()) {
PutStatus("Unable to unload global module [" + sMod + "]: Access Denied.");
return;
}
if (eType == CModInfo::NetworkModule && !m_pNetwork) {
PutStatus("Unable to unload network module [" + sMod + "] Not connected with a network.");
return;
}
CString sModRet;
switch (eType) {
case CModInfo::GlobalModule:
CZNC::Get().GetModules().UnloadModule(sMod, sModRet);
break;
case CModInfo::UserModule:
m_pUser->GetModules().UnloadModule(sMod, sModRet);
break;
case CModInfo::NetworkModule:
m_pNetwork->GetModules().UnloadModule(sMod, sModRet);
break;
default:
sModRet = "Unable to unload module [" + sMod + "]: Unknown module type";
}
PutStatus(sModRet);
return;
} else if (sCommand.Equals("RELOADMOD") || sCommand.Equals("RELOADMODULE")) {
CModInfo::EModuleType eType;
CString sType = sLine.Token(1);
CString sMod = sLine.Token(2);
CString sArgs = sLine.Token(3, true);
if (m_pUser->DenyLoadMod()) {
PutStatus("Unable to reload modules. Access Denied.");
return;
}
if (sType.Equals("global")) {
eType = CModInfo::GlobalModule;
} else if (sType.Equals("user")) {
eType = CModInfo::UserModule;
} else if (sType.Equals("network")) {
eType = CModInfo::NetworkModule;
} else {
sMod = sType;
sArgs = sLine.Token(2, true);
sType = "default";
// Will be set correctly later
eType = CModInfo::UserModule;
}
if (sMod.empty()) {
PutStatus("Usage: ReloadMod [type] <module> [args]");
return;
}
CModInfo ModInfo;
CString sRetMsg;
if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sMod, sRetMsg)) {
PutStatus("Unable to find modinfo for [" + sMod + "] [" + sRetMsg + "]");
return;
}
if (sType.Equals("default")) {
eType = ModInfo.GetDefaultType();
}
if (eType == CModInfo::GlobalModule && !m_pUser->IsAdmin()) {
PutStatus("Unable to reload global module [" + sMod + "]: Access Denied.");
return;
}
if (eType == CModInfo::NetworkModule && !m_pNetwork) {
PutStatus("Unable to load network module [" + sMod + "] Not connected with a network.");
return;
}
CString sModRet;
switch (eType) {
case CModInfo::GlobalModule:
CZNC::Get().GetModules().ReloadModule(sMod, sArgs, NULL, NULL, sModRet);
break;
case CModInfo::UserModule:
m_pUser->GetModules().ReloadModule(sMod, sArgs, m_pUser, NULL, sModRet);
break;
case CModInfo::NetworkModule:
m_pNetwork->GetModules().ReloadModule(sMod, sArgs, m_pUser, m_pNetwork, sModRet);
break;
default:
sModRet = "Unable to reload module [" + sMod + "]: Unknown module type";
}
PutStatus(sModRet);
return;
} else if ((sCommand.Equals("UPDATEMOD") || sCommand.Equals("UPDATEMODULE")) && m_pUser->IsAdmin() ) {
CString sMod = sLine.Token(1);
if (sMod.empty()) {
PutStatus("Usage: UpdateMod <module>");
return;
}
if (m_pUser->DenyLoadMod() || !m_pUser->IsAdmin()) {
PutStatus("Unable to reload [" + sMod + "] Access Denied.");
return;
}
PutStatus("Reloading [" + sMod + "] on all users...");
if (CUser::UpdateModule(sMod)) {
PutStatus("Done");
} else {
PutStatus("Done, but there were errors, some users no longer have ["
+ sMod + "] loaded");
}
} else if ((sCommand.Equals("ADDBINDHOST") || sCommand.Equals("ADDVHOST")) && m_pUser->IsAdmin()) {
CString sHost = sLine.Token(1);
if (sHost.empty()) {
PutStatus("Usage: AddBindHost <host>");
return;
}
if (CZNC::Get().AddBindHost(sHost)) {
PutStatus("Done");
} else {
PutStatus("The host [" + sHost + "] is already in the list");
}
} else if ((sCommand.Equals("REMBINDHOST") || sCommand.Equals("REMVHOST") || sCommand.Equals("DELVHOST")) && m_pUser->IsAdmin()) {
CString sHost = sLine.Token(1);
if (sHost.empty()) {
PutStatus("Usage: RemBindHost <host>");
return;
}
if (CZNC::Get().RemBindHost(sHost)) {
PutStatus("Done");