-
Notifications
You must be signed in to change notification settings - Fork 7
/
Sitecmds.tcl
195 lines (181 loc) · 6.15 KB
/
Sitecmds.tcl
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
#################################################################################
# dZSbot/ngBot - Sitecmds Plug-in v0.2.4 #
#################################################################################
#
# Description:
# - You need to have NickDb.tcl loaded.
# - You need to install lftp
# - Thanks to neoxed AGAIN(!!) for helping with the pzs-ng part
#
# Installation:
# 1. add this to your glftpd.conf:
# -emulate -<emulate user>
# if you leave the defaults of this script:
# -emulate -emulate
# and add the user by:
# site adduser emulate emulation *@127.0.0.1
#
# 2. Edit the configuration options below.
#
# 3. Add the following to your eggdrop.conf:
# source pzs-ng/plugins/Sitecmds.tcl
#
# 4. Add the following line to your dZSbot/ngBot.conf:
# set variables(SITECMDS) "%msg"
# set disable(SITECMDS) 0
#
# Add SITECMDS at the end of your msgtypes(DEFAULT) line
#
# Optionally:
# set redirect(SITECMDS) "#staffchannel"
#
# 5. Add the following line to your theme file:
# announce.SITECMDS = "[%b{sitecmd}] %msg"
#
# 6. Rehash or restart your eggdrop for the changes to take effect.
#
#################################################################################
namespace eval ::ngBot::plugin::Sitecmds {
variable ns [namespace current]
## Config Settings ###############################
##
## Choose one of two settings, the first when using ngBot, the second when using dZSbot
variable np [namespace qualifiers [namespace parent]]
#variable np ""
##
## (OLD) Path to cpt-Sitecmds.sh (place it in your glftpd/bin directory please!)
## (OLD) variable cptSitecmds "/jail/glftpd/bin/cpt-Sitecmds.sh"
# Now uses lftp instead
variable lftp "/usr/bin/lftp"
##
## Username and password for the user that should execute the commands
variable username "emulate"
variable password "1eMuL!4T3"
##
## And where should we connect to?
variable ftphost "127.0.0.1"
variable port "39500"
##
## Change username if the user is privileged to execute those commands??
## For now, i'd certainly consider it desired behaviour :)
variable emulate True
##
##
## Who can use the 'raw' !site command? It strongly recommended that you
## only allow very trusted folks to do that.
variable permsraw "1 =siteops"
##
## Maximum number of lines... don't set this too high, or your channel will
## get flooded ;p
variable maxlines 5
##
##################################################
namespace import ${np}::plugin::NickDb::*
#bind evnt -|- prerehash ${ns}::deinit
interp alias {} IsTrue {} string is true -strict
interp alias {} IsFalse {} string is false -strict
if {[string equal "" $np]} {
bind evnt -|- prerehash ${ns}::deinit
}
####
# init
#
# Called on initialization; registers the event handler. Yeah, nothing fancy.
#
proc init {} {
variable ns
## Bind event callbacks.
bind pub -|- !site ${ns}::Cmd
putlog "\[ngBot\] Sitecmds :: Loaded successfully."
return
}
####
# Getinfo
#
# Get $group and $flags, needed for rightscheck
#
proc GetInfo {ftpUser groupVar flagsVar} {
variable np
global ${np}::location
upvar $groupVar group $flagsVar flags
set file "$location(USERS)/$ftpUser"
# Linux will give an error if you open a directory and try to read from it.
if {![file isfile $file]} {
putlog "\[ngBot\] SiteCmds Error :: Invalid user file for \"$ftpUser\" ($file)."
return 0
}
set group ""; set flags ""
if {![catch {set handle [open $file r]} error]} {
set data [read $handle]
close $handle
foreach line [split $data "\n"] {
switch -exact -- [lindex $line 0] {
"FLAGS" {set flags [lindex $line 1]}
"GROUP" {set group [lindex $line 1]}
}
}
return 1
} else {
putlog "dZSbot error: Unable to open user file for \"$ftpUser\" ($error)"
return 0
}
}
####
# deinit
#
# Called on rehash; unregisters the event handler.
#
proc deinit {} {
variable ns
## Remove event callbacks.
#catch {unbind evnt -|- prerehash ${ns}::DeInit}
catch {unbind pub -|- !site ${ns}::Cmd}
namespace delete $ns
return
}
proc Cmd {nick host handle channel text} {
variable np
variable lftp
variable username
variable password
variable ftphost
variable port
variable emulate
variable permsraw
variable maxlines
set emulUser [GetFtpUser $nick]
if {[string equal "" $nick]} {return}
#regsub -all "$text"
if {[regexp {\\n|\||\;} $text]} {
set line "%b{ALERT:} $emulUser tried to execute these commands: \nsite $text"
${np}::sndall SITECMDS DEFAULT [${np}::ng_format "SITECMDS" "DEFAULT" \"$line\"]
return
}
if {[GetInfo $emulUser group flags]} {
if {[${np}::rightscheck $permsraw $ $group $flags]} {
set i 1
foreach line [split [exec $lftp -u $username,$password $ftphost:$port -e "site emulate $emulUser\nsite $text"] "\n"] {
if { $i < $maxlines } {
if { $line != "200 Command Successful."} {
${np}::sndall SITECMDS DEFAULT [${np}::ng_format "SITECMDS" "DEFAULT" \"$line\"]
}
} else {
set line "Maximum number of lines($maxlines) has been reached."
${np}::sndall SITECMDS DEFAULT [${np}::ng_format "SITECMDS" "DEFAULT" \"$line\"]
break
}
incr i
}
} else {
set line "Sorry, you're not allowed to execute that command."
puthelp "PRIVMSG $channel :$line"
}
} else {
set line "Sorry, you don't exist. Try inviting yourself again."
puthelp "PRIVMSG $channel :$line"
}
}
}
if {[string equal "" $::ngBot::plugin::Sitecmds::np]} {
::ngBot::plugin::Sitecmds::init
}