tiid-user.tcl (1565B)
1 #!/usr/bin/env tclsh 2 # tiid-user: user management utility for tiid (tii node daemon) 3 # can work both over HTTP and Gopher/Nex 4 # Usage: tiid-user.tcl [dbfile] user [username] auth [password] acl [acl] 5 # if the username doesn't exist, it will be created 6 # if it does exist, the corresponding fields will be updated 7 # Depends upon Tcllib and sqlite3 8 # Created by Luxferre in 2024, released into public domain 9 10 package require sqlite3 11 package require sha256 12 13 if {$argc > 2} { 14 set dbfile [lindex $argv 0] 15 set kvargs [lrange $argv 1 end] 16 puts $kvargs 17 set username "" 18 set authhash "" 19 set acl "*" 20 if {[dict exists $kvargs user]} { 21 set username [dict get $kvargs user] 22 } 23 if {[dict exists $kvargs auth]} { 24 set rawauth [dict get $kvargs auth] 25 set authhash [::sha2::sha256 -hex -- [string trim $rawauth]] 26 } 27 if {[dict exists $kvargs acl]} { 28 set acl [dict get $kvargs acl] 29 } 30 if {$username ne ""} { 31 if {$authhash eq ""} { # we're only changing the ACL 32 set query {UPDATE `auth` SET `posting_acl` = :acl WHERE `username` = :username;} 33 } else { # we're inserting/updating a user 34 set query {INSERT INTO `auth` (`username`, `authstrhash`, `posting_acl`) 35 VALUES (:username, :authhash, :acl) 36 ON CONFLICT(`username`) DO UPDATE SET `authstrhash` = excluded.`authstrhash`, 37 `posting_acl` = excluded.`posting_acl`;} 38 } 39 sqlite3 db $dbfile 40 db eval $query 41 db close 42 puts "Changes written" 43 } else {puts "User field is required!"} 44 } else {puts "DB file and at least one key is required!"}