05-30-2020, 06:36 +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
(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.

                                                                                                                              
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
#Access (c) gotisch
namespace eval Access {
    # Limit's Access to a Channel based on Q-Auth.
    # To check Q-Account we use: who nick n%nat,30
    # Config:
    variable mysql
    array set mysql {
        pkg        ""
        host    "localhost"
        user    "user"
        pass    "pass"
        db        "db"
        table    "access"
        ncol    "account"
        ccol     "channel"
    }
    #No need to change that prob.
    variable num 100
    variable chan ""
    #Channel flag
    setudef flag Access
    #Binds:
    bind join - * [namespace current]::OnJoin
    bind raw - 354 [namespace current]::OnRaw
    bind dcc n access  [namespace current]::OnCommand
    #Procs:
    proc OnCommand { ha id te } {
        set args [split $te]
        if {[llength $args] < 3} {
            showhelp $id
            return
        }
        foreach {cmd auth chan} $args break;
        switch $cmd {
            "add" {
                if {![IsAllowed $auth $chan]} {
                    Allow $auth $chan
                }
                putdcc $id "Done."
            }
            "remove" {
                if {[IsAllowed $auth $chan]} {
                    UnAllow $auth $chan
                }
                putdcc $id "Done."
            }
            default {
                showhelp $id
                return
            }
        }
    }
    proc showhelp id {
        putdcc $id "Syntax is: .access <add/remove> <nick> <channel>"
        putdcc $id "Both can be masks so be carefull"
        putdcc $id "For example '.access remove somenick %' will remove all access of that user."
    }
    proc OnJoin { n uh ha ch } {
        variable num
        variable chan
        if {[isbotnick $n]} {return}
        if {![channel get $ch Access]} {return}
        putquick "WHO $n n%nat,$num" -next
        putlog "[namespace current]: Testing $n on $ch"
        set chan $ch
    }
    proc OnRaw { from keyword arguments } {
        variable num
        variable chan
        if {$keyword != 354} { return }
        putlog "[namespace current]: Got $arguments"
        set list1 [split $arguments]
        if {[lindex $list1 0] != $::botnick} { return }
        putlog "[namespace current]: For me [lindex $list1 0]"
        if {[lindex $list1 1] != $num} { return }
        putlog "[namespace current]: Right Query"
        if {![IsAllowed [lindex $list1 3] $chan]} {
            putlog "[namespace current]: Not Allowed"
            Remove [lindex $list1 2] $chan
            return
        }
    }
    proc IsAllowed {auth chan} {
        variable mysql
        if {$auth == "0"} { return 0 }
        putlog "[namespace current]: Authed as $auth"
        #1. Connect to Database:
        if { [ catch {
                set handle [mysqlconnect -host $mysql(host) -u $mysql(user) -password $mysql(pass) -db $mysql(db)]
            } err ] } {
            putlog "[namespace current]: Could not connect to MYSQL."
            return 1
        }
        #2. We now have a valid mysql handle in $handle
        set result [mysqlsel $handle "SELECT `$mysql(ncol)` FROM `$mysql(table)` WHERE `$mysql(ncol)` LIKE '$auth' AND `$mysql(ccol)` LIKE '$chan'" -list]
        mysqlclose $handle
        putlog "[namespace current]: $result"
        if {$result == {}} { return 0 }
        return 1
    }
    proc Allow { auth chan } {
        variable mysql
        if { [ catch {
                set handle [mysqlconnect -host $mysql(host) -u $mysql(user) -password $mysql(pass) -db $mysql(db)]
            } err ] } {
            putlog "[namespace current]: Could not connect to MYSQL."
            return 1
        }
        putlog "[namespace current]:Allowing '$auth' to enter '$chan'"
        set result [mysqlexec $handle "INSERT INTO `$mysql(table)` ($mysql(ncol), $mysql(ccol)) VALUES ('$auth','$chan')"]
        putlog "[namespace current]: $result"
    }
    proc UnAllow { auth chan } {
        variable mysql
        if { [ catch {
                set handle [mysqlconnect -host $mysql(host) -u $mysql(user) -password $mysql(pass) -db $mysql(db)]
            } err ] } {
            putlog "[namespace current]: Could not connect to MYSQL."
            return 1
        }
        putlog "[namespace current]: Removing '$auth's right to enter '$chan'"
        set result [mysqlexec $handle "DELETE FROM `$mysql(table)` WHERE `$mysql(ncol)` LIKE '$auth' AND `$mysql(ccol)` LIKE '$chan'"]
        putlog "[namespace current]: $result"
    }
    proc Remove {nick chan} {
        if {![channel get $chan Access]} { continue }
        if {![onchan $nick $chan]} { continue }
        newchanban $chan [maskhost [getchanhost $nick $chan]] [namespace current] "No Access - 10min ban" 10 sticky
        putkick $chan $nick "No Access - 10min ban"
        putlog "[namespace current]: Removing $nick from $chan. Reason: No Access"
    }
    proc ScriptLoad {} {
        variable mysql
        putlog "[namespace current]: Loading..."
        if { $mysql(pkg) == "" } {
            #No package set so we try to just require it.
            if { [catch { package require mysqltcl } err ] } { putlog "[namespace current]: Could not load mysql, unloading"; ScriptUnload; return }
        } else {
            #Mysqltcl should be a .so
            if { [catch { load $mysql(pkg) } err ] } { putlog "[namespace current]: Could not load mysql, unloading"; ScriptUnload; return }
        }
        putlog "[namespace current]: Done..."
    }
    #This never gets called manually.
    proc ScriptUnload {} {
        putlog "[namespace current]: Unloading..."
        foreach bind [binds [namespace current]*] {
            unbind [lindex $bind 0] [lindex $bind 1] [lindex $bind 2] [lindex $bind 4]
        }
        putlog "[namespace current]: Done..."
        namespace delete [namespace current]
    }
    #Start
    ScriptLoad
}

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 | Time: 164.6 msec, CPU time: 63 msec, 30 Database queries in 119.1 msec | 6 kB (38 kB) | Timezone: +0200