This file is indexed.

/usr/share/sbnc/scripts/virtual.tcl is in sbnc-tcl 1.3.9-3ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
# shroudBNC - an object-oriented framework for IRC
# Copyright (C) 2005-2014 Gunnar Beutner
# Copyright (C) 2010 Christoph Wiese
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

internalbind command virtual:commandiface

proc virtual:commandiface {client parameters} {
	if {![virtual:isadmin $client] && ![getbncuser $client admin]} { return }

	set command [lindex $parameters 0]

	if {[getbncuser $client admin]} {
		if {[string equal -nocase $command "addgroup"]} { virtual:cmd:addgroup $client $parameters }
		if {[string equal -nocase $command "delgroup"]} { virtual:cmd:delgroup $client $parameters }
		if {[string equal -nocase $command "vadmin"]} { virtual:cmd:vadmin $client $parameters }
		if {[string equal -nocase $command "vunadmin"]} { virtual:cmd:vunadmin $client $parameters }
		if {[string equal -nocase $command "getlimit"]} { virtual:cmd:getlimit $client $parameters }
		if {[string equal -nocase $command "setlimit"]} { virtual:cmd:setlimit $client $parameters }
		if {[string equal -nocase $command "groups"]} { virtual:cmd:groups $client $parameters }
		if {[string equal -nocase $command "globalset"]} { virtual:cmd:globalset $client $parameters }
	}

	if {[string equal -nocase $command "who"]} { virtual:cmd:who $client $parameters }
	if {[string equal -nocase $command "resetpass"]} { virtual:cmd:resetpass $client $parameters }
	if {[string equal -nocase $command "deluser"]} { virtual:cmd:deluser $client $parameters }
	if {[string equal -nocase $command "adduser"]} { virtual:cmd:adduser $client $parameters }

	if {[string equal -nocase $command "help"]} {
		if {[getbncuser $client admin]} {
			bncaddcommand "addgroup" "VAdmin" "creates a new group"
			bncaddcommand "delgroup" "VAdmin" "deletes a group and all its users"
			bncaddcommand "vadmin" "VAdmin" "gives a user virtual admin privileges"
			bncaddcommand "vunadmin" "VAdmin" "removes a user's virtual admin privileges"
			bncaddcommand "getlimit" "VAdmin" "gets a group's limit"
			bncaddcommand "setlimit" "VAdmin" "sets a group's limit"
			bncaddcommand "groups" "VAdmin" "lists all groups"

			set help "Syntax: who \[group\]\n"
			append help "Shows a list of all users (in a specific group).\n"
			append help "Flags (which are displayed in front of the username):\n"
			append help "@ user is an admin\n"
			append help "* user is currently logged in\n"
			append help "! user is suspended\n"
			append help "\$ user is a virtual admin"
			bncaddcommand "who" "Admin" "shows users" $help
		} else {
			bncaddcommand "adduser" "Admin" "creates a new user" "Syntax: adduser <username> <password> \[<group>\]\nCreates a new user."
			bncaddcommand "deluser" "Admin" "removes a user" "Syntax: deluser <username>\nDeletes a user."

			bncaddcommand "resetpass" "Admin" "sets a user's password" "Syntax: resetpass <user> <password>\nResets another user's password."

			set help "Syntax: who\n"
			append help "Shows a list of all users.\n"
			append help "Flags (which are displayed in front of the username):\n"
			append help "@ user is an admin\n"
			append help "\$ user is a virtual admin"
			append help "* user is currently logged in\n"
			append help "! user is suspended\n"
			bncaddcommand "who" "Admin" "shows users" $help
		}
	}
}

proc virtual:isadmin {account} {
	if {[getbncuser $account tag reseller] == "1"} {
		return 1
	} else {
		return 0
	}
}

proc virtual:setadmin {group account {value 1}} {
	setbncuser $account tag group $group
	setbncuser $account tag reseller $value
}

proc virtual:getadmin {group} {
	foreach user [bncuserlist] {
		if {[virtual:isadmin $user] && [string equal -nocase [virtual:getgroup $user] $group] && [getbncuser $user tag maxbncs] != ""} {
			return $user
		}
	}

	return ""
}

proc virtual:setgroup {account group} {
	setbncuser $account tag group $group
}

proc virtual:getgroup {account} {
	variable result

	set error [catch [list getbncuser $account tag group] result]

	if {$error} { return "" }

	return $result
}

proc virtual:setmaxbncs {group maxbncs} {
	set account [virtual:getadmin $group]

	if {$account == ""} { return 0 }

	setbncuser $account tag maxbncs $maxbncs

	return 1
}

proc virtual:getmaxbncs {group} {
	set account [virtual:getadmin $group]

	if {$account == ""} { return 0 }

	return [getbncuser $account tag maxbncs]
}

proc virtual:cmd:who {account parameters} {
	set accts [getctx 1]

	if {[getbncuser $account admin]} {
		set group [lindex $parameters 1]
	} else {
		set group [virtual:getgroup $account]
	}

	foreach user [lsort [bncuserlist]] {
		if {[string equal -nocase [virtual:getgroup $user] $group] || $group == ""} {
			set out ""

			setctx $user

			if {[getbncuser $user admin]} {
				append out "@"
			}

			if {[virtual:isadmin $user]} {
				if {[getbncuser $account admin]} {
					append out "\$"
				} elseif {![getbncuser $user admin]} {
					append out "@"
				}
			}

			if {[getbncuser $user hasclient]} {
				append out "*"
			}

			if {[getbncuser $user lock]} {
				append out "!"
			}

			append out $user
			append out "([getcurrentnick])@[getbncuser $user client] \[[getbncuser $user realserver]\]"

			append out " \[Last seen: "

			if {[getbncuser $user hasclient]} {
				append out "Now"
			} elseif {[getbncuser $user seen] == 0} {
				append out "Never"
			} else {
				append out [strftime "%c" [getbncuser $user seen]]
			}

			append out "\]"

			if {[getbncuser $account admin] && $group == ""} {
				set grp [virtual:getgroup $user]
				if {$grp == ""} { set grp "<none>" }
				append out " $grp"
			}

			append out " :[getbncuser $user realname]"

			setctx $accts
			bncreply $out
		}
	}

	bncreply "End of USERS."

	haltoutput
}

proc virtual:vresetpass {caller user pass} {
	if {![getbncuser $caller admin] && ![string equal -nocase [virtual:getgroup $caller] [virtual:getgroup $user]]} {
		return -code error "There's no such user."
	}

	setbncuser $user password $pass

	return 0
}

proc virtual:cmd:resetpass {client parameters} {
	set user [lindex $parameters 1]
	set pass [lindex $parameters 2]

	if {$pass == ""} {
		bncnotc "Syntax: resetpass <User> <Password>"
		haltoutput

		return
	}

	if {[catch [list virtual:vresetpass $client $user $pass] error]} {
		bncreply $error
		haltoutput

		return
	}

	bncreply "Done."
	haltoutput
}

proc virtual:vdeluser {caller user} {
	set vadmindeluser [bncgetglobaltag vadmindeluser]

	if {[string equal -nocase $user $caller]} {
		return -code error "You can't remove your own account."
	}

	if {![getbncuser $caller admin]} {
		if {![string equal -nocase [virtual:getgroup $user] [virtual:getgroup $caller]]} {
			return -code error "There's no such user."
		}

		if {[getbncuser $user lock]} {
			return -code error "You can't remove suspended accounts."
		}
	}

	if {[getbncuser $caller admin]} {
		if {[getbncuser $user tag maxbncs] != ""} {
			return -code error "You cannot remove this user. Delete the group instead if you really want to delete this user."
		}
	}

	if {$vadmindeluser != "on" && ![getbncuser $caller admin]} {
		return -code error "Operation not permitted."
	}

	delbncuser $user

	return 0
}

proc virtual:cmd:deluser {client parameters} {
	set user [lindex $parameters 1]

	if {$user == ""} {
		bncreply "Syntax: deluser <User>"
		haltoutput
		return
	}

	if {[catch [list virtual:vdeluser $client $user] error]} {
		bncreply $error
		haltoutput

		return
	}

	bncreply "Done."
	haltoutput
}

proc virtual:vadduser {user pass group {checklimits 1} {override 0}} {
	set error [catch [list getbncuser $user server] result]

	if {!$error} {
		return -code error "The ident '$user' is already in use."
	}

	set nogroup 1
	foreach u [bncuserlist] {
		if {[string equal -nocase $group [virtual:getgroup $u]]} {
			set nogroup 0
			break
		}
	}

	if {$nogroup && !$override} {
		return -code error "There is no such group: $group"
	}

	if {$checklimits} {
		set maxbncs [virtual:getmaxbncs $group]

		set bncs [list]
		foreach u [bncuserlist] {
			if {[string equal -nocase $group [getbncuser $u tag group]]} {
				lappend bncs $u
			}
		}

		if {[llength $bncs] >= $maxbncs} {
			return -code error "You cannot add more than $maxbncs users."
		}
	}

	addbncuser $user $pass
	virtual:setgroup $user $group

	return 0
}

proc virtual:cmd:adduser {client parameters} {
	set user [lindex $parameters 1]
	set pass [lindex $parameters 2]

	if {[getbncuser $client admin]} {
		set group [lindex $parameters 3]
		set override [lindex $parameters 4]
	} else {
		set group [virtual:getgroup $client]
		set override 0
	}

	if {$pass == ""} {
		if {[getbncuser $client admin]} {
			bncreply "Syntax: adduser <User> <Password> \[<Group>\]"
		} else {
			bncreply "Syntax: adduser <User> <Password>"
		}

		haltoutput
		return
	}

	if {[getbncuser $client admin]} {
		set checklimits 0
	} else {
		set checklimits 1
	}

	if {[catch [list virtual:vadduser $user $pass $group $checklimits $override] error]} {
		bncreply $error
		haltoutput

		return
	}

	bncreply "Done."
	haltoutput
}

proc virtual:vaddgroup {group limit} {
	set pass [randstring 8]

	if {$limit == "" || ![string is integer $limit]} {
		return -code error "Limit should be a number."
	}

	foreach user [bncuserlist] {
		if {[string equal -nocase $group [virtual:getgroup $user]]} {
			return -code error "This groupname is already in use. Try /sbnc who $group to view a list of users."
		}
	}

	virtual:vadduser $group $pass $group 0 1
	virtual:setadmin $group $group
	setbncuser $group tag maxbncs $limit

	return $pass
}

proc virtual:cmd:addgroup {client parameters} {
	set group [lindex $parameters 1]
	set limit [lindex $parameters 2]

	if {$limit == ""} {
		bncreply "Syntax: addgroup <Group> <Limit>"
		haltoutput
		return
	}

	if {[catch [list virtual:vaddgroup $group $limit] error]} {
		bncreply $error
		haltoutput
		return
	} else {
		set pass $error
	}

	bncreply "Created a new group and user '$group' with password '$pass'."
	haltoutput
}

proc virtual:vdelgroup {group} {
	foreach user [bncuserlist] {
		if {[string equal -nocase $group [virtual:getgroup $user]] && ![getbncuser $user admin]} {
			delbncuser $user
		}
	}

	return 0
}

proc virtual:cmd:delgroup {client parameters} {
	set group [lindex $parameters 1]

	if {$group == ""} {
		bncreply "Syntax: delgroup <Group>"
		haltoutput
		return
	}

	virtual:vdelgroup $group

	bncreply "Deleted all users in group '$group' (except real admins)."
	haltoutput
}

proc virtual:vadmin {user} {
	if {[virtual:getgroup $user] == ""} {
		return -code error "'$user' is not in a group."
	}

	virtual:setadmin [virtual:getgroup $user] $user

	return 0
}

proc virtual:cmd:vadmin {client parameters} {
	set user [lindex $parameters 1]

	if {$user == ""} {
		bncreply "Syntax: vadmin <User>"
		haltoutput
		return
	}

	if {[catch [list virtual:vadmin $user] error]} {
		bncreply $error
		haltoutput
		return
	}

	bncreply "'$user' is now a virtual admin."
	haltoutput
}

proc virtual:vunadmin {user} {
	if {[virtual:getgroup $user] == ""} {
		return -code error "'$user' is not in a group."
	}

	if {[getbncuser $user tag maxbncs] != ""} {
		return -code error "You cannot remove this user's admin privilesges. Delete the group instead."
	}

	virtual:setadmin [virtual:getgroup $user] $user 0

	return 0
}

proc virtual:cmd:vunadmin {client parameters} {
	set user [lindex $parameters 1]

	if {$user == ""} {
		bncreply "Syntax: vunadmin <User>"
		haltoutput
		return
	}

	if {[catch [list virtual:vunadmin $user] error]} {
		bncreply $error
		haltoutput
		return
	}

	bncreply "'$user' is no longer a virtual admin."
	haltoutput
}

