09-05-2010, 00:28 +0200
Forum: Overviewworkscript announcements
Allows to set a channelmode +Access who will check Q-auth against a db
AuthorPost
Gotisch  02-18-2006, 14:00   | [EGG] Access ICQ        Quote  Reply
(Moderator)
Member since 01/2006
19 Posts
Location: Europe
This script will check Q-Auths against a Database with at least two columns, where one defines the auth and the other the channel the auth has access to.

you can change access with the .access command (owners only) from the party line.

I was writing this for Someone but only for one channel. So i though just in case someone needs something like that to expand it to multiple chans.

1  #Access (c) gotisch
2  namespace eval Access {
3      # Limit's Access to a Channel based on Q-Auth.
4      # To check Q-Account we use: who nick n%nat,30
5      # Config:
6      variable mysql
7      array set mysql {
8          pkg        ""
9          host    "localhost"
10          user    "user"
11          pass    "pass"
12          db        "db"
13          table    "access"
14          ncol    "account"
15          ccol     "channel"
16      }
17      #No need to change that prob.
18      variable num 100
19      variable chan ""
20      #Channel flag
21      setudef flag Access
22      #Binds:
23      bind join - * [namespace current]::OnJoin
24      bind raw - 354 [namespace current]::OnRaw
25      bind dcc n access  [namespace current]::OnCommand
26      #Procs:
27      proc OnCommand { ha id te } {
28          set args [split $te]
29          if {[llength $args] < 3} {
30              showhelp $id
31              return
32          }
33          foreach {cmd auth chan} $args break;
34          switch $cmd {
35              "add" {
36                  if {![IsAllowed $auth $chan]} {
37                      Allow $auth $chan
38                  }
39                  putdcc $id "Done."
40              }
41              "remove" {
42                  if {[IsAllowed $auth $chan]} {
43                      UnAllow $auth $chan
44                  }
45                  putdcc $id "Done."
46              }
47              default {
48                  showhelp $id
49                  return
50              }
51          }
52      }
53      proc showhelp id {
54          putdcc $id "Syntax is: .access <add/remove> <nick> <channel>"
55          putdcc $id "Both can be masks so be carefull"
56          putdcc $id "For example '.access remove somenick %' will remove all access of that user."   
57      }
58      proc OnJoin { n uh ha ch } {
59          variable num
60          variable chan
61          if {[isbotnick $n]} {return}
62        if {![channel get $ch Access]} {return}
63        putquick "WHO $n n%nat,$num" -next
64        putlog "[namespace current]: Testing $n on $ch"
65        set chan $ch
66      }
67      proc OnRaw { from keyword arguments } {
68          variable num
69          variable chan
70          if {$keyword != 354} { return }
71          putlog "[namespace current]: Got $arguments"
72          set list1 [split $arguments]
73          if {[lindex $list1 0] != $::botnick} { return }
74          putlog "[namespace current]: For me [lindex $list1 0]"
75          if {[lindex $list1 1] != $num} { return }
76          putlog "[namespace current]: Right Query"
77          if {![IsAllowed [lindex $list1 3] $chan]} {
78              putlog "[namespace current]: Not Allowed"
79              Remove [lindex $list1 2] $chan
80              return
81          }
82      }
83      proc IsAllowed {auth chan} {
84          variable mysql
85          if {$auth == "0"} { return 0 }
86          putlog "[namespace current]: Authed as $auth"
87          #1. Connect to Database:
88      if { [ catch {
89                    set handle [mysqlconnect -host $mysql(host) -u $mysql(user) -password $mysql(pass) -db $mysql(db)] 
90                   } err ] } {
91        putlog "[namespace current]: Could not connect to MYSQL."
92        return 1
93      }
94      #2. We now have a valid mysql handle in $handle
95          set result [mysqlsel $handle "SELECT `$mysql(ncol)` FROM `$mysql(table)` WHERE `$mysql(ncol)` LIKE '$auth' AND `$mysql(ccol)` LIKE '$chan'" -list]
96          mysqlclose $handle
97          putlog "[namespace current]: $result"
98          if {$result == {}} { return 0 }
99      return 1
100    }
101    proc Allow { auth chan } {
102          variable mysql
103          if { [ catch {
104                    set handle [mysqlconnect -host $mysql(host) -u $mysql(user) -password $mysql(pass) -db $mysql(db)] 
105                   } err ] } {
106        putlog "[namespace current]: Could not connect to MYSQL."
107        return 1
108      }
109          putlog "[namespace current]:Allowing '$auth' to enter '$chan'"
110          set result [mysqlexec $handle "INSERT INTO `$mysql(table)` ($mysql(ncol), $mysql(ccol)) VALUES ('$auth','$chan')"]
111          putlog "[namespace current]: $result"
112      }
113      proc UnAllow { auth chan } {
114          variable mysql
115          if { [ catch {
116                    set handle [mysqlconnect -host $mysql(host) -u $mysql(user) -password $mysql(pass) -db $mysql(db)] 
117                   } err ] } {
118        putlog "[namespace current]: Could not connect to MYSQL."
119        return 1
120      }
121          putlog "[namespace current]: Removing '$auth's right to enter '$chan'"
122          set result [mysqlexec $handle "DELETE FROM `$mysql(table)` WHERE `$mysql(ncol)` LIKE '$auth' AND `$mysql(ccol)` LIKE '$chan'"]
123          putlog "[namespace current]: $result"
124      }
125      proc Remove {nick chan} {
126              if {![channel get $chan Access]} { continue }
127              if {![onchan $nick $chan]} { continue }
128              newchanban $chan [maskhost [getchanhost $nick $chan]] [namespace current] "No Access - 10min ban" 10 sticky
129              putkick $chan $nick "No Access - 10min ban"
130              putlog "[namespace current]: Removing $nick from $chan. Reason: No Access"
131      }
132      proc ScriptLoad {} {
133          variable mysql
134          putlog "[namespace current]: Loading..."
135          if { $mysql(pkg) == "" } {
136          #No package set so we try to just require it.
137          if { [catch { package require mysqltcl } err ] } { putlog "[namespace current]: Could not load mysql, unloading"; ScriptUnload; return }
138        } else {
139          #Mysqltcl should be a .so
140          if { [catch { load $mysql(pkg) } err ] } { putlog "[namespace current]: Could not load mysql, unloading"; ScriptUnload; return }
141        }
142        putlog "[namespace current]: Done..."
143      }
144      #This never gets called manually.
145      proc ScriptUnload {} {
146          putlog "[namespace current]: Unloading..."
147          foreach bind [binds [namespace current]*] {
148           unbind [lindex $bind 0] [lindex $bind 1] [lindex $bind 2] [lindex $bind 4]
149      }
150      putlog "[namespace current]: Done..."
151      namespace delete [namespace current]
152      }
153      #Start
154      ScriptLoad
155  }
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen