-
Notifications
You must be signed in to change notification settings - Fork 2
/
zdb.tcl
110 lines (108 loc) · 3.65 KB
/
zdb.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
# zdb.tcl - zConf Database manager
namespace eval zconf {
namespace eval zdb {
package require sqlite3
proc create {hand nick} {
set path [zconf::util::getPath]
set authcode [zconf::util::randpass 5]
set db "$path/userdir/$hand.db"
if {![file exists "$db"]} { sqlite3 zdb $db -create true } else { sqlite3 zdb $db -readonly false }
zdb eval BEGIN
zdb eval {CREATE TABLE zncdata(registrar text, auth text, confirmed text, freeze text)}
zdb eval {INSERT INTO zncdata VALUES('$nick',$authcode,'false','false')}
zdb eval COMMIT
putlog "zDB ~ Account Created - $hand created by $nick / authcode - $authcode"
zdb close
}
proc admcreate {nick} {
set path [zconf::util::getPath]
set db "$path/userdir/$nick.db"
if {![file exists "$db"]} { sqlite3 zdb $db -create true } else { sqlite2 zdb $db -readonly falce }
zdb eval BEGIN
zdb eval {CREATE TABLE zncdata(registrar text, auth text, confirmed text, freeze text)}
zdb eval {INSERT INTO zncdata VALUES('admin','acp','true','false')}
zdb eval COMMIT
putlog "zDB ~ Account created by admin - $nick created"
zdb close
}
proc get {nick v1} {
set path [zconf::util::getPath]
set db "$path/userdir/$nick.db"
if {![file exists "$db"]} { sqlite3 zdb $db -create true } else { sqlite3 zdb $db -readonly true }
if {$v1 == "reg"} { set chk 0 }
if {$v1 == "auth"} { set chk 1 }
if {$v1 == "confirmed"} { set chk 2 }
if {$v1 == "freeze"} { set chk 3 }
if {$v1 == ""} { return "Error - No variable asked for" }
putlog "zDB ~ checking '$nick' for $v1 (section: $chk)"
set rt [zdb eval {SELECT * FROM zncdata ORDER BY $v1}]
set zrt [lindex $rt $chk]
putlog "zDB ~ Info retreived - $zrt"
return "$zrt"
zdb close
}
proc makereg {} {
global zconf::settings::path
set path $zconf::settings::path
set db "$path/userdir/settings.db"
sqlite3 rdb $db -create true
rdb eval BEGIN
rdb eval {CREATE TABLE regstat(setting text)}
rdb eval {INSERT INTO regstat VALUES("public")}
rdb eval COMMIT
rdb close
}
proc regstat {} {
set path [zconf::util::getPath]
set db "$path/userdir/settings.db"
sqlite3 rdb $db -readonly true
set rt [rdb eval {SELECT * FROM regstat}]
set zrt [lindex $rt 0]
return $zrt
rdb close
}
proc regset {reg} {
set path [zconf::util::getPath]
set db "$path/userdir/settings.db"
sqlite3 rdb $db
rdb eval BEGIN
rdb eval {UPDATE regstat SET setting = $reg}
rdb eval COMMIT
rdb close
}
proc freeze {nick} {
set path [zconf::util::getPath]
set db "$path/userdir/$nick.db"
if {![file exists "$db"]} { putserv "PRIVMSG [zconf::util::getChan] :Error: $nick account doesnt exist"; halt }
putlog "freezing $nick @ $db"
sqlite3 zdb $db -readonly false
zdb eval BEGIN
zdb eval {UPDATE zncdata SET freeze = "true"}
zdb eval COMMIT
putlog "zDB ~ Account $nick frozen"
zdb close
}
proc unfreeze {nick} {
set path [zconf::util::getPath]
set db "$path/userdir/$nick.db"
if {![file exists "$db"]} { putserv "PRIVMSG [zconf::util::getChan] :Error: $nick account doesnt exist"; halt }
sqlite3 zdb $db -readonly false
zdb eval BEGIN
zdb eval {UPDATE zncdata SET freeze = "false"}
zdb eval COMMIT
putlog "zDB ~ Account $nick unfrozen"
zdb close
}
proc confirm {nick} {
set path [zconf::util::getPath]
set db "$path/userdir/$nick.db"
if {![file exists "$db"]} { sqlite3 zdb $db -create true } else { sqlite3 zdb $db -readonly false }
zdb eval BEGIN
zdb eval {UPDATE zncdata SET confirmed = "true"}
zdb eval COMMIT
putlog "zDB ~ Account $nick confirmed"
zdb close
}
}
}
putlog "zConf Database Manager v0.2 loaded";