proc virtual:cmd:getlimit {client parameters} {
	set group [lindex $parameters 1]

	if {$group == ""} {
		bncreply "Syntax: getlimit <Group>"
		haltoutput
		return
	}

	if {[virtual:getadmin $group] == ""} {
		bncreply "'$group' is not a group."
		haltoutput
		return
	}

	bncreply "$group is limited to [virtual:getmaxbncs $group] users."
	haltoutput
}

proc virtual:vsetlimit {group limit} {
	if {[virtual:getadmin $group] == ""} {
		return -code error "'$group' is not a group."
	}

	if {![string is integer $limit]} {
		return -code error "You did not specify a valid limit."
	}

	virtual:setmaxbncs $group $limit

	return 0
}

proc virtual:cmd:setlimit {client parameters} {
	set group [lindex $parameters 1]
	set limit [lindex $parameters 2]

	if {$group == ""} {
		bncreply "Syntax: setlimit <Group> <Limit>"
		haltoutput
		return
	}

	if {[catch [list virtual:vsetlimit $group $limit] error]} {
		bncreply $error
		haltoutput
		return
	}

	bncreply "$group is now limited to $limit users."
	haltoutput
}

proc virtual:vgroupusers {group} {
	set bncs [list]
	foreach u [bncuserlist] {
		if {[string equal -nocase $group [getbncuser $u tag group]]} {
			lappend bncs $u
		}
	}

	return $bncs
}

proc virtual:cmd:groups {client parameters} {
	set bncs [list]
	foreach u [bncuserlist] {
		if {[virtual:getgroup $u] != ""} {
			lappend bncs [virtual:getgroup $u]
		}
	}

	set groups [sbnc:uniq $bncs]

	bncreply "Groups:"

	foreach group $groups {
		set bncs [list]
		foreach u [bncuserlist] {
			if {[string equal -nocase $group [getbncuser $u tag group]]} {
				lappend bncs $u
			}
		}

		bncreply "$group [llength $bncs]/[virtual:getmaxbncs $group]"
	}

	bncreply "End of GROUPS."
	haltoutput
}

proc virtual:cmd:globalset {client parameters} {
	set setting [string tolower [lindex $parameters 1]]
	set value [string tolower [lindex $parameters 2]]
	set vadmindeluser [bncgetglobaltag vadmindeluser]

	if {$vadmindeluser == ""} {
		set vadmindeluser "off"
	}

	switch $setting {
		vadmindeluser {
			if {$value == "on" || $value == "off" || $value == ""} {
				bncsetglobaltag vadmindeluser $value
				bncreply "Done."
				haltoutput
			} else {
				bncreply "Invalid value. Valid settings for vadmindeluser are \"on\" and \"off\"."
			}
		}
		"" {
			internaltimer 0 0 bncreply "vadmindeluser - $vadmindeluser"
		}
		default {
			return
		}
	}
}

# iface commands
# +user:
# vgetgroup
# visadmin
# +vadmin:
# vgetlimit
# vgroupusers
# vadduser user pass
# vdeluser user
# vresetpass user pass
# vuptimehr [user]
# vchannels [user]
# vsuspended [user]
# vclient [user]
# +admin:
# vgetlimit [group]
# vsetlimit [group] [limit]
# vgetgroup [user]
# visadmin [user]
# vgroups
# vgroupusers [group]
# vadmin [user]
# vunadmin [user]
# vaddgroup [group] [limit]
# vdelgroup [group]
# vsetgroup user group

proc access:vadmin {user} {
	if {[access:admin $user]} { return 1}
	if {[virtual:getgroup $user] == ""} { return 0 }
	if {![virtual:isadmin $user]} { return 0 }

	return 1
}

proc virtual:canmodify {user} {
	if {[string equal -nocase [virtual:getgroup $user] [virtual:getgroup [getctx]]] || [getbncuser [getctx] admin]} {
		return 1
	} else {
		return -code error "You cannot modify this user."
	}
}

proc virtual:canmodifygroup {group} {
	if {[string equal -nocase $group [virtual:getgroup [getctx]]] || [getbncuser [getctx] admin]} {
		return 1
	} else {
		return -code error "You cannot modify this user."
	}
}

# Iface2 commands

