From: b Date: Thu, 8 Sep 2022 20:59:54 +0000 (+0000) Subject: Initial state from botcastle1b/eizm/pro/mrobsniped X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;ds=sidebyside;p=ott%2Fmrobsniped Initial state from botcastle1b/eizm/pro/mrobsniped --- d7d5eb55dd3ae3744ea08cb8b1c436f6d8d188e6 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e36d4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +confirmd +cookf +htmltemp +htmltmp2 +lastmax +lasttemp +nextpost +postf +postfile +tempf +thispost diff --git a/makefile b/makefile new file mode 100644 index 0000000..d2807c9 --- /dev/null +++ b/makefile @@ -0,0 +1,32 @@ +SCHEDULE2 = */12 * * * * +SCHEDULE4 = 11 6 */2 * * +CRON_USER = b +ROOT = root + +CRON_DIR = /etc/cron.d +BIN_DIR = /botm/bin/mrobsniped + +CP = /usr/bin/cp +MV = /usr/bin/mov +RM = /usr/bin/rm +CHMOD = /usr/bin/chmod +CHOWN = /usr/bin/chown + +all: mrobsniped.cron + +install: cronout + +mrobsniped.cron: + echo "###mrobsniped" > mrobsniped.cron + echo "$(SCHEDULE2) $(CRON_USER) $(BIN_DIR)/sniped2.awk" >> mrobsniped.cron + echo "$(SCHEDULE4) $(CRON_USER) $(BIN_DIR)/sniped4.awk" >> mrobsniped.cron + +cronout: mrobsniped.cron + $(CHMOD) o-w,g-w mrobsniped.cron + $(CHOWN) $(ROOT) mrobsniped.cron + $(MV) mrobsniped.cron $(CRON_DIR) + +clean: + $(RM) mrobsniped.cron + +PHONY: all install cronout clean diff --git a/mpost.awk b/mpost.awk new file mode 100644 index 0000000..6b0f726 --- /dev/null +++ b/mpost.awk @@ -0,0 +1,58 @@ +BEGIN{ + FS="=" + fora="http://1190.bicyclesonthemoon.info/ott" + useragent="\"mr*bdexbot (http://1190.bicyclesonthemoon.info/mrobsniped/; mr*bdex bOTTeriada post bot)\"" +}; +{ + eq=index($0,"=") + argtab[substr($0,1,eq-1)]=substr($0,eq+1) +}; +END{ + printf ("username=%s",argtab["username"])>postfile + printf ("&password=%s",argtab["password"])>>postfile + printf ("&subject=%s",argtab["subject"])>>postfile + if("&addbbcode20" in argtab) + printf ("&addbbcode20=%s",argtab["addbbcode20"])>>postfile + printf ("&message=%s",argtab["message"])>>postfile + printf ("&post=%s","Submit")>>postfile + if("disable_bbcode" in argtab) + printf ("&disable_bbcode=%s",argtab["disable_bbcode"])>>postfile + if("disable_smilies" in argtab) + printf ("&disable_smilies=%s",argtab["disable_smilies"])>>postfile + if("disable_magic_url" in argtab) + printf ("&disable_magic_url=%s",argtab["disable_magic_url"])>>postfile + if("attach_sig" in argtab) + printf ("&attach_sig=%s",argtab["attach_sig"])>>postfile + if("notify" in argtab) + printf ("¬ify=%s",argtab["notify"])>>postfile + printf ("&creation_time=%s",argtab["creation_time"])>>postfile + printf ("&form_token=%s",argtab["form_token"])>>postfile + close(postfile) + + if(system("wget -q -t 3 --connect-timeout=60 --post-file=" postfile " -U " useragent " -O " tempfile " \""fora "/post\"")) + { + print "Submit fail." + exit 1 + } + + while((getline temp < tempfile)>0) + { + if (temp ~ /

information/) + { + success=1 + } + } + close(tempfile) + + if (success!=1) + { + print "Sent back to preview!" + exit INDELIVERABLE + } +} diff --git a/mrobsniped.cron b/mrobsniped.cron new file mode 100644 index 0000000..9434899 --- /dev/null +++ b/mrobsniped.cron @@ -0,0 +1,3 @@ +###mrobsniped +*/12 * * * * b /botm/bin/mrobsniped/sniped2.awk +11 6 */2 * * b /botm/bin/mrobsniped/sniped4.awk diff --git a/post.awk b/post.awk new file mode 100644 index 0000000..959a69e --- /dev/null +++ b/post.awk @@ -0,0 +1,221 @@ +BEGIN{ + FS="=" + fora="http://forums.xkcd.com" + useragent="\"mr*bdexbot (http://1190.bicyclesonthemoon.info/mrobsniped/; mr*bdex bOTTeriada post bot)\"" + + for(i=0;i<256;++i) + { + ch=sprintf("%c",i) + hex=sprintf("%02X",i); + ch2hex[ch]=hex + } +}; +{ + eq=index($0,"=") + argtab[substr($0,1,eq-1)]=substr($0,eq+1) +}; +END{ + if(system("wget -q -t 3 --connect-timeout=60 --save-cookies=" cookiefile " -U " useragent " -O " tempfile " " fora "/ucp.php?mode=login")) + { + print "Pre-login fail." + exit 1 + } + while((getline cookie < cookiefile)>0) + { + if(cookie ~ /_sid/) + { + split(cookie,arr,"_sid[ \t]*") + SID=arr[2] + } + } + close(cookiefile) + print "username=" argtab["username"] "&password=" argtab["password"] "&sid=" SID "&login=Login" > postfile + close(postfile) + if(system("wget -q -t 3 --connect-timeout=60 --save-cookies=" cookiefile " --post-file=" postfile " -U " useragent " -O " tempfile " \"" fora "/ucp.php?mode=login\"")) + { + print "Login fail." + exit 1 + } + + while((getline temp < tempfile)>0) + { + if (temp ~ /

