Changeset 56
- Timestamp:
- 03/01/08 14:30:57 (10 months ago)
- Location:
- trunk/awkbot
- Files:
-
- 4 added
- 6 modified
-
bin/awkbot (modified) (1 diff)
-
cgi-bin (added)
-
cgi-bin/paste.cgi (added)
-
etc/awkbot.conf (modified) (3 diffs)
-
htdocs (added)
-
htdocs/index.xhtml (added)
-
src/awkbot.awk (modified) (1 diff)
-
src/awkbot_db_mysql.awk (modified) (1 diff)
-
src/awkpaste.awk (modified) (2 diffs)
-
src/cgi-lib.awk (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/awkbot/bin/awkbot
r50 r56 16 16 # Give our continuous input through a pipe to tail. tail -f never exits. 17 17 # Note, that this means awkbot never exits unless killed from the outside. 18 chmod 666 $livedata 18 19 tail -f $livedata | awk -f $awkbot 19 20 -
trunk/awkbot/etc/awkbot.conf
r47 r56 2 2 # IRC Stuff 3 3 <irc> 4 nickname awk test5 altnick awk _test4 nickname awkbot 5 altnick awkbot- 6 6 username awkbot 7 7 realname AWK IRC bot … … 11 11 # channel awk perl pike 12 12 # channel c++ 13 channel awk 13 channel awk #leapfrog 14 14 # channel blacksun 15 15 debug 1 16 #startup PRIVMSG NickServ :identify darwin16 startup PRIVMSG NickServ :identify darwin 17 17 </irc> 18 18 … … 22 22 23 23 <mysql> 24 username scott 25 password scott 24 username scottmc 25 password scottmc 26 26 database awkbot 27 27 </mysql> 28 29 <paste> 30 channel #awk 31 cgi http://awkpaste.blisted.org/cgi/paste.cgi 32 form http://awkpaste.blisted.org/ 33 </paste> -
trunk/awkbot/src/awkbot.awk
r48 r56 71 71 $1 == "say" { 72 72 _msg = $3 73 for (i = 4; i < NF; i++) {73 for (i = 4; i <= NF; i++) { 74 74 _msg = _msg " " $i 75 75 } -
trunk/awkbot/src/awkbot_db_mysql.awk
r47 r56 119 119 return result 120 120 } 121 122 function awkbot_db_paste_add (nick, description, content) { 123 mysql_finish(mysql_query("INSERT INTO paste (nick, subject, content) " \ 124 " VALUES (" mysql_quote(nick) "," \ 125 mysql_quote(description) "," \ 126 mysql_quote(content) ")")) 127 } 128 129 function awkbot_db_paste_get (id,row ,rv) { 130 rv = mysql_query("SELECT nick, subject, content FROM paste " \ 131 "WHERE paste_id = " mysql_quote(id)) 132 133 mysql_fetch_assoc(rv, row) 134 mysql_finish(rv) 135 } 136 137 function awkbot_db_paste_last ( result,row,rv) { 138 rv = mysql_query("SELECT max(paste_id) as paste_id FROM paste"); 139 140 if (mysql_fetch_assoc(rv, row)) { 141 result = row["paste_id"] 142 } 143 144 mysql_finish(rv) 145 146 return result 147 } -
trunk/awkbot/src/awkpaste.awk
r47 r56 2 2 3 3 #import <cgi-lib.awk> 4 #import <config.awk> 5 #import <awkbot_db_mysql.awk> 4 6 5 7 BEGIN { … … 7 9 cgi_headers("text/plain") 8 10 9 for (key in query) { 10 print key, ":", query[key] 11 config_load("etc/awkbot.conf") 12 awkbot_db_init() 13 14 if (query["id"]) { 15 awkbot_db_paste_get(query["id"], paste) 16 17 id = query["id"] 18 nick = paste["nick"] 19 subject = paste["subject"] 20 content = paste["content"] 21 22 gsub(/\\n/, "\n", content) 11 23 } 24 else { 25 stream = awkbot_db_status_livefeed() 26 27 nick = query["name"] 28 subject = query["description"] 29 content = query["content"] 30 31 awkbot_db_paste_add(nick, subject, content) 32 # This has synchronization issues...but what the hell, this is awk 33 id = awkbot_db_paste_last() 34 35 if (id) { 36 printf("say %s %s pasted %s at %s?id=%s\n", \ 37 config("paste.channel"), nick, subject,\ 38 config("paste.cgi"), id) >> stream 39 40 close(stream) 41 } 42 } 43 44 45 print "Id:", id 46 print "Nick:", nick 47 print "Subject:", subject 48 print content 12 49 } -
trunk/awkbot/src/cgi-lib.awk
r47 r56 1 2 #import <chr.awk> 3 1 4 BEGIN { 2 5 if (ENVIRON["REQUEST_METHOD"] == "POST") … … 7 10 # Set this globally so we don't have to ensure it happens anywhere else... 8 11 ORS = "\r\n" 12 } 9 13 10 # Handle uploads... 14 function uri_decode (string ,i,len,result) { 15 # for portability, we have to continuously work in the argument provided... 16 # standard awk has no Nth match 17 len = length(string) 11 18 12 # gawk only 13 match(HEADER["Content-Disposition"], / filename="([^;]*)"/, r) 14 filename = r[1] ? r[1] : "multipart/mixed" 15 16 if (filename && multipart) { 17 tempfilename = tempfile("cgi-awk") 19 while ((i = index(string, "%")) && i + 2 < len) { 20 result = result substr(string, 1, i - 1) 21 result = result chr(dec( substr(string, i + 1, 2) )) 22 string = substr(string, i + 3) 18 23 } 19 24 20 # When it's multipart, save headers and body together 21 if (multipart) { 22 for (key in HEADER) print key ":", HEADER[key] >> tempfilename 23 print "\r\n" >> tempfilename 24 } 25 result = result string 25 26 26 while (buffersize < length(input)) { 27 getline i 28 print i >> tempfile 29 } 30 31 print cgi_read_buffer() >> tempfilename 27 gsub("+", " ", result) 28 return result 32 29 } 33 30 … … 35 32 split(_cgilib_in, pairs, /\&/) 36 33 i = 0 34 37 35 while (pairs[++i]) { 38 36 split(pairs[i], each, /=/) 39 query[each[1]] = each[2] 37 38 # This assumes no encoding will exist in keys...typically a safe 39 # assumption, but not necessarily always true 40 query[each[1]] = uri_decode(each[2]) 40 41 } 41 42 }