proc iface-virtual:getgroup {username} {
	virtual:canmodify $username

	return [itype_string [virtual:getgroup $username]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getgroup" "iface-virtual:getgroup"
}

proc iface-virtual:getmygroup {} {
	return [itype_string [virtual:getgroup [getctx]]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getmygroup" "iface-virtual:getmygroup"
}

proc iface-virtual:isvadmin {username} {
	virtual:canmodify $username

	return [itype_string [access:vadmin $username]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "isvadmin" "iface-virtual:isvadmin"
}

proc iface-virtual:getgrouplimit {group} {
	virtual:canmodifygroup $group

	return [itype_string [virtual:getmaxbncs $group]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getgrouplimit" "iface-virtual:getgrouplimit" "access:vadmin"
}

proc iface-virtual:getgroupusers {group} {
	virtual:canmodifygroup $group

	return [itype_list_strings [virtual:vgroupusers $group]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getgroupusers" "iface-virtual:getgroupusers" "access:vadmin"
}

proc iface-virtual:vadduser {username password} {
	if {[getbncuser [getctx] admin]} {
		set checklimits 0
	} else {
		set checklimits 1
	}

	virtual:vadduser $username $password [virtual:getgroup [getctx]] $checklimits

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vadduser" "iface-virtual:vadduser" "access:vadmin"
}

proc iface-virtual:vdeluser {username} {
	virtual:canmodify $username

	virtual:vdeluser [getctx] $username

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vdeluser" "iface-virtual:vdeluser" "access:vadmin"
}

proc iface-virtual:vresetpass {username password} {
	virtual:canmodify $username

	setbncuser $username password $password

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vresetpass" "iface-virtual:vresetpass" "access:vadmin"
}

proc iface-virtual:vgetuptimehr {username} {
	virtual:canmodify $username

	return [itype_string [duration [getbncuser $username uptime]]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vgetuptimehr" "iface-virtual:vgetuptimehr" "access:vadmin"
}

proc iface-virtual:vgetchannels {username} {
	virtual:canmodify $username

	setctx $username
	return [itype_list_strings [internalchannels]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vgetchannels" "iface-virtual:vgetchannels" "access:vadmin"
}

proc iface-virtual:vissuspended {username} {
	virtual:canmodify $username

	return [itype_string [getbncuser $username lock]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vissuspended" "iface-virtual:vissuspended" "access:vadmin"
}

proc iface-virtual:vgetclient {username} {
	virtual:canmodify $username

	setctx $username
	return [itype_string [getbncuser $username client]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vgetclient" "iface-virtual:vgetclient" "access:vadmin"
}

proc iface-virtual:setgrouplimit {group limit} {
	virtual:vsetlimit $group $limit

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "setgrouplimit" "iface-virtual:setgrouplimit" "access:admin"
}

proc iface-virtual:getgroups {} {
	set groups [list]

	foreach user [bncuserlist] {
		if {[virtual:getgroup $user] != ""} {
			lappend groups [string tolower [virtual:getgroup $user]]
		}
	}

	return [itype_list_strings [sbnc:uniq $groups]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getgroups" "iface-virtual:getgroups" "access:admin"
}

proc iface-virtual:getgroup {username} {
	return [itype_string [virtual:getgroup $username]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getgroup" "iface-virtual:getgroup" "access:admin"
}

proc iface-virtual:setgroup {username group} {
	virtual:setgroup $username $group

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "setgroup" "iface-virtual:setgroup" "access:admin"
}

proc iface-virtual:vadmin {username} {
	virtual:vadmin $username

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vadmin" "iface-virtual:vadmin" "access:admin"
}

proc iface-virtual:vunadmin {username} {
	virtual:vunadmin $username

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "vunadmin" "iface-virtual:vunadmin" "access:admin"
}

proc iface-virtual:addgroup {group limit} {
	virtual:vaddgroup $group $limit

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "addgroup" "iface-virtual:addgroup" "access:admin"
}

proc iface-virtual:delgroup {group} {
	virtual:vdelgroup $group

	return ""
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "delgroup" "iface-virtual:delgroup" "access:admin"
}

proc iface-virtual:getgroupadmin {group} {
	return [itype_string [virtual:getadmin $group]]
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "getgroupadmin" "iface-virtual:getgroupadmin" "access:admin"
}

proc iface-virtual:setvadmindeluser {value} {
	if {$value == "on" || $value == "off" || $value == ""} {
		bncsetglobaltag vadmindeluser $value
		return ""
	} else {
		return -code error "vadmindeluser setting needs to be either \"on\" or \"off\""
	}
}

if {[info commands "registerifacecmd"] != ""} {
	registerifacecmd "virtual" "setvadmindeluser" "iface-virtual:setvadmindeluser" "access:admin"
}