0) + { + if(((i=match(temp, /")+1) + } + if(textarea!="") + { + if((i=match(temp, /<\/textarea/))!=0) + { + temp=substr(temp,1,i-1) + textarea="" + } + argtab["old_message"] = argtab["old_message"] urlencode(entitydecode(temp)"\n") + + } + else if(temp ~ /name=\"form_token/) + #\"#" + { + temp=substr(temp, index(temp, "value=\"")+7) + temp=substr(temp, 1, index(temp, "\"")-1) + argtab["form_token"]=urlencode(entitydecode(temp)) + } + else if(temp ~ /name=\"creation_time/) + #\"#" + { + temp=substr(temp, index(temp, "value=\"")+7) + temp=substr(temp, 1, index(temp, "\"")-1) + argtab["creation_time"]=urlencode(entitydecode(temp)) + } + else if(temp ~ /name=\"subject/) + #\"#" + { + temp=substr(temp, index(temp, "value=\"")+7) + temp=substr(temp, 1, index(temp, "\"")-1) + argtab["old_subject"]=urlencode(entitydecode(temp)) + } + if (tolower(temp) ~ /

information/) + { + print "Unexpected h2: information\n" + getline temp < tempfile + print temp + exit 1 + } + } + close(tempfile) + + printf ("subject=%s",argtab[(edit!="")?"old_subject":"subject"])>postfile + if("&addbbcode20" in argtab) + printf ("&addbbcode20=%s",argtab["addbbcode20"])>>postfile + if(edit!="") + printf ("&message=%s",argtab["old_message"] "%5Bsize%3D110%5D%5Bb%5D" argtab["subject"] "%5B%2Fb%5D%5B%2Fsize%5D%0A%5Bsize%3D80%5D" argtab["d"] "." argtab["m"] "." argtab["y"] "%20" argtab["h"] "%3A00%20GMT%5B%2Fsize%5D%0A" argtab["message"])>>postfile + else + printf ("&message=%s",argtab["message"])>>postfile + printf ("&post=%s","Submit")>>postfile + if("disable_bbcode" in argtab) + printf ("&disable_bbcode=%s",argtab["disable_bbcode"])>>postfile + if("disable_smilies" in argtab) + printf ("&disable_smilies=%s",argtab["disable_smilies"])>>postfile + if("disable_magic_url" in argtab) + printf ("&disable_magic_url=%s",argtab["disable_magic_url"])>>postfile + if("attach_sig" in argtab) + printf ("&attach_sig=%s",argtab["attach_sig"])>>postfile + if("notify" in argtab) + printf ("¬ify=%s",argtab["notify"])>>postfile + printf ("&creation_time=%s",argtab["creation_time"])>>postfile + printf ("&form_token=%s",argtab["form_token"])>>postfile + close(postfile) + + system("sleep 1") + if(system("wget -q -t 3 --connect-timeout=60 --load-cookies=" cookiefile " --save-cookies=" cookiefile " --post-file=" postfile " -U " useragent " -O " tempfile " \"" fora "/posting.php?mode="((edit!="")?"edit&f=7&p="edit:"reply&f=7&t=101043")"\"")) + { + print "Submit fail." + exit 1 + } + + while((getline temp < tempfile)>0) + { + if (temp ~ /

information/) + { + success=1 + } + } + close(tempfile) + + if (success!=1) + { + print "Sent back to preview!" + exit INDELIVERABLE + } + + while((getline cookie < cookiefile)>0) + { + if(cookie ~ /_sid/) + { + split(cookie,arr,"_sid[ \t]*") + SID=arr[2] + break + } + } + close(cookiefile) + if(system("wget -q -t 3 --connect-timeout=60 -U " useragent " -O " tempfile " \"" fora "/ucp.php?mode=logout&sid=" SID"\"")) + { + print "Logout fail." + } + + +} +function urlencode(name,all, len,iii,escaped,ch) +{ + len=length(name) + escaped="" + for(iii=1;iii<=len;++iii) + { + ch=substr(name,iii,1); + if ((ch ~ /[a-zA-Z0-9\.\-_~]/)&&(all=="")) + escaped = escaped ch + else + escaped = escaped "%" ch2hex[ch] + } + return escaped +} +function entitydecode(ht ,i,j,un,num) +# quot, amp, lt, gt, nbsp, and decimal numbered. +{ + while ((i=match(ht, /&((#[0-9]+)|([a-zA-Z]+));/))!=0)# + { + un=un substr(ht, 1, i-1) + ht=substr(ht, i) + j=index(ht, ";") + + if(ht~/^&#/) + { + num=int(substr(ht, 3, j-3)) + un=un sprintf("%c",num) + } + else + { + num=tolower(substr(ht, 2, j-2)) + if(num == "quot") + un=un "\"" + else if(num == "amp") + un=un "&" + else if(num == "lt") + un=un "<" + else if(num == "gt") + un=un ">" + else if(num == "nbsp") + un=un "\xA0" + else + un = un ht + } + ht=substr(ht, j+1) + } + un=un ht + return un +} diff --git a/sniped.awk b/sniped.awk new file mode 100644 index 0000000..c3dbf28 --- /dev/null +++ b/sniped.awk @@ -0,0 +1,40 @@ +BEGIN{ + RS="<" + FS="#" + for(i=0;i<255;++i) + { + ch=sprintf("%c",i) + hex=sprintf("%02x",i) + HEX=sprintf("%02X",i) + hex2ch[HEX]=ch + hex2ch[hex]=ch + } + #hex2ch["00"]=" " +} +{ + if($0 ~ /id=\"content\"/) #") + ok=1 + if($0 ~ /href=\"(index.html)?#contents\"/) #") + ok="" + if(ok!="") + { + if($0 ~ /class=\"bl0nk\"/) #") + a=a "0" + if($0 ~ /class=\"bl1nk\"/) #") + a=a "1" + } +} +END{ + b=length(a) + for(i=0;i> "htmltemp) + system(sleep" 2") + } + } + system(mawk" -f "snipedawk" "htmltemp" > "lasttemp) + + getline this < lasttemp + close(lasttemp) + + if(this!=last) + exit + if(this==conf) + exit + + print this > confirmd + close(confirmd) + + r13in ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + r13out="NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm" + len=length(r13in) + + for(i=1;i<=len;++i) + { + rot13[substr(r13in,i,1)]=substr(r13out,i,1) + } + + len=length(this) + for(i=1;i<=len;++i) + { + ch=substr(this,i,1) + if(ch~/[A-Za-z]/) + out=out rot13[ch] + else + out=out ch + } + print out >> result0 + close(result) + + system(mawk" -f "snipedawk3" "result0" > "result1) +} +{ + +} \ No newline at end of file diff --git a/sniped3.awk b/sniped3.awk new file mode 100644 index 0000000..72fdb20 --- /dev/null +++ b/sniped3.awk @@ -0,0 +1,38 @@ +BEGIN{ + FS="" + max=0 + lastmax="/eizm/pro/mrobsniped/lastmax" + nextpost="/eizm/pro/mrobsniped/nextpost" + getline last < lastmax + close(lastmax) + lm=int(last) +} +{ + ii=substr($0, 19, 4) + tt=substr($0, 1, 8) substr($0, 10, 4) + i=int(ii) + t=int(tt) + + if(i>max) + max=i + + if( line[i]!="" && time[i]>=t) + next + + line[i]=substr($0, 23) + sub(/^ /,"\n ",line[i]) + sub(/^ ----/,"\n----",line[i]) + sub(/^ =/,"\n=",line[i]) + time[i]=t +} +END{ + for(i=0;i<=max;++i) + { + printf ("%s",line[i]) + if (i>lm) + printf ("%s",line[i]) >> nextpost + } + close(nextpost) + print max > lastmax + close(lastmax) +} diff --git a/sniped4.awk b/sniped4.awk new file mode 100755 index 0000000..c65b172 --- /dev/null +++ b/sniped4.awk @@ -0,0 +1,82 @@ +#!/usr/bin/mawk -f +BEGIN{ + nextpost="/eizm/pro/mrobsniped/nextpost" + thispost="/eizm/pro/mrobsniped/thispost" + postfile="/eizm/pro/mrobsniped/postfile" + userpass="/eizm/mem/ottmirror/name" + tempf="tempfile=/eizm/pro/mrobsniped/tempf" + postf="postfile=/eizm/pro/mrobsniped/postf" + cookf="cookiefile=/eizm/pro/mrobsniped/cookf" + mv="/bin/mv" + mawk="/usr/bin/mawk" + postawk="/eizm/pro/mrobsniped/post.awk" + mpostawk="/eizm/pro/mrobsniped/mpost.awk" + fscmd="ls -l" + #rm="/bin/rm" + + for(i=0;i<256;++i) + { + ch=sprintf("%c",i) + hex=sprintf("%02X",i) + ch2hex[ch]=hex + } + + fscmd = fscmd " " nextpost + fscmd | getline lsline + close(fscmd) + split(lsline,lstab," ") + nextpostsize = int(lstab[5]) + +# if(nextpostsize<729) + if(nextpostsize<3300) + exit + + if(system(mv" "nextpost" "thispost)) + exit + + for(i=0;(getline line < thispost) > 0;++i) + { + if(i!=0) + line="\n"line + post=post line + } + close(thispost) + + getline name < userpass + getline pass < userpass + close(userpass) + + post="the [url=http://1190.bicyclesonthemoon.info/mrobsniped/mrobdexmessage-onlytext.txt]mr*bdex story[/url] cONGtinues.\n[quote]"post"[/quote]\n[right][size=85]-- posted by mr[img]http://1190.bicyclesonthemoon.info/ott/attachment/41728[/img]bdexbot[/size][/right]" + + print "username="name > postfile + print "password="pass >>postfile + print "subject="urlencode("bOTTeriada goes ONG") >>postfile + print "addbbcode20=100" >>postfile + print "message="urlencode(post,1) >>postfile + print "disable_magic_url=on" + + close(postfile) + + if(system(mawk" -f "postawk" -v "postf" -v "tempf" -v "cookf" "postfile)!=0) + system(mawk" -f "mpostawk" -v "postf" -v "tempf" -v "cookf" "postfile) + + #system(rm" "thispost) + #system(rm" "postfile) +} +{ + +} +function urlencode(name,all, len,iii,escaped,ch) +{ + len=length(name) + escaped="" + for(iii=1;iii<=len;++iii) + { + ch=substr(name,iii,1); + if ((ch ~ /[a-zA-Z0-9\.\-_~]/)&&(all=="")) + escaped = escaped ch + else + escaped = escaped "%" ch2hex[ch] + } + return escaped +} \ No newline at end of file diff --git a/test.awk b/test.awk new file mode 100644 index 0000000..04f2753 --- /dev/null +++ b/test.awk @@ -0,0 +1,3 @@ +{ + print length($0) +} \ No newline at end of file