From: b Date: Tue, 25 May 2021 20:33:49 +0000 (+0000) Subject: Update from src as of 25.05.2021 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=HEAD;p=ott%2Faftertime Update from src as of 25.05.2021 --- diff --git a/bot4.awk b/bot4.awk index d83e267..2610000 100644 --- a/bot4.awk +++ b/bot4.awk @@ -1,463 +1,496 @@ -#// bot4.awk -#// The bot to post frames to the OTT -#// 19.06.2018- -#// -#// Copyright (C) 2015, 2018 Balthasar Szczepański -#// -#// This program is free software: you can redistribute it and/or modify -#// it under the terms of the GNU Affero General Public License as -#// published by the Free Software Foundation, either version 3 of the -#// License, or (at your option) any later version. -#// -#// This program is distributed in the hope that it will be useful, -#// but WITHOUT ANY WARRANTY; without even the implied warranty of -#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -#// GNU Affero General Public License for more details. -#// -#// You should have received a copy of the GNU Affero General Public License -#// along with this program. If not, see . - -BEGIN{ - FS="" - # noticepath="/eizm/mem/aftertime/mpost/" - # framepath="/eizm/www/time/" - datapath="/eizm/data/aftertime/" - timecmd="date" - timecmd2="date -u +%N%s" - lastpath ="/eizm/mem/aftertime/lastong/" - temppath ="/eizm/tmp/aftertime/" - ott_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&start=" - tto_address="http://1190.bicyclesonthemoon.info/ott/view?start=" - mstd_address="http://1190.bicyclesonthemoon.info/ott/mview?start=" - lastpost_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&sd=d" - - wget="/usr/bin/wget" - rm="/bin/rm" - perl="/usr/bin/perl" - mawk="/usr/bin/mawk" - automome="/eizm/pro/ong1/mome.pl" - memedef="/eizm/mem/ong1/mome.txt" - - postawk="/eizm/pro/aftertime/post.awk" - mpostawk="/eizm/pro/aftertime/mpost.awk" - - # timecmd2="date +\"%H%M%S\"" - botcastleurl="http://1190.bicyclesonthemoon.info" - - if(enhance!="" && int(enhance)!="0") - { - enh=int(enhance) - ext="-"enh - } - else - { - ext="" - enh=0 - } - - f=int(frame) - timecmd | getline thistime - close(timecmd) - - timecmd2 | getline ID - close(timecmd2) - ID=int(ID/3600) - ID =int(ID%9999) - - for(i=0;i<256;++i) - { - ch=sprintf("%c",i) - hex=sprintf("%02X",i); - ch2hex[ch]=hex - } - - statefile= datapath story"/ongstate" - getline temp < statefile - close(statefile) - - split(temp, temptab, " ") - state=int(temptab[1]) - last=int(temptab[2]) - - if(frame=="") - f=last - - # srand(ID + f) - # for(i=0;i0) - { - if(temp ~ regexp) - { - print "Newpage "page" - already ONGed." - system(rm" -f "tempfile) - print page" "f > lasttime - close(lasttime) - exit 1 - } - gsub(/<[^<>]*>/,"",temp) - gsub(/ +/," ",temp) - temp2=tolower(temp) - if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0) - { - temp2=substr(temp2,i) - temp2=substr(temp2,index(temp2,"of")+3)" " - temp2=substr(temp2,1,index(temp2," ")-1) - lastpage=int(temp2) - } - temp2=tolower(temp) - if((i=match(temp2,/[0-9]+ posts/))!=0) - { - temp2=substr(temp2,index(temp2,"")-1) - posts=int(temp2) - if(posts%40==0) - pope=1 - else - pope="" - } - } - close(tempfile) - print "Newpage "page" - nothing found." - } - mlastpage=1 - for(mpage=1;mpage<=mlastpage;++mpage) - { - url= "\""mstd_address (mpage-1)*40"\"" - - cmd= wget " -q -O "tempfile" -U "useragent" "url - if(system(cmd)!=0) - { - print "Mustardtime newpage "mpage" not downloaded." - break - } - for(j=0;(getline temp < tempfile)>0;++j) - { - if(temp ~ regexp) - { - print "Newpage "mpage" - already ONGed." - system(rm" -f "tempfile) - #writeout - exit 1 - } - gsub(/<[^<>]*>/,"",temp) - gsub(/ +/," ",temp) - temp2=tolower(temp) - if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0) - { - temp2=substr(temp2,i) - temp2=substr(temp2,index(temp2,"of")+3) - temp2=substr(temp2,1,index(temp2," ")-1) - mlastpage=int(temp2) - } - temp2=tolower(temp) - if((i=match(temp2,/[0-9]+ posts/))!=0) - { - temp2=substr(temp2,index(temp2,"")-1) - posts=int(temp2) - if(posts%40==0) - pope=1 - else - pope="" - } - } - close(tempfile) - print "Mustradtime newpage "mpage" - nothing found." - } - } - - if(argtab["nomeme"]=="") - { - print "Ok, can ONG. Now generate ONGtext" - cmd = perl" "automome" -lc 150 -n 67 -d "memedef (pope!=""?" -t \"[decrall]\"":"") - while ((cmd | getline temp)>0) - { - if(sub(/[AEIOUY]-N-G/,"[b]O-N-G[/b]",temp)>0) - { - ongtext= prepare(temp) - break - } - if(sub(/O+N+G+/,"[b]&[/b]",temp)>0) - { - ongtext= prepare(temp) - break - } - if(sub(/DON'T/,"D[b]ON'G[/b]T",temp)>0) - { - ongtext= prepare(temp) - break - } - if(sub(/[AEIOUY]NG/,"[b]ONG[/b]",temp)>0) - { - if($0!~/TH\[b\]ONG/) - { - ongtext= prepare(temp) - break - } - } - if(sub(/ON G/,"[b]ON G[/b] ",temp)>0) - { - ongtext= prepare(temp) - break - } - if(sub(/ON /,"[b]ONG[/b] ",temp)>0) - { - ongtext= prepare(temp) - break - } - if(sub(/O\.?$/,"[b]ONG[/b] ",temp)>0) - { - ongtext= prepare(temp) - break - } - } - close(cmd) - - if(ongtext=="") - ongtext="ONG" - print ongtext - } - else - ongtext="ONG" - - cmd= wget " -q -O "tempfile" -U "useragent" \""lastpost_address"\"" - if(system(cmd)!=0) - { - print "Can't check last post" - # system(rm" -f "tempfile) - # exit 1 - } - - else - { - while((getline temp < tempfile)>0) - { - if ((i=match(temp, /id=\"p[0-9]+\"/))!=0) #" - { - temp2=substr(temp, i+5) - lastpostid=substr(temp2, 1, index(temp2,"\"")-1) - } - - if (temp ~ /class=\"postprofile\"/) #" - postprofile = "1" - - else if (postprofile=="") - continue - - if(temp ~ /memberlist\.php.*mode=viewprofile[^<>]*>[^<>]+<\/a/) - { - temp2=substr(temp, index(temp, ">")+1) - lastusername=substr(temp2, 1, index(temp2,"<")-1) - break - } - } - close(tempfile) - if(lastusername=="" || lastpostid=="") - { - print "Can't check last post" - # system(rm" -f "tempfile) - # exit 1 - } - } - - srand(ID+lastpostid+f) - - if(rand()<(argtab["npbprob"]+0)) - { - print "Also, let's do some NewpixbOTTification!" - npbsel="npbframe"ext - } - else - npbsel="frame"ext - - - - framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") - - print "username="urlencode(username) > tempfile - print "password="urlencode(password,1) >> tempfile - print "subject="urlencode(sprintf(argtab["subject"ext],f)) >> tempfile - print "message="urlencode(ongtext"\n[url="botcastleurl"/aftertime/viewer?story="argtab["story"]"&f="f((enh>0)?"&e="enh:"")"][img]"botcastleurl framedir sprintf(argtab[npbsel],f)"[/img][/url][spoiler]"alt"[/spoiler]\n[right][size=80] -- posted by "botname"[/size][/right]") >> tempfile - print "Send post" - - cmd= mawk" -f "postawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t((lastpostid!="" && lastusername!="")?" -v edit="lastpostid" -v user=\""lastusername"\"":"")" "tempfile - cmd2= mawk" -f "mpostawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t" "tempfile - - if(system(cmd)!=0) - { - print "Can't post, try again from mirror" - if(system(cmd2)!=0) - { - print "CAN'T POST EITHER!" - system(rm" -f "tempfile) - system(rm" -f "tempfile_t) - system(rm" -f "tempfile_c) - system(rm" -f "tempfile_p) - exit 1 - } - } - print "ONGed" - system(rm" -f "tempfile) - system(rm" -f "tempfile_t) - system(rm" -f "tempfile_c) - system(rm" -f "tempfile_p) - if(force=="") - { - print lastpage" "f > lasttime - close(lasttime) - } - - -} -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-z]|[A-Z]|[0-9]/ && all=="") - escaped = escaped ch - else - escaped = escaped "%" ch2hex[ch] - } - return escaped -}; -function prepare(rh) -{ - gsub(/\*\*/,"¤",rh) - gsub(/\*[^\*]+\*/,"±&±",rh) - gsub(/±\*/,"[i]",rh) - gsub(/\*±/,"[/i]",rh) - gsub(/¤/,"*",rh) - - gsub(/__/,"¤",rh) - gsub(/_[^_]+_/,"±&±",rh) - gsub(/±_/,"[u]",rh) - gsub(/_±/,"[/u]",rh) - gsub(/¤/,"_",rh) - - gsub(/\$\$/,"¤",rh) - gsub(/\$[^\$]+\$/,"±&±",rh) - gsub(/±\$/,"[size=80]",rh) - gsub(/\$±/,"[/size]",rh) - gsub(/¤/,"$",rh) - - return rh " -- [url=http://1190.bicyclesonthemoon.info/ongtext?b=on][b]ong[/b]o[/url][url=http://mrob.com/time/automome/]mome[/url]" -} +#// bot4.awk +#// The bot to post frames to the OTT +#// 24.04.2021 +#// +#// Copyright (C) 2015, 2018-2019, 2021 Balthasar Szczepański +#// +#// This program is free software: you can redistribute it and/or modify +#// it under the terms of the GNU Affero General Public License as +#// published by the Free Software Foundation, either version 3 of the +#// License, or (at your option) any later version. +#// +#// This program is distributed in the hope that it will be useful, +#// but WITHOUT ANY WARRANTY; without even the implied warranty of +#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#// GNU Affero General Public License for more details. +#// +#// You should have received a copy of the GNU Affero General Public License +#// along with this program. If not, see . + +BEGIN{ + FS="" + # noticepath="/eizm/mem/aftertime/mpost/" + # framepath="/eizm/www/time/" + datapath="/eizm/data/aftertime/" + timecmd="date" + timecmd2="date -u +%N%s" + lastpath ="/eizm/mem/aftertime/lastong/" + temppath ="/eizm/tmp/aftertime/" + ott_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&start=" + tto_address="http://1190.bicyclesonthemoon.info/ott/view?start=" + mstd_address="http://1190.bicyclesonthemoon.info/ott/mview?start=" + lastpost_address="http://forums.xkcd.com/viewtopic.php?f=7&t=101043&sd=d" + + wget="/usr/bin/wget" + rm="/bin/rm" + perl="/usr/bin/perl" + mawk="/usr/bin/mawk" + automome="/eizm/pro/ong1/mome.pl" + memedef="/eizm/mem/ong1/mome.txt" + + postawk="/eizm/pro/aftertime/post.awk" + mpostawk="/eizm/pro/aftertime/mpost.awk" + + # timecmd2="date +\"%H%M%S\"" + botcastleurl="http://1190.bicyclesonthemoon.info" + + if(enhance!="" && int(enhance)!="0") + { + enh=int(enhance) + ext="-"enh + } + else + { + ext="" + enh=0 + } + + f=int(frame) + timecmd | getline thistime + close(timecmd) + + timecmd2 | getline ID + close(timecmd2) + ID=int(ID/3600) + ID =int(ID%9999) + + for(i=0;i<256;++i) + { + ch=sprintf("%c",i) + hex=sprintf("%02X",i); + ch2hex[ch]=hex + } + + statefile= datapath story"/ongstate" + getline temp < statefile + close(statefile) + + split(temp, temptab, " ") + state=int(temptab[1]) + last=int(temptab[2]) + + if(frame=="") + f=last + + # srand(ID + f) + # for(i=0;i0) + { + gsub(/[\r\n]/, "", line) + + if (line == "" && !undertext) + { + undertext=1 + argtab["text"]="" + continue + } + + if (undertext) + { + argtab["text"] = argtab["text"] line "\n" + } + else + { + + eq=index(line, "=") + argtab[substr(line, 1, eq-1)]=substr(line, eq+1) + } + } + close (specialfile) + } + + + botfile=datapath argtab["story"]"/"ongbot + getline botname < botfile + getline username < botfile + getline password < botfile + gsub(/[\r\n]/, "", botname) + gsub(/[\r\n]/, "", username) + gsub(/[\r\n]/, "", password) + close(botfile) + + if (botname =="" || username=="" || password=="") + { + print "Can't get login and password." + exit 1 + } + print botname + + useragent = "\""botname" (time after Time post bot; http://1190.bicyclesonthemoon.info/aftertime; story="argtab["story"]"; frame "f")\"" + + temp="" + lasttime = lastpath argtab["story"] ext + getline temp < lasttime + close(lasttime) + + split(temp, temptab, " ") + lastpage=int(temptab[1]) + lastframe=int(temptab[2]) + + print "Start with page "lastpage", last frame was "lastframe", current frame is "f"." + if(f <= lastframe && force=="") + { + print "Already ONGed." + exit 1 + } + + if(force=="") + { + temp=argtab["match"ext] + for(i=0;(j=index(substr(temp,2),"%"))!=0;++i) + { + temp2=substr(temp,1,j) + temp=substr(temp,j+1) + regexp = regexp sprintf(temp2,f) + } + regexp = regexp sprintf(temp,f) + print "match "regexp + + for(page=lastpage;page<=lastpage;++page) + { + url= "\""ott_address (page-1)*40"\"" + url2= "\""tto_address (page-1)*40"\"" + + cmd= wget " -q -O "tempfile" -U "useragent" "url + cmd2= wget " -q -O "tempfile" -U "useragent" "url2 + # print "! "cmd" !" + if(system(cmd)!=0) + { + print "Newpage "page" download fail. Retry from mirror." + if(system(cmd2)!=0) + { + print "Newpage "page" download fail." + system(rm" -f "tempfile) + exit 1 + } + } + while((getline temp < tempfile)>0) + { + if(temp ~ regexp) + { + print "Newpage "page" - already ONGed." + system(rm" -f "tempfile) + print page" "f > lasttime + close(lasttime) + exit 1 + } + gsub(/<[^<>]*>/,"",temp) + gsub(/ +/," ",temp) + temp2=tolower(temp) + if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0) + { + temp2=substr(temp2,i) + temp2=substr(temp2,index(temp2,"of")+3)" " + temp2=substr(temp2,1,index(temp2," ")-1) + lastpage=int(temp2) + } + temp2=tolower(temp) + if((i=match(temp2,/[0-9]+ posts/))!=0) + { + temp2=substr(temp2,index(temp2,"")-1) + posts=int(temp2) + if(posts%40==0) + pope=1 + else + pope="" + } + } + close(tempfile) + print "Newpage "page" - nothing found." + } + mlastpage=1 + for(mpage=1;mpage<=mlastpage;++mpage) + { + url= "\""mstd_address (mpage-1)*40"\"" + + cmd= wget " -q -O "tempfile" -U "useragent" "url + if(system(cmd)!=0) + { + print "Mustardtime newpage "mpage" not downloaded." + break + } + for(j=0;(getline temp < tempfile)>0;++j) + { + if(temp ~ regexp) + { + print "Newpage "mpage" - already ONGed." + system(rm" -f "tempfile) + print page" "f > lasttime + close(lasttime) + + exit 1 + } + gsub(/<[^<>]*>/,"",temp) + gsub(/ +/," ",temp) + temp2=tolower(temp) + if((i=match(temp2,/page [0-9]+ of [0-9]+/))!=0) + { + temp2=substr(temp2,i) + temp2=substr(temp2,index(temp2,"of")+3) + temp2=substr(temp2,1,index(temp2," ")-1) + mlastpage=int(temp2) + } + temp2=tolower(temp) + if((i=match(temp2,/[0-9]+ posts/))!=0) + { + temp2=substr(temp2,index(temp2,"")-1) + posts=int(temp2) + if(posts%40==0) + pope=1 + else + pope="" + } + } + close(tempfile) + print "Mustradtime newpage "mpage" - nothing found." + } + } + + if(argtab["nomeme"]=="") + { + print "Ok, can ONG. Now generate ONGtext" + cmd = perl" "automome" -lc 150 -n 67 -d "memedef (pope!=""?" -t \"[decrall]\"":"") + while ((cmd | getline temp)>0) + { + if(sub(/[AEIOUY]-N-G/,"[b]O-N-G[/b]",temp)>0) + { + ongtext= prepare(temp) + break + } + if(sub(/O+N+G+/,"[b]&[/b]",temp)>0) + { + ongtext= prepare(temp) + break + } + if(sub(/DON'T/,"D[b]ON'G[/b]T",temp)>0) + { + ongtext= prepare(temp) + break + } + if(sub(/[AEIOUY]NG/,"[b]ONG[/b]",temp)>0) + { + if($0!~/TH\[b\]ONG/) + { + ongtext= prepare(temp) + break + } + } + if(sub(/ON G/,"[b]ON G[/b] ",temp)>0) + { + ongtext= prepare(temp) + break + } + if(sub(/ON /,"[b]ONG[/b] ",temp)>0) + { + ongtext= prepare(temp) + break + } + if(sub(/O\.?$/,"[b]ONG[/b] ",temp)>0) + { + ongtext= prepare(temp) + break + } + } + close(cmd) + + if(ongtext=="") + ongtext="ONG" + print ongtext + } + else + ongtext="ONG" + + cmd= wget " -q -O "tempfile" -U "useragent" \""lastpost_address"\"" + if(system(cmd)!=0) + { + print "Can't check last post" + # system(rm" -f "tempfile) + # exit 1 + } + + else + { + while((getline temp < tempfile)>0) + { + if ((i=match(temp, /id=\"p[0-9]+\"/))!=0) #" + { + temp2=substr(temp, i+5) + lastpostid=substr(temp2, 1, index(temp2,"\"")-1) + } + + if (temp ~ /class=\"postprofile\"/) #" + postprofile = "1" + + else if (postprofile=="") + continue + + if(temp ~ /memberlist\.php.*mode=viewprofile[^<>]*>[^<>]+<\/a/) + { + temp2=substr(temp, index(temp, ">")+1) + lastusername=substr(temp2, 1, index(temp2,"<")-1) + break + } + } + close(tempfile) + if(lastusername=="" || lastpostid=="") + { + print "Can't check last post" + # system(rm" -f "tempfile) + # exit 1 + } + } + + srand(ID+lastpostid+f) + + if(rand()<(argtab["npbprob"]+0)) + { + print "Also, let's do some NewpixbOTTification!" + npbsel="npbframe"ext + } + else + npbsel="frame"ext + + + + framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") + + print "username="urlencode(username) > tempfile + print "password="urlencode(password,1) >> tempfile + print "subject="urlencode(sprintf(argtab["subject"ext],f,"")) >> tempfile + print "message="urlencode(ongtext"\n[url="botcastleurl"/aftertime/viewer?story="argtab["story"]"&f="f((enh>0)?"&e="enh:"")"][img]"botcastleurl framedir sprintf(argtab[npbsel],f,"")"[/img][/url]"((argtab["text"]!="")?("\n"argtab["text"]):"")"[spoiler]"alt"[/spoiler]\n[right][size=80] -- posted by "botname"[/size][/right]") >> tempfile + print "Send post" + + cmd= mawk" -f "postawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t((lastpostid!="" && lastusername!="")?" -v edit="lastpostid" -v user=\""lastusername"\"":"")" "tempfile + cmd2= mawk" -f "mpostawk" -v postfile="tempfile_p" -v cookiefile="tempfile_c" -v tempfile="tempfile_t" "tempfile + + if(system(cmd)!=0) + { + print "Can't post, try again from mirror" + if(system(cmd2)!=0) + { + print "CAN'T POST EITHER!" + system(rm" -f "tempfile) + system(rm" -f "tempfile_t) + system(rm" -f "tempfile_c) + system(rm" -f "tempfile_p) + exit 1 + } + } + print "ONGed" + system(rm" -f "tempfile) + system(rm" -f "tempfile_t) + system(rm" -f "tempfile_c) + system(rm" -f "tempfile_p) + if(force=="") + { + print lastpage" "f > lasttime + close(lasttime) + } + + +} +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-z]|[A-Z]|[0-9]/ && all=="") + escaped = escaped ch + else + escaped = escaped "%" ch2hex[ch] + } + return escaped +}; +function prepare(rh) +{ + gsub(/\*\*/,"¤",rh) + gsub(/\*[^\*]+\*/,"±&±",rh) + gsub(/±\*/,"[i]",rh) + gsub(/\*±/,"[/i]",rh) + gsub(/¤/,"*",rh) + + gsub(/__/,"¤",rh) + gsub(/_[^_]+_/,"±&±",rh) + gsub(/±_/,"[u]",rh) + gsub(/_±/,"[/u]",rh) + gsub(/¤/,"_",rh) + + gsub(/\$\$/,"¤",rh) + gsub(/\$[^\$]+\$/,"±&±",rh) + gsub(/±\$/,"[size=80]",rh) + gsub(/\$±/,"[/size]",rh) + gsub(/¤/,"$",rh) + + return rh " -- [url=http://1190.bicyclesonthemoon.info/ongtext?b=on][b]ong[/b]o[/url][url=http://mrob.com/time/automome/]mome[/url]" +} diff --git a/compare-t-1.awk b/compare-t-1.awk new file mode 100644 index 0000000..2aab0e9 --- /dev/null +++ b/compare-t-1.awk @@ -0,0 +1,33 @@ +BEGIN{ + # for(i=1; i<=828; ++i) + # { + # f=sprintf("%04d",i) + # cmpcmd="/eizm/pro/aftertime/compare /eizm/www/time/aftertime/t-1/t-1_"f".png /eizm/data/aftertime/testaftertime/t-1/t-1_"f".png" + + # printf("%s","t-1_"f".png ") + + # # print cmpcmd + # system (cmpcmd) + # } + for(i=1; i<=828; ++i) + { + f=sprintf("%04d",i) + cmpcmd="/eizm/pro/aftertime/compare /eizm/www/time/aftertime/t-1/remapt-1_"f".png /eizm/data/aftertime/testaftertime/t-1/remapt-1_"f".png" + cpcmd="/bin/cp /eizm/data/aftertime/testaftertime/t-1/remapt-1_"f".png /eizm/www/time/aftertime/t-1/mustardremapt-1_"f".png" + + printf("%s","remapt-1_"f".png ") + + # print cmpcmd + # system (cmpcmd) + + cmpcmd | getline line + close(cmpcmd) + print line + if (line!="identical.") + { + system(cpcmd) + print "upload "f"." + } + } + +} diff --git a/convert1.awk b/convert1.awk new file mode 100644 index 0000000..b9b4bf6 --- /dev/null +++ b/convert1.awk @@ -0,0 +1,16 @@ +BEGIN{ + print "SilentTimer\n5TkxDBIL21OyEGwkdTR2EQYwdYC5F4\n" +} +{ + y=substr($1, 1, 4) + m=substr($1, 5, 2) + d=substr($1, 7, 2) + h=substr($1, 9, 2) + + if($NF !~ /^t1i-[0-9]+$/) + next + + id= $NF "-1" + + print y"-"m"-"d" "h"\nq\n" +} \ No newline at end of file diff --git a/convert2.awk b/convert2.awk new file mode 100644 index 0000000..2bf3c69 --- /dev/null +++ b/convert2.awk @@ -0,0 +1,47 @@ +BEGIN{ + FS="" + print "SilentTimer\n5TkxDBIL21OyEGwkdTR2EQYwdYC5F4\n" + i=0 +} +{ + ind=index($0, " ") + id=substr($0, 1, ind-1) + value=substr($0, ind+1) + ind=index(value," ") + name=substr(value, 1, ind-1) + value=substr(value, ind+1) + + if (tab[id]=="") + { + list[i]=id + tab[id]=id + ++i + } + tab[id"-"name]=value +} +END{ + for(j=0;jthis_sf && argtab["cfrt"]=="") s=this_sf @@ -116,7 +118,7 @@ END{ if(argtab["special"] != "") { - specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f) + specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s) line="" undertext="" @@ -146,19 +148,19 @@ END{ } framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") - if(sf!="") - { + # if(sf!="") + # { frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) if (system("[ -f " framepath frame" ]")!=0) frame= framedir sprintf(argtab["frame"],f,s) - } - else - { - s="" - frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) - if (system("[ -f " framepath frame" ]")!=0) - frame=framedir sprintf(argtab["frame"],f) - } + # } + # else + # { + # s="" + # frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) + # if (system("[ -f " framepath frame" ]")!=0) + # frame=framedir sprintf(argtab["frame"],f) + # } if(f==last && state==1) { diff --git a/info.awk b/info.awk index 47bd110..949a124 100644 --- a/info.awk +++ b/info.awk @@ -1,6 +1,6 @@ #// info.awk #// Info about an aftertime story. -#// 7.01.2019 +#// 10.03.2019 #// #// Copyright (C) 2015-2016, 2018-2019 Balthasar Szczepański #// @@ -239,7 +239,7 @@ END{ if(argtab["special"] != "") { - specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f) + specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s) line="" undertext="" @@ -302,26 +302,26 @@ END{ numberformat=argtab["number"] else { - if (sf!="") + # if (sf!="") numberformat="%u%s" - else - numberformat="%u" + # else + # numberformat="%u" } framedir= "/aftertime/"argtab["story"]"/" - if(sf!="") - { + # if(sf!="") + # { title=sprintf(argtab["title"(e>0 ? "-"e : "")],f,s2) frame=framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"]),s2) - } - else - { - s="" - title=sprintf(argtab["title"(e>0 ? "-"e : "")],f) - frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) - otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"])) - } + # } + # else + # { + # s="" + # title=sprintf(argtab["title"(e>0 ? "-"e : "")],f) + # frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) + # otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"])) + # } if (system("[ -f " framepath frame" ]")!=0) exit 0 @@ -342,10 +342,10 @@ END{ { for(i=0;i<=max_enhance;++i) { - if(sf!="") + # if(sf!="") enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f,s) - else - enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f) + # else + # enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f) if (system("[ -f " framepath enhancedframe" ]")==0) print "enhance-"i"="argtab["enhance-"i] diff --git a/mpview.c b/mpview.c index b1fbfd6..0f3f013 100644 --- a/mpview.c +++ b/mpview.c @@ -59,7 +59,7 @@ int main() sprintf(key,"key=%s",arg?arg:"???"); // sprintf(filename,"%s",line); - sprintf(postpath,"%s%s",POST_PATH,line); + sprintf(postpath,"%s%s",POST_PATH,line);//UNSAFE! (2019) sprintf(path2,"%s%lu",TEMP_PATH,(unsigned long)getpid()); diff --git a/ong-bsta.awk b/ong-bsta.awk index 179f41b..487d049 100644 --- a/ong-bsta.awk +++ b/ong-bsta.awk @@ -1,6 +1,6 @@ #// ong-bsta.awk #// The bot to ketchup frames from the bsta viewer -#// 6.01.2019 +#// 6.09.2019 #// #// Copyright (C) 2019 Balthasar Szczepański #// @@ -333,8 +333,8 @@ function bb2bb (text) gsub(/\[(fq|tq)\]/, "[quote]", text) gsub(/\[\/(fq|tq)\]/, "[/quote]", text) gsub(/\[br\]/, "[color=#BB6622]", text) - gsub(/\[ni\]/, "[color=#FF8800]", text) - gsub(/\[po\]/, "[color=#0057AF]", text) + gsub(/\[ni\]/, "[color=#0057AF]", text) + gsub(/\[po\]/, "[color=#FF8800]", text) gsub(/\[\/(br|ni|po)\]/, "[/color]", text) return htmlescape(text,"","br") diff --git a/ong-mscha-t-1.awk b/ong-mscha-t-1.awk index b8d1318..7f03aa3 100644 --- a/ong-mscha-t-1.awk +++ b/ong-mscha-t-1.awk @@ -1,8 +1,8 @@ #// ong-mscha-t-1.awk #// The bot to ketchup frames from the mschaviewer, and enhance by remapping -#// 21.12.2015 +#// 12.02.2019 #// -#// Copyright (C) 2015 Balthasar Szczepański +#// Copyright (C) 2015, 2019 Balthasar Szczepański #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as @@ -44,10 +44,16 @@ BEGIN{ END{ if (file=="") + { + print "No data." exit 1 + } if(argtab["ongoing"]!="2") + { + print "Story is not externally onged." exit 1 + } # timecmd | getline thistime # close(timecmd) @@ -71,15 +77,19 @@ END{ optionfile = datapath argtab["story"]"/settings" framedir = "aftertime/"argtab["story"]"/" - system("sleep 15") + # system("sleep 15") while(1) { + + timecmd | getline thistime close(timecmd) timetext = substr(thistime,1,10); timenumber = substr(thistime,11); + print f" "timetext" "timenumber + newalt="" frameurl= sprintf(argtab["otherviewerframe"],f) viewerurl= sprintf(argtab["otherviewerurl"],f) @@ -99,11 +109,17 @@ END{ addhashcmd= mawk" -f "uploadawk" -v timenumber="timenumber" -v timetext="timetext" -v tempfile="tempfile" "tempfile2 if(system(getfcmd)!=0) + { + print "Frame download failed: "getfcmd break - system("sleep 5") + } + system("sleep 2") if(system(getvcmd)!=0) + { + print "Viewer download failed: "getvcmd break + } system("sleep 1") foundalt="" @@ -115,12 +131,14 @@ END{ newalt=substr(temp,index(temp,"title=\"")+7) newalt=substr(newalt,1,index(newalt,"\"")-1) foundalt=1 + print "alt: "newalt } if(index(temp,"class=\"hash\"")!=0 && foundpal=="" ) { pal=substr(temp,index(temp,">")+1) pal=substr(pal,1,index(pal,".")-1) foundpal=1 + print "pal: "pal } if(foundalt!="" && foundpal!="") break; diff --git a/ong.awk b/ong.awk index 9da5f24..f6dc1ab 100644 --- a/ong.awk +++ b/ong.awk @@ -1,8 +1,8 @@ #// ong.awk #// The bot to ONG new frames to the viewer. -#// 05.01.2019 +#// 28.08.2020 #// -#// Copyright (C) 2015, 2018-2019 Balthasar Szczepański +#// Copyright (C) 2015, 2018-2020 Balthasar Szczepański #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as @@ -31,6 +31,7 @@ BEGIN{ mawk="/usr/bin/mawk" bot4awk="/eizm/pro/aftertime/bot4.awk" chmod="/bin/chmod" + npb="/eizm/pro/ong1/npb" timecmd2 | getline thistime2 close(timecmd2) @@ -40,6 +41,15 @@ BEGIN{ # close(timecmd) thistime3 -= thistime3%3600 + + for(i=0;i<256;++i) + { + ch=sprintf("%c",i) + hex=sprintf("%02X",i) + dec=sprintf("%u",i) + ch2hex[ch]=hex + ch2dec[ch]=dec + } } { file=1 @@ -84,24 +94,51 @@ END{ last=int(temptab[2]) nextong=int(temptab[3]) ongfailcount=int(temptab[4]) + enhance=int(argtab["enhance"]) + + specialtab[0]="" + effectivetab[0]="" # temp="" # updatefile= datapath argtab["story"]"/update" # getline temp < updatefile # close(updatefile) + timefile= datapath argtab["story"]"/ongtime" + if (state == 1 || state ==2) { updatefail="" temp="" updatefile= datapath argtab["story"]"/update" + # timefile= datapath argtab["story"]"/ongtime" + + updated="" while((getline temp < updatefile)>0) { - if (temp !~ /^([0-9]+)|(c)$/) + if (temp !~ /^([0-9]+[a-z]?)|(c)$/) continue - i = int(temp) + if(timeread=="") + { + while((getline line < timefile)>0) + { + ongind=index(line," ") + ongft=substr(line,1,ongind-1) + ongt=substr(line,ongind+1) + + if(ongft ~ /^[0-9]+[a-z]$/) + ongf=int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) + else + ongf=int(ongft) + + timetab[ongft]=ongt + } + close(timefile) + timeread=1 + } + if(temp=="c") { print "Update CFRT." @@ -110,141 +147,132 @@ END{ print "There is no cfrt frame." continue } - inframe= datapath argtab["story"]"/"argtab["cfrt"] + inframe[0]= datapath argtab["story"]"/"argtab["cfrt"] - frame= framepath framedir argtab["cfrt"] + frame[0]= framepath framedir argtab["cfrt"] - cpcmd = cp" "inframe" "frame - chmodcmd = chmod" +r "frame + cpcmd[0] = cp" "inframe[0]" "frame[0] + chmodcmd[0] = chmod" +r "frame[0] } else { - print "Update frame "i"." + if (temp ~ /[a-z]$/) + { + i=int(substr(temp,1,length(temp)-1)) + j=substr(temp, length(temp)) + } + else + { + i = int(temp) + j = "" + } + + print "Update frame "i j"." + + if(argtab["special"] != "") + { + specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],i,j) + readspecialfile(specialfile,argtab,specialtab,effectivetab) + } + else + { + readspecialfile("",argtab,specialtab,effectivetab) + } if ((i < int(argtab["first"]))||(i > last)) { - print (i" not onged yet.") + print (i j" not onged yet.") continue } - inframe= datapath argtab["story"]"/"sprintf(argtab["inframe"],i) - frame= framepath framedir sprintf(argtab["frame"],i) - npbframe= framepath framedir sprintf(argtab["npbframe"],i) - - npbcmd= sprintf("/eizm/pro/ong1/npb %s %s q",inframe,npbframe) - cpcmd = cp" "inframe" "frame - chmodcmd = chmod" +r "frame + if(j!="") + { + if(argtab["sf-"i]=="") + { + print (i" doesn't have meteor frames.") + continue + } + else if(j > argtab["sf-"i]) + { + print (j" is not a meteor frame of "i".") + continue + } + + } + for (k=0; k<=enhance; ++k) + { + k2=(k>0)?("-"k):"" + inframe[k]= datapath argtab["story"]"/"sprintf(effectivetab["inframe"k2],i,j) + + frame[k]= framepath framedir sprintf(effectivetab["frame"k2],i,j) + npbframe[k]= framepath framedir sprintf(effectivetab["npbframe"k2],i,j) + + npbcmd[k]= npb" "inframe[k]" "npbframe[k]" q" + cpcmd[k] = cp" "inframe[k]" "frame[k] + chmodcmd[k] = chmod" +r "frame[k] + } + if (specialtab["text"]!="") + { + specialtab["HTML"]=bb2html(specialtab["text"]) + writespecialfile(specialfile,specialtab) + # print debug + } + } + + if(temp!="c" && timetab[sprintf("%04u%s",i,j)]=="") + { + print sprintf("%04u%s",i,j)" "thistime2 >> timefile + close(timefile) + timetab[sprintf("%04u%s",i,j)]=thistime2 } - if((argtab["npbframe"]!="") && (temp!="c")) + + for(k=0; k<=enhance; ++k) { - if(system(npbcmd)!=0) + k2=(k>0)?("-"k):"" + + if ((system("[ -f " inframe[k]" ]")!=0)&&(k>0)) + continue + + if((argtab["npbframe"]!="") && (temp!="c")) { - print i" NewpixbOTTification failed." + if(system(npbcmd[k])!=0) + { + print i j k2" NewpixbOTTification failed." + updatefail=1 + break + } + } + if(system(cpcmd[k])!=0) + { + print i j k2" Upload failed." updatefail=1 - continue + break + } + if(system(chmodcmd[k])!=0) + { + print "Chmod failed." + updatefail=1 + break + } + if(temp=="c") + { + break } } - if(system(cpcmd)!=0) - { - print "Upload failed." - updatefail=1 - continue - } - if(system(chmodcmd)!=0) + if (updatefail) { - print "Chmod failed." - updatefail=1 - continue + break #come up with other aproach } + updated=1 print "Updated." } close(updatefile) - if (!updatefail) + if (!updatefail && updated) { print "" > updatefile close(updatefile) } } - # # temp ="remove this line!" - # if (temp != "") - # { - # print "Update requested." - # updatefail="" - - # if(state>2 || state <1) - # { - # print "Can't update in this state" - # } - # else - # { - # for(i=int(argtab["first"]);i<=last;++i) - # { - # if (i==int(argtab["first"]) && argtab["cfrt"]!="") - # { - # inframe= datapath argtab["story"]"/"argtab["cfrt"] - # frame= framepath framedir argtab["cfrt"] - # cpcmd = cp" "inframe" "frame - # chmodcmd = chmod" +r "frame - - # # print cpcmd - # if(system(cpcmd)!=0) - # { - # print "CFRT upload failed." - # updatefail=1 - # break - # } - # # print chmodcmd - # if(system(chmodcmd)!=0) - # { - # print "CFRT chmod failed." - # updatefail=1 - # break - # } - # print "CFRT updated." - # } - - # inframe= datapath argtab["story"]"/"sprintf(argtab["inframe"],i) - - # frame= framepath framedir sprintf(argtab["frame"],i) - # npbframe= framepath framedir sprintf(argtab["npbframe"],i) - - # npbcmd= sprintf("/eizm/pro/ong1/npb %s %s q",inframe,npbframe) - # cpcmd = cp" "inframe" "frame - # chmodcmd = chmod" +r "frame - # if(argtab["npbframe"]!="") - # { - # # print npbcmd - # if(system(npbcmd)!=0) - # { - # print i" NewpixbOTTification failed." - # updatefail=1 - # break - # } - # } - # # print cpcmd - # if(system(cpcmd)!=0) - # { - # print i" upload failed." - # updatefail=1 - # break - # } - # # print chmodcmd - # if(system(chmodcmd)!=0) - # { - # print i" chmod failed." - # updatefail=1 - # break - # } - # print i" updated." - # } - # if (!updatefail) - # { - # print "" > updatefile - # close(updatefile) - # } - # } - # } - firstong="" if (state==4) { print "Time to start onging." @@ -295,18 +323,18 @@ END{ if(firstong && argtab["cfrt"]!="") { - inframe= datapath argtab["story"]"/"argtab["cfrt"] - frame= framepath framedir argtab["cfrt"] + inframe[0]= datapath argtab["story"]"/"argtab["cfrt"] + frame[0]= framepath framedir argtab["cfrt"] - cpcmd = cp" "inframe" "frame - chmodcmd = chmod" +r "frame + cpcmd[0] = cp" "inframe[0]" "frame[0] + chmodcmd[0] = chmod" +r "frame[0] - if(system(cpcmd)!=0) + if(system(cpcmd[0])!=0) { print "CFRT upload failed." exit 1 } - if(system(chmodcmd)!=0) + if(system(chmodcmd[0])!=0) { print "CFRT chmod failed." exit 1 @@ -316,72 +344,102 @@ END{ print "ONG frame "f"." - inframe= datapath argtab["story"]"/"sprintf(argtab["inframe"],f) + if(argtab["special"] != "") + { + specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,"") + readspecialfile(specialfile,argtab,specialtab,effectivetab) + } + else + { + readspecialfile("",argtab,specialtab,effectivetab) + } - if (system("[ -f " inframe " ]")!=0) + for(k=0; k<=enhance; ++k) { - ++ongfailcount - print "Frame "f" doesnt't exist. (#"ongfailcount")" + k2=(k>0)?("-"k):"" - print sprintf("%u %u %u %u",state,last,nextong,ongfailcount) > statefile - close(statefile) + inframe[k]= datapath argtab["story"]"/"sprintf(effectivetab["inframe"k2],f,"") - if((argtab["finalreplaceframe"]!="") && (argtab["finalreplacetime"]!="")) + if (system("[ -f " inframe[k] " ]")!=0) { - if(((thistime3 - nextong) >= int(argtab["finalreplacetime"])*3600) && (ongfailcount>=int(argtab["finalreplacetime"]))) + if(k>0) #we only care about missing original frame { - print "Time to stop trying." - print "ONG final replacement frame." - inframe= datapath argtab["story"]"/"argtab["finalreplaceframe"] - nextstate=3 + continue + } + ++ongfailcount + print "Frame "f" doesnt't exist. (#"ongfailcount")" + + print sprintf("%u %u %u %u",state,last,nextong,ongfailcount) > statefile + close(statefile) + + if((argtab["finalreplaceframe"]!="") && (argtab["finalreplacetime"]!="")) + { + if(((thistime3 - nextong) >= int(argtab["finalreplacetime"])*3600) && (ongfailcount>=int(argtab["finalreplacetime"]))) + { + print "Time to stop trying." + print "ONG final replacement frame." + inframe[0]= datapath argtab["story"]"/"argtab["finalreplaceframe"] + nextstate=3 + } + else + exit 1 } else exit 1 } - else - exit 1 + + frame[k]= framepath framedir sprintf(effectivetab["frame"k2],f,"") + npbframe[k]= framepath framedir sprintf(effectivetab["npbframe"k2],f,"") + + + npbcmd[k]= npb" "inframe[k]" "npbframe[k]" q" + cpcmd[k] = cp" "inframe[k]" "frame[k] + chmodcmd[k] = chmod" +r "frame[k] } - - - frame= framepath framedir sprintf(argtab["frame"],f) - npbframe= framepath framedir sprintf(argtab["npbframe"],f) - # nextong = thistime3 + int(argtab["ongtime"])*3600 - nextong = getnextongtime() - - npbcmd= sprintf("/eizm/pro/ong1/npb %s %s q",inframe,npbframe) - cpcmd = cp" "inframe" "frame ongcmd = mawk" -f " bot4awk" -v story="argtab["story"]" -v frame="last" "datapath argtab["story"]"/settings" - chmodcmd = chmod" +r "frame - +# nextong = thistime3 + int(argtab["ongtime"])*3600 + nextong = getnextongtime() ### replace this with actual onging!!! # system("/eizm/pro/ong1/bot4") + if (specialtab["text"]!="") + { + specialtab["HTML"]=bb2html(specialtab["text"]) + writespecialfile(specialfile,specialtab) + } - timefile= datapath argtab["story"]"/ongtime" + # timefile= datapath argtab["story"]"/ongtime" print sprintf("%04u ",f)thistime2 >> timefile close(timefile) - if(argtab["npbframe"]!="") + for(k=0; k<=enhance; ++k) { - if(system(npbcmd)!=0) + k2=(k>0)?("-"k):"" + + if ((system("[ -f " inframe[k]" ]")!=0)&&(k>0)) + continue + + if(argtab["npbframe"]!="") + { + if(system(npbcmd[k])!=0) + { + print "NewpixbOTTification"k2" failed." + exit 1 + } + } + + if(system(cpcmd[k])!=0) { - print "NewpixbOTTification failed." + print "Frame"k2" upload failed." + exit 1 + } + + if(system(chmodcmd[k])!=0) + { + print "Frame"k2" chmod failed." exit 1 } } - - if(system(cpcmd)!=0) - { - print "Frame upload failed." - exit 1 - } - - if(system(chmodcmd)!=0) - { - print "Frame chmod failed." - exit 1 - } - print sprintf("%u %u %u 0",nextstate,f,nextong) > statefile close(statefile) @@ -419,4 +477,669 @@ function getnextongtime( schedulefile,temp,i) } close(schedulefile) return thistime3 + int(argtab["ongtime"])*3600 -} \ No newline at end of file +} + +function readspecialfile (datafile, argtab, specialtab, effectivetab, line,undertext,eq,i) +{ + for (i in specialtab) + delete specialtab[i] + + for (i in effectivetab) + delete effectivetab[i] + + if (datafile=="") + return + + line="" + while((getline line < datafile)>0) + { + gsub(/[\r\n]/, "", line) + + if (line == "" && !undertext) + { + undertext=1 + specialtab["text"]="" + } + else if (undertext) + { + specialtab["text"] = specialtab["text"] line "\n" + } + else + { + eq=index(line, "=") + specialtab[substr(line, 1, eq-1)]=substr(line, eq+1) + } + } + + for (i in argtab) + effectivetab[i]=argtab[i] + + for (i in specialtab) + effectivetab[i]=specialtab[i] + + + close (datafile) + +} + +function writespecialfile (datafile, specialtab, i) +{ + for (i in specialtab) + { + if (i!="text") + print i"="specialtab[i] > specialfile + } + + print "" > specialfile + if (specialtab["text"]!="") + printf("%s",specialtab["text"]) > specialfile + close (specialfile) +} + +#HTML STUFF FROM HERE +function bb2html(text, depth,count,bbtree,html,tag,tagstart,taglength,elm,tagv,tagname,tagvalue,matchname) +{ + depth=0 + count[0]=1 + bbtree["0"]="" + bbtree["0.n"]=0 + bbtree["0.t"]="post" + bbtree["0.v"]=argtab["subject"] + html="" + # gsub(/=/,"=",text) + debug = debug "\n\nBuild BBcode tree:" + while(length(text)!=0) + { + tag=match(text, /\[\/?[a-z0-9\*]+(=(([^\[<>\"\]]*)|(\"[^\"<>]*\")))?\]/) + #"#\"" + if (tag==0) + { + debug = debug "\ntext: " text + bbtree[ind(count,depth)]=text + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + text="" + break; + } + tagstart=RSTART + taglength=RLENGTH + if(tagstart>1) + { + elm=substr(text,1,tagstart-1) + debug = debug "\ntext: " elm + bbtree[ind(count,depth)]=elm + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + } + tag=substr(text,tagstart,taglength) + text=substr(text,tagstart+taglength) + debug = debug "\ntag: " tag + if(tag!~/^\[\//) + { + tagv=index(tag,"=") + if(tagv<2) + { + tagname=substr(tag,2,length(tag)-2) + tagvalue="" + } + else + { + tagname=substr(tag,2,tagv-2) + tagvalue=substr(tag,tagv+1,length(tag)-tagv-1) + } + if(tagname !~ /^((fq)|(tq)|(ni)|(po)|(quote)|b|i|u|(code)|(img)|(url)|(size)|(color)|(center)|(right)|(sub)|(sup)|(s)|(spoiler)|(list)|(br)|(\*))$/) + { + debug = debug "\nunknown tag" + bbtree[ind(count,depth)]=tag + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + continue + } + if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||bbtree[indt(count,depth)".t"] == "img"||(bbtree[indt(count,depth)".t"] == "spoiler" && tagname=="spoiler")||(bbtree[indt(count,depth)".t"] == "size" && tagname=="size")) + { + debug = debug "\nthis tag forbidden here" + bbtree[ind(count,depth)]=tag + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + continue + } + if(tagname=="*") + { + if(bbtree[indt(count,depth)".t"]==tagname) + { + debug = debug "\nimplied tag: [/"tagname"]" + debug = debug "\nmatched" + bbtree[ind(count,depth)]="[/"tagname"]" + bbtree[ind(count,depth)".k"]="e" + bbtree[ind(count,depth)".m"]=1 + bbtree[ind(count,depth)".t"]=tagname + bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"] + bbtree[indt(count,depth)".n"]=count[depth] + bbtree[indt(count,depth)".m"]=1 + count[depth]="" + --depth + ++count[depth] + } + else if(bbtree[indt(count,depth)".t"]!="list") + { + debug = debug "\nthis tag forbidden here" + bbtree[ind(count,depth)]=tag + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + continue + } + } + debug = debug "\nname: " tagname " value: " tagvalue + bbtree[ind(count,depth)]=tagname" "tagvalue + bbtree[ind(count,depth)".k"]="s" + bbtree[indt(count,depth)".n"]=count[depth] + ++depth + count[depth]=1 + bbtree[indt(count,depth)]=tag + bbtree[indt(count,depth)".n"]=0 + bbtree[indt(count,depth)".t"]=tagname + bbtree[indt(count,depth)".v"]=tagvalue + + # if(tagname=="br") #or other single tags in the future + # { + # debug = debug "\nmatched" + # bbtree[ind(count,depth)]=tag + # bbtree[ind(count,depth)".k"]="e" + # bbtree[ind(count,depth)".m"]=1 + # bbtree[ind(count,depth)".t"]=tagname + # bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"] + # bbtree[indt(count,depth)".n"]=count[depth] + # bbtree[indt(count,depth)".m"]=1 + # count[depth]="" + # --depth + # ++count[depth] + # } + } + else + { + if(depth<=0) + { + debug = debug "\n""unmatched" + bbtree[ind(count,depth)]=tag + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + continue + } + tagname=substr(tag,3,length(tag)-3) + if(tagname=="list"&&bbtree[indt(count,depth)".t"]=="*") + { + debug = debug "\nimplied tag: [/*]" + debug = debug "\nmatched" + bbtree[ind(count,depth)]="[/*]" + bbtree[ind(count,depth)".k"]="e" + bbtree[ind(count,depth)".m"]=1 + bbtree[ind(count,depth)".t"]="*" + bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"] + bbtree[indt(count,depth)".n"]=count[depth] + bbtree[indt(count,depth)".m"]=1 + count[depth]="" + --depth + ++count[depth] + } + debug = debug "\nname: " tagname + matchname=bbtree[indt(count,depth)".t"] + if((bbtree[indt(count,depth)".t"] == "code" && tagname!="code")||(bbtree[indt(count,depth)".t"] == "img" && tagname != "img")) + { + debug = debug "\nthis tag forbidden here" + bbtree[ind(count,depth)]=tag + bbtree[indt(count,depth)".n"]=count[depth] + ++count[depth] + continue + } + if(tagname!=matchname) + { + debug = debug "\nmismatched: " matchname + # bbtree[ind(count,depth)]=tag + # bbtree[indt(count,depth)".n"]=count[depth] + # ++count[depth] + # continue + bbtree[ind(count,depth)]=tag + bbtree[ind(count,depth)".k"]="e" + bbtree[ind(count,depth)".t"]=bbtree[indt(count,depth)".t"] + bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"] + bbtree[indt(count,depth)".n"]=count[depth] + count[depth]="" + --depth + ++count[depth] + continue + } + debug = debug "\nmatched" + bbtree[ind(count,depth)]=tag + bbtree[ind(count,depth)".k"]="e" + bbtree[ind(count,depth)".m"]=1 + bbtree[ind(count,depth)".t"]=tagname + bbtree[ind(count,depth)".v"]=bbtree[indt(count,depth)".v"] + bbtree[indt(count,depth)".n"]=count[depth] + bbtree[indt(count,depth)".m"]=1 + count[depth]="" + --depth + ++count[depth] + } + } + if(depth>0) + debug = debug "\nunclosed tags: " depth + + debug = debug "\n\n""generate HTML:" + depth=0 + count[0]=0 + while(count[0]<=bbtree["0.n"]&&depth>=0) + { + if(count[depth]==0) + { + tag=bbtree[indt(count,depth)] + tagname=bbtree[indt(count,depth)".t"] + tagvalue=bbtree[indt(count,depth)".v"] + debug = debug "\nname: "tagname" value: "tagvalue" elements: "bbtree[indt(count,depth)".n"] + if(tagname == "post") + { + } + else if(bbtree[indt(count,depth)".m"]=="") + { + debug = debug "\nunmatched" + html = html htmlescape(tag) + } + else if(tagname == "quote") + { + if (tagvalue=="") + { + html = html "
" + } + else + { + if(tagvalue !~ /^\".*\"$/) + #"#\"" + tagvalue="You forgot about the quote marks, "htmlescape(tagvalue) + else + tagvalue=bb2html(substr(tagvalue,2,length(tagvalue)-2)) + html = html "
"tagvalue" wrote:
" + } + } + else if (tagname == "fq") + { + html = html"
" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "tq") + { + html = html"
" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "br") + { + html = html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "ni") + { + html = html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "po") + { + html = html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "b") + { + html = html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "i") + { + html = html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "u") + { + html = html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname == "code") + { + if(bbtree[indtu(count,depth)".t"] == "code") + { + html=html htmlescape(tag) + debug = debug "\nnot a tag, actually" + } + else + { + html=html"
Code: Select all
" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + } + else if (tagname == "img") + html=html"" + } + else if (tagname == "size") + { + if (tagvalue==""||(tagvalue !~ /^[0-9]+$/)||(tagvalue+0)>200) + html=html" This tag should have a correct value. " + else + html=html"" + } + else if (tagname == "color") + { + if (tagvalue==""||tagvalue !~ /^#[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]$/) #for some reason /^([0-9A-F]{6})$/ doesn't work. + html=html" This tag should have a correct value. " + else + html=html"" + } + else if (tagname ~ /^((center)|(right))$/) + { + html=html"
" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname =="s") + { + html=html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname =="sub") + { + html=html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname =="sup") + { + html=html"" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname=="spoiler") + { + html=html"
Spoiler:
" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if (tagname=="list") + { + if(tagvalue=="") + html=html"
    " + else + { + if (tagvalue=="1") + tagvalue="decimal" + else if (tagvalue=="i") + tagvalue="lower-roman" + else if (tagvalue=="I") + tagvalue="upper-roman" + else if (tagvalue=="a") + tagvalue="lower-alpha" + else if (tagvalue=="A") + tagvalue="upper-alpha" + else + { + html=html"This tag should have a correct value. " + tagvalue="decimal" + } + html=html"
      " + } + } + else if (tagname=="*") + { + html=html"
    1. " + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + # else if (tagname == "br") + # { + # html = html"
      " + # if(tagvalue!="") + # html=html"This tag shouldn't have any value. " + # } + else + { + debug = debug "\nunknown tag" + html = html htmlescape(tag) + } + ++count[depth] + } + else if(bbtree[ind(count,depth)".k"]=="s") + { + debug = debug "\nentering tag:" + ++depth + count[depth]=0 + } + else if(bbtree[ind(count,depth)".k"]=="e") + { + debug = debug "\nleaving tag:" + tag=bbtree[ind(count,depth)] + tagname=bbtree[ind(count,depth)".t"] + tagvalue=bbtree[ind(count,depth)".v"] + debug = debug "\nname: "tagname" value: "tagvalue + if (tagname == "post") + { + } + else if(bbtree[ind(count,depth)".m"]=="") + { + debug = debug "\nunmatched" + html = html htmlescape(tag) + } + else if(tagname == "quote") + html = html "
" + else if (tagname ~/^(b|i|u|(size)|(color)|(br)|(ni)|(po))$/) + html = html"" + else if (tagname == "code") + { + if(bbtree[indtu(count,depth)".t"] == "code") + { + html=html htmlescape(tag) + debug = debug "\nnot a tag, actually" + } + else + html = html"" + } + else if (tagname == "img") + { + html = html"\" alt=\"Image\" />" + if(tagvalue!="") + html=html"This tag shouldn't have any value. " + } + else if(tagname=="url") + html=html"" + else if (tagname ~ /^((center)|(right)|(fq)|(tq))$/) + html=html"
" + else if (tagname =="s") + html=html"" + else if (tagname =="sub") + html=html"" + else if (tagname =="sup") + html=html"" + else if (tagname=="spoiler") + html=html"" + else if (tagname=="list") + { + if (tagvalue=="") + html=html"" + else + html=html"" + } + else if (tagname=="*") + html=html"" + # else if (tagname == "br") # + # { + # # + # } + else + { + debug = debug "\nunknown tag" + html = html htmlescape(tag) + } + count[depth]="" + --depth + ++count[depth] + } + else if(count[depth]>bbtree[indt(count,depth)".n"]) + { + debug = debug "\nrun out of elements in this tag; leaving" + count[depth]="" + --depth + ++count[depth] + } + else + { + tag=bbtree[ind(count,depth)] + debug = debug "\ntext: "tag + + tag=htmlescape(tag,"","br") + + if(bbtree[indt(count,depth)".t"] == "code") + { + gsub(/ /,"\\ ",tag) + gsub(/\t/,"\\ \\ ",tag) + } + else{ + gsub(/ /,"\\  ",tag) + gsub(/ /," \\ ",tag) + # gsub(/
/,"
\\ ",tag) + } + + + if(nourl==""&& bbtree[indt(count,depth)".t"] !~ /^((code)|(img)|(url))$/) + gsub(/https?:\/\/[^\n\r\t<> ]+/,"&",tag) + # if(nosmil=="" && bbtree[indt(count,depth)".t"] !~ /^((code)|(img))$/) + # { + # gsub(/(^|[\n\r\t ]):D($|[\n\r\t ])/," \":D\" ",tag) + # gsub(/(^|[\n\r\t ]):\)($|[\n\r\t ])/," \":)\" ",tag) + # gsub(/(^|[\n\r\t ]):\(($|[\n\r\t ])/," \":(\" ",tag) + # gsub(/(^|[\n\r\t ]):o($|[\n\r\t ])/," \":o\" ",tag) + # gsub(/(^|[\n\r\t ]):shock:($|[\n\r\t ])/," \":shock:\" ",tag) + # gsub(/(^|[\n\r\t ]):\?($|[\n\r\t ])/," \":?\" ",tag) + # gsub(/(^|[\n\r\t ])8-\)($|[\n\r\t ])/," \"8-)\" ",tag) + # gsub(/(^|[\n\r\t ]):lol:($|[\n\r\t ])/," \":lol:\" ",tag) + # gsub(/(^|[\n\r\t ]):x($|[\n\r\t ])/," \":x\" ",tag) + # gsub(/(^|[\n\r\t ]):P($|[\n\r\t ])/," \":P\" ",tag) + # gsub(/(^|[\n\r\t ]):oops:($|[\n\r\t ])/," \":oops:\" ",tag) + # gsub(/(^|[\n\r\t ]):cry:($|[\n\r\t ])/," \":cry:\" ",tag) + # gsub(/(^|[\n\r\t ]):evil:($|[\n\r\t ])/," \":evil:\" ",tag) + # gsub(/(^|[\n\r\t ]):twisted:($|[\n\r\t ])/," \":twisted:\" ",tag) + # gsub(/(^|[\n\r\t ]):roll:($|[\n\r\t ])/," \":roll:\" ",tag) + # gsub(/(^|[\n\r\t ]):wink:($|[\n\r\t ])/," \":wink:\" ",tag) + # gsub(/(^|[\n\r\t ]);\)($|[\n\r\t ])/," \":wink:\" ",tag) + # gsub(/(^|[\n\r\t ]):!:($|[\n\r\t ])/," \":!:\" ",tag) + # gsub(/(^|[\n\r\t ]):\?:($|[\n\r\t ])/," \":?:\" ",tag) + # gsub(/(^|[\n\r\t ]):idea:($|[\n\r\t ])/," \":idea:\" ",tag) + # gsub(/(^|[\n\r\t ]):arrow:($|[\n\r\t ])/," \":arrow:\" ",tag) + # gsub(/(^|[\n\r\t ]):\|($|[\n\r\t ])/," \":|\" ",tag) + # gsub(/(^|[\n\r\t ]):mrgreen:($|[\n\r\t ])/," \":mrgreen:\" ",tag) + # } + + html = html tag + ++count[depth] + } + } + debug = debug "\ndone\n" + return html +} + +function ind(count,depth, ii,iindex) +{ + iindex = "" + for(ii=0;ii<=depth;++ii) + { + if(ii!=0) + iindex = iindex "." + iindex = iindex count[ii] + } + # debug = debug "\n" iindex + return iindex +} +function indt(count,depth, ii,iindex) +{ + iindex = "" + for(ii=0;ii0) + iindex=iindex"." + iindex = iindex "0" + # debug = debug "\n" iindex + return iindex +} +function indtu(count,depth, ii,iindex) +{ + iindex = "" + for(ii=0;ii0) + iindex=iindex"." + iindex = iindex "0" + # debug = debug "\n" iindex + return iindex +} +function htmlescape(name,less,br, len,iii,escaped,ch) +{ + len=length(name) + escaped="" + for(iii=1;iii<=len;++iii) + { + ch=substr(name,iii,1); + if(ch == "\n") + escaped = escaped ((br!="")?"
":"&#"ch2dec[ch]";") + else if(ch =="\r") + escaped = escaped ((br!="")?"":"&#"ch2dec[ch]";") + else if(ch == "\"" && less=="") + escaped = escaped "&#"ch2dec[ch]";" + else if(ch ~ /[=<>&]/) + escaped = escaped "&#"ch2dec[ch]";" + else + escaped = escaped ch + } + return escaped +} +function hexencode(name, len,iii,escaped,ch) +{ + len=length(name) + escaped="" + for(iii=1;iii<=len;++iii) + { + ch=substr(name,iii,1) + escaped = escaped ch2hex[ch] + } + return escaped +} + + + + + + + + + + + diff --git a/post.cpp b/post.cpp index f5cc701..4ccac67 100644 --- a/post.cpp +++ b/post.cpp @@ -1,8 +1,8 @@ // post.cpp (1190.bicyclesonthemoon.info/aftertime/post) // The post edit interface -// 05.04.2015 +// 15.04.2019 // -// Copyright (C) 2015 Balthasar Szczepański +// Copyright (C) 2015, 2019 Balthasar Szczepański // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -75,6 +75,7 @@ char *subject =&zero; char *key =&zero; char *forcekey =&zero; char *ID =&zero; +bool special=false; char wrong[256]; @@ -86,7 +87,8 @@ void writeArgH(FILE *file,const char *name,const char *value, unsigned char br); void writeArgH(FILE *file,const char *value); // void writeArgBR(FILE *file,const char *name, const char *value); void end(int m); -void id(char *timenumber,char *story, unsigned short frame, unsigned char round); +void id(char *timenumber, char *story, unsigned short frame, char *subframe, unsigned char round); +void specialid(char *timenumber, char *story, char frame); void end(int m) { @@ -257,41 +259,86 @@ void submit() char mm[4]; char dd[4]; char hh[4]; + char sf[2]={0,0}; char arg1[256]; char arg2[256]; char arg3[256]; + char arg4[256]; char newkey[33]; unsigned char tm, td, th, tr; unsigned short ty, tf; + + // dup2(fileno(stdout),fileno(stderr)); + // printf("Content-type: text/plain\n\n"); + // posttime=time(NULL); // nowS=gmtime(&posttime); if(forcekey[0]=='\0') - sprintf(newkey,"%04X%04X%04X%04X%04X%04X%04X%04X", + snprintf(newkey,33,"%04X%04X%04X%04X%04X%04X%04X%04X", (unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand(), (unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand(),(unsigned short)rand()); else - sprintf(newkey,"%s",forcekey); + snprintf(newkey,33,"%s",forcekey); - if(y[0]!='\0'){sscanf(y,"%hu",&ty); sprintf(yy,"%04hu",ty); } - if(m[0]!='\0'){sscanf(m,"%hhu",&tm);sprintf(mm,"%02hhu",tm);} - if(d[0]!='\0'){sscanf(d,"%hhu",&td);sprintf(dd,"%02hhu",td);} - if(h[0]!='\0'){sscanf(h,"%hhu",&th);sprintf(hh,"%02hhu",th);} - if(frame[0]!='\0'){sscanf(frame,"%hu",&tf);sprintf(ff,"%04hu",tf);} - if(round[0]!='\0'){sscanf(round,"%hhu",&tr);sprintf(rr,"%02hhu",tr);} + if(y[0]!='\0') + { + sscanf(y,"%hu",&ty); + snprintf(yy,8,"%04hu",ty); + } + if(m[0]!='\0') + { + sscanf(m,"%hhu",&tm); + snprintf(mm,4,"%02hhu",tm); + } + if(d[0]!='\0') + { + sscanf(d,"%hhu",&td); + snprintf(dd,4,"%02hhu",td); + } + if(h[0]!='\0') + { + sscanf(h,"%hhu",&th); + snprintf(hh,4,"%02hhu",th); + } + if(frame[0]!='\0') + { + if(special) + { + snprintf(ff,8,"%c",frame[0]); + } + else + { + sscanf(frame,"%hu%c",&tf,sf); + snprintf(ff,8,"%04hu%s",tf,sf); + } + } + if(round[0]!='\0') + { + if(special) + snprintf(rr,4,""); + else + { + sscanf(round,"%hhu",&tr); + snprintf(rr,4,"%02hhu",tr); + } + } if((ty>0x0fff)||(tm>0x0f)||(td>0x1f)||(th>0x1f)) preview("Time too long"); // I accept invalid time as long as it's not too long - id(timenumber,story,tf,tr); - sprintf(postpath,"%s%s",MPOST_PATH,timenumber); + if (special) + specialid(timenumber,story,frame[0]); + else + id(timenumber,story,tf,sf,tr); + snprintf(postpath,512,"%s%s",MPOST_PATH,timenumber); if(forceID[0]!='\0') - sprintf(forcepath,"%s%s",MPOST_PATH,forceID); + snprintf(forcepath,512,"%s%s",MPOST_PATH,forceID); tempfile=fopen(temppath,"wt"); if(tempfile==NULL) @@ -321,8 +368,8 @@ void submit() fclose(tempfile); tf=false; - sprintf(arg1,"outfile=%s",temppath); - sprintf(arg2,"tempfile=%s",temppath2); + snprintf(arg1,256,"outfile=%s",temppath); + snprintf(arg2,256,"tempfile=%s",temppath2); fflush(stdout); sub=fork(); if(sub==0) @@ -334,19 +381,24 @@ void submit() } waitpid(sub,&r,0); - sprintf(arg1,"name=%s",username); - sprintf(arg2,"pass=%s",password); - sprintf(arg3,"story=%s",story); + snprintf(arg1,256,"name=%s",username); + snprintf(arg2,256,"pass=%s",password); + snprintf(arg3,256,"story=%s",story); + snprintf(arg4,256,"file=%s",(forceID[0]!='\0')?forcepath:postpath); + sub=fork(); if(sub==0) { - r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",arg1,"-v",arg2,"-v",arg3,"-v","reversed=1",(forceID[0]!='\0')?forcepath:postpath,(char *)0); + r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",arg1,"-v",arg2,"-v",arg3,"-v",arg4,(char *)0); exit(r); } waitpid(sub,&r,0); - if(!r) + + // printf("r=%d\n",r); + + if(r) preview("Can't submit this post. Not yours or wrong password?"); - + if(forceID[0]!='\0') { sub=fork(); @@ -370,7 +422,7 @@ void submit() preview(postpath); printf("Content-type: text/html\n\n"); - sprintf(arg1,"info=

This message has been sent successfully.

View your submitted message

Return to the list

",timenumber,newkey); + snprintf(arg1,256,"info=

This message has been sent successfully.

View your submitted message

Return to the list

",timenumber,newkey); // printf("Content-type: text/html\n\n"); fflush(stdout); sub=fork(); @@ -394,14 +446,54 @@ void preview (const char *text) char mm[4]; char dd[4]; char hh[4]; + char sf[2]={0,0}; unsigned short ty, tf; unsigned char tm,td,th, tr; - if(y[0]!='\0'){sscanf(y,"%hu",&ty); ty&=0x0fff;sprintf(yy,"%04hu",ty); } - if(m[0]!='\0'){sscanf(m,"%hhu",&tm);tm&= 0x0f;sprintf(mm,"%02hhu",tm);} - if(d[0]!='\0'){sscanf(d,"%hhu",&td);td&= 0x1f;sprintf(dd,"%02hhu",td);} - if(h[0]!='\0'){sscanf(h,"%hhu",&th);th&= 0x1f;sprintf(hh,"%02hhu",th);} - if(frame[0]!='\0'){sscanf(frame,"%hu",&tf);sprintf(ff,"%04hu",tf);} - if(round[0]!='\0'){sscanf(round,"%hhu",&tr);sprintf(rr,"%02hhu",tr);} + if(y[0]!='\0') + { + sscanf(y,"%hu",&ty); + ty&=0x0fff; + snprintf(yy,8,"%04hu",ty); + } + if(m[0]!='\0') + { + sscanf(m,"%hhu",&tm); + tm&= 0x0f; + snprintf(mm,4,"%02hhu",tm); + } + if(d[0]!='\0') + { + sscanf(d,"%hhu",&td); + td&= 0x1f; + snprintf(dd,4,"%02hhu",td); + } + if(h[0]!='\0') + { + sscanf(h,"%hhu",&th); + th&= 0x1f;snprintf(hh,4,"%02hhu",th); + } + if(frame[0]!='\0') + { + if(special) + { + snprintf(ff,8,"%c",frame[0]); + } + else + { + sscanf(frame,"%hu%c",&tf,sf); + snprintf(ff,8,"%04hu%s",tf,sf); + } + } + if(round[0]!='\0') + { + if(special) + snprintf(rr,4,""); + else + { + sscanf(round,"%hhu",&tr); + snprintf(rr,4,"%02hhu",tr); + } + } tempfile=fopen(temppath,"wt"); if(tempfile==NULL) @@ -434,8 +526,8 @@ void preview (const char *text) printf("Content-type: text/html\n\n"); - sprintf(arg1,"outfile=%s",temppath); - sprintf(arg2,"tempfile=%s",temppath2); + snprintf(arg1,256,"outfile=%s",temppath); + snprintf(arg2,256,"tempfile=%s",temppath2); fflush(stdout); sub=fork(); @@ -449,8 +541,8 @@ void preview (const char *text) waitpid(sub,&r,0); // printf("Content-type: text/html\n\n"); - sprintf(arg1,"argfile=%s",temppath); - sprintf(arg2,"key=%s",key[0]?key:"???"); + snprintf(arg1,256,"argfile=%s",temppath); + snprintf(arg2,256,"key=%s",key[0]?key:"???"); fflush(stdout); sub=fork(); if(sub==0) @@ -472,12 +564,14 @@ int main() char *arg; + // printf("Content-type: text/plain\n\n"); + cgi=cgiInit(); srand (time (NULL) + getpid()); - sprintf(temppath,"%s%lu",TEMP_PATH,(unsigned long)getpid()); - sprintf(temppath2,"%s_%lu",TEMP_PATH,(unsigned long)getpid()); + snprintf(temppath,256,"%s%lu",TEMP_PATH,(unsigned long)getpid()); + snprintf(temppath2,256,"%s_%lu",TEMP_PATH,(unsigned long)getpid()); arg=cgiGetValue(cgi,"password"); if(arg!=NULL) @@ -501,9 +595,19 @@ int main() if(arg!=NULL) { story=arg; - if(!strcmp(story,"t1i")); - else if(!strcmp(story,"bftf")); + if(!strcmp(story,"time")); //really shouldn't be hardcoded! + else if(!strcmp(story,"prickly")); + else if(!strcmp(story,"potm")); + else if(!strcmp(story,"lucky")); + else if(!strcmp(story,"beany")); + else if(!strcmp(story,"bean2")); + else if(!strcmp(story,"t1i")); else if(!strcmp(story,"zodiac")); + else if(!strcmp(story,"bftf")); + else if(!strcmp(story,"t-1")); + else if(!strcmp(story,"bsta")); + else if(!strcmp(story,"advent")); + else if(!strcmp(story,"phys")); else { missing=true; @@ -518,7 +622,11 @@ int main() arg=cgiGetValue(cgi,"frame"); if(arg!=NULL) + { frame=arg; + if((frame[0]>='a')&&(frame[0]<='z')) + special=true; + } else { missing=true; @@ -530,8 +638,11 @@ int main() round=arg; else { - missing=true; - strcpy(wrong,"Round number was missing. Replaced with default value."); + if(!special) + { + missing=true; + strcpy(wrong,"Round number was missing. Replaced with default value."); + } } arg=cgiGetValue(cgi,"subject"); if(arg!=NULL) @@ -646,7 +757,11 @@ int main() } -void id(char *timenumber,char *story, unsigned short frame, unsigned char round) +void id(char *timenumber, char *story, unsigned short frame, char *subframe, unsigned char round) +{ + snprintf(timenumber,256,"%s-%04hu%s-%02hhu",story,frame,subframe,round); +} +void specialid(char *timenumber, char *story, char frame) { - sprintf(timenumber,"%s-%04hu-%02hhu",story,frame,round); -} \ No newline at end of file + snprintf(timenumber,256,"%s-%c",story,frame); +} diff --git a/preview.awk b/preview.awk index 20b4a61..01d7db5 100644 --- a/preview.awk +++ b/preview.awk @@ -1,8 +1,8 @@ #// preview.awk #// Preview a post in the post edit interface -#// 31.03.2015 +#// 25.05.2021 #// -#// Copyright (C) 2015 Balthasar Szczepański +#// Copyright (C) 2015, 2021 Balthasar Szczepański #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as @@ -51,7 +51,7 @@ BEGIN{ } # print "-->" close(argfile) - if(argtab["edit"] ~ /^[a-zA-Z0-9]+\-[0-9]+\-[0-9]+$/) + if(argtab["edit"] ~ /^[a-zA-Z0-9]+\-(([0-9]+[a-z]?\-[0-9]+)|([a-z]))$/) { argtab["forceID"]=argtab["edit"] ### reused from where it made more sense argfile= postpath argtab["forceID"] @@ -83,7 +83,7 @@ BEGIN{ } close(argfile) } - else if(argtab["addquote"] ~ /^[a-zA-Z0-9]+\-[0-9]+\-[0-9]+$/) + else if(argtab["addquote"] ~ /^[a-zA-Z0-9]+\-(([0-9]+[a-z]?\-[0-9]+)|([a-z]))$/) { argfile= postpath argtab["addquote"] while((getline argline < argfile)>0) diff --git a/remove.c b/remove.c index 694be8d..670c4ff 100644 --- a/remove.c +++ b/remove.c @@ -1,8 +1,8 @@ // remove.c (1190.bicyclesonthemoon.info/aftertime/remove) // remove a post -// 28.03.2015 +// 15.04.2019 // -// Copyright (C) 2015 Balthasar Szczepański +// Copyright (C) 2015, 2019 Balthasar Szczepański // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -45,9 +45,12 @@ int main(int argc, char **argv) char outpath[256]; char argp1[256]; char argp2[256]; + char argp3[256]; cgi=cgiInit(); + // dup2(fileno(stdout),fileno(stderr)); + // printf("Content-type: text/plain\n\n"); rmov=((arg=cgiGetValue(cgi,"r"))?arg:&zero); @@ -77,15 +80,16 @@ int main(int argc, char **argv) return 0; } - sprintf(inpath,"%s%s",POST_PATH,rmov); + snprintf(inpath,256,"%s%s",POST_PATH,rmov); - sprintf(argp1,"name=%s",username); - sprintf(argp2,"pass=%s",password); + snprintf(argp1,256,"name=%s",username); + snprintf(argp2,256,"pass=%s",password); + snprintf(argp3,256,"file=%s",inpath); sub=fork(); if(sub==0) { - r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",argp1,"-v",argp2,inpath,(char *)0); + r=execl(MAWK_PATH,MAWK_PATH,"-f",AWK_VERIFY,"-v",argp1,"-v",argp2,"-v",argp3,(char *)0); exit(r); } waitpid(sub,&r,0); @@ -94,7 +98,7 @@ int main(int argc, char **argv) cgiRedirect("/aftertime/list"); return(0); } - sprintf(outpath,"%s%s",RMOV_PATH,rmov); + snprintf(outpath,256,"%s%s",RMOV_PATH,rmov); sub=fork(); if(sub==0) diff --git a/upload.awk b/upload.awk index 2bd7312..728701d 100644 --- a/upload.awk +++ b/upload.awk @@ -1,8 +1,8 @@ #// upload.awk #// The post upload interface -#// 21.12.2015 +#// 25.05.2021 #// -#// Copyright (C) 2015 Balthasar Szczepański +#// Copyright (C) 2015, 2019, 2021 Balthasar Szczepański #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as @@ -20,7 +20,7 @@ BEGIN{ postpath="/eizm/mem/aftertime/mpost/" passpath="/eizm/mem/aftertime/pass/" - rmpath="/eizm/mem/aftertime/rm/" + rmpath="/eizm/mem/aftertime/mpost/rm/" bb2html="/eizm/pro/aftertime/bb2html.awk" automome="/eizm/pro/ong1/mome.pl" memepath="/eizm/mem/ong1/mome.txt" @@ -108,7 +108,21 @@ BEGIN{ else split($0, idtab, "-") story=idtab[1] - frame=int(idtab[2]) + if (idtab[2]~/^[a-z]/) + { + frame=substr(idtab[2],1,1) + subframe="" + } + else if(idtab[2]~/^[0-9]+[a-z]$/) + { + frame=int(substr (idtab[2], 1, length(idtab[2])-1)) + subframe=substr (idtab[2], length(idtab[2]), 1) + } + else + { + frame=int(idtab[2]) + subframe="" + } round=int(idtab[3]) } else if(ln==2) @@ -152,9 +166,23 @@ END{ if(ln!=0) post() } + + +function makeid(story,frame,subframe,round) +{ + if(frame ~ /^[a-z]/) + { + return sprintf("%s-%s",story,frame) + } + else + { + return sprintf("%s-%04u%s-%02u",story,frame,subframe,round) + } +} + function remove( postid,postfile,rmfile,passfile,temp,f,tn,eq,tv,namef,passf) { - postid=sprintf("%s-%04u-%02u",story,frame,round) + postid=makeid(story,frame,subframe,round) postfile=postpath postid rmfile=rmpath postid passfile=passpath story @@ -171,7 +199,7 @@ function remove( postid,postfile,rmfile,passfile,temp,f,tn,eq,tv,namef,passf) print "Can't remove. Wrong username." return } - if(pass!=password) + if(pass!=passf) { print "Can't remove. Wrong password." return @@ -187,7 +215,7 @@ function remove( postid,postfile,rmfile,passfile,temp,f,tn,eq,tv,namef,passf) function quote( postid,postfile,passfile,temp,f,opt,cont,ongt,subj,eq,tn,tv,id,namef,passf,yy,mm,dd,hh) { - postid=sprintf("%s-%04u-%02u",story,frame,round) + postid=makeid(story,frame,subframe,round) postfile=postpath postid passfile=passpath story @@ -318,7 +346,7 @@ function post( postid,replaceid,postfile,passfile,replacefile,temp,i,eq,tn,tv, return quote() if(rmov!="") return remove() - postid=sprintf("%s-%04u-%02u",story,frame,round) + postid=makeid(story,frame,subframe,round) printf("%s",postid" ") postfile=postpath postid @@ -346,7 +374,7 @@ function post( postid,replaceid,postfile,passfile,replacefile,temp,i,eq,tn,tv, print "Story name missing." return } - if(story !~ /^(t1i|bftf|t-1)$/) + if(story !~ /^(time|prickly|potm|lucky|beany|bean2|t1i|zodiac|bftf|t-1|bsta|advent|phys)$/) #this really shouldn't be hardcoded! { print "Unknown story." return @@ -421,8 +449,13 @@ function post( postid,replaceid,postfile,passfile,replacefile,temp,i,eq,tn,tv, print "username_h="htmlescape(name) >> postfile print "subject_h="htmlescape(subject) >> postfile print "story="story >> postfile - print "frame="sprintf("%04u",frame) >> postfile - print "round="sprintf("%02u",round) >> postfile + if (frame ~ /^[a-z]/) + print "frame="frame >> postfile + else + { + print "frame="sprintf("%04u",frame) >> postfile + print "round="sprintf("%02u",round) >> postfile + } print "h="htmlescape(h) >> postfile print "d="htmlescape(d) >> postfile diff --git a/verify.awk b/verify.awk index a4ca33b..b94bfff 100644 --- a/verify.awk +++ b/verify.awk @@ -1,8 +1,8 @@ #// verify.awk #// Check if post belongs to user -#// 27.03.2015 +#// 15.04.2019 #// -#// Copyright (C) 2015 Balthasar Szczepański +#// Copyright (C) 2015, 2019 Balthasar Szczepański #// #// This program is free software: you can redistribute it and/or modify #// it under the terms of the GNU Affero General Public License as @@ -38,15 +38,24 @@ BEGIN{ fail=1 } } -{ - gsub(/[\r\n]/,"",$0) - eq=index($0,"=") - argtab[substr($0,1,eq-1)]=substr($0,eq+1) -} +# { + # gsub(/[\r\n]/,"",$0) + # eq=index($0,"=") + # argtab[substr($0,1,eq-1)]=substr($0,eq+1) +# } END{ + while((getline line < file)>0) + { + gsub(/[\r\n]/,"",line) + eq=index(line,"=") + argtab[substr(line,1,eq-1)]=substr(line,eq+1) + } + close (file) + if(story=="") story=argtab["story"] - else if(story!=argtab["story"]) + + else if(story!=argtab["story"] && argtab["story"]!="") exit fail passfile = passpath story diff --git a/viewer.awk b/viewer.awk new file mode 100644 index 0000000..50e2713 --- /dev/null +++ b/viewer.awk @@ -0,0 +1,687 @@ +#// viewer.awk +#// The viewer +#// 25.05.2021 +#// +#// Copyright (C) 2015-2021 Balthasar Szczepański +#// +#// This program is free software: you can redistribute it and/or modify +#// it under the terms of the GNU Affero General Public License as +#// published by the Free Software Foundation, either version 3 of the +#// License, or (at your option) any later version. +#// +#// This program is distributed in the hope that it will be useful, +#// but WITHOUT ANY WARRANTY; without even the implied warranty of +#// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#// GNU Affero General Public License for more details. +#// +#// You should have received a copy of the GNU Affero General Public License +#// along with this program. If not, see . + + +BEGIN{ + FS="" + noticepath="/eizm/mem/aftertime/mpost/" + framepath="/eizm/www/time/" + datapath="/eizm/data/aftertime/" + timecmd="date -u +\"%Y%m%d%H\"" + timecmd2="date +\"%H%M%S\"" + timecmd3="date -u +\"%m%d%H%M\"" + timecmd4="date -u +\"%s\"" + botcastleurl="http://1190.bicyclesonthemoon.info" + postlink="http://forums.xkcd.com/viewtopic.php?f=7" + + for(i=0;i<256;++i) + { + ch=sprintf("%c",i) + hex=sprintf("%02X",i) + dec=sprintf("%u",i) + ch2hex[ch]=hex + ch2dec[ch]=dec + } + + listfile = datapath "stories" + stories=0 + line="" + while((getline line < listfile)>0) + { + gsub(/[\r\n]/,"",line) + eq=index(line,"=") + + storytab[stories]=htmlescape(substr(line, 1, eq-1),"","") + storyname[stories]=htmlescape(substr(line, eq+1),"","") + ++stories + } + close(listfile) + + if(frame ~ /[a-zA-Z]$/) + { + f=int(substr(frame,1,length(frame)-1)) + s=substr(frame, length(frame)) + } + else + { + f=int(frame) + s="" + } + e=int(enhance) + n=int(notice) + b=int(bbcode) + + timecmd | getline thistime + close(timecmd) + + timecmd2 | getline thistime2 + close(timecmd2) + + timecmd3 | getline thistime3 + close(timecmd3) + + timecmd4 | getline thistime4 + close(timecmd4) + + thistime3=int(thistime3) + thistime4=int(thistime4) + + lastalt=0 + + ch2num[0]="" + num2ch[""]=0 + for(i=1;i<=26;++i) + { + ch=sprintf("%c",i+96) + num2ch[i]=ch + ch2num[ch]=i + } + for(i=0;i<256;++i) + { + ch=sprintf("%c",i) + dec=sprintf("%u",i) + ch2dec[ch]=dec + } + alttabsize=0 +} +{ + file=1 + gsub(/[\r\n]/, "", $0) + eq=index($0, "=") + if($0 ~ /^[0-9]+=/) + { + i=int(substr($0, 1, eq-1)) + alttab[alttabsize]=substr($0, eq+1) + alttabn[alttabsize]=i + ++alttabsize + + # i=int(substr($0, 1, eq-1)) + # if(f>=i && i>=lastalt) + # { + # alt=substr($0, eq+1) + # lastalt=i + # } + } + else if($0 ~ /^sf-[0-9]+=/) + { + sf=1 + i=int(substr($0, 4, eq-4)) + if(i==f) + this_sf= tolower(substr($0, eq+1)) + if(i==f-1) + prev_sf=tolower(substr($0, eq+1)) + + } + argtab[substr($0, 1, eq-1)]=substr($0, eq+1) +} +END{ + + if (file=="") + exit 1 + + if(sf=="") + s="" + else if(this_sf=="") + s="" + else if(s>this_sf && argtab["cfrt"]=="") + s=this_sf + + ongoing=int(argtab["ongoing"]) + if(ongoing>0) + { + statefile= datapath argtab["story"]"/ongstate" + getline temp < statefile + close(statefile) + + split(temp, temptab, " ") + state=int(temptab[1]) + last=int(temptab[2]) + nextong=int(temptab[3]) + } + else + { + last=int(argtab["last"]) + state=3 + } + first=int(argtab["first"]) + + ongtimefile= datapath argtab["story"]"/ongtime" + + if(frame=="") + { + if(ongoing>0) + { + if (int(argtab["onlyframe"])>0) + { + f=last + onlyframe=1 + } + else + { + onlyframe="" + if (int(argtab["showlatest"])>0) + f=last + else + f=first + } + } + else + { + f=first + onlyframe="" + if (replay != "") + { + # print "DEBUG:
" + ongyr=0 + ongsy=0 + line="" + while((getline line < ongtimefile)>0) + { + ongind=index(line," ") + ongft=substr(line,1,ongind-1) + ongt=int((ongsy?(substr(line,ongind+1,4)-ongyr):0) substr(line,ongind+6,2) substr(line,ongind+9,2) substr(line,ongind+12,2) substr(line,ongind+15,2)) + + # printf("o.%d
",ongt) + + if(!ongsy) + { + ongsy=1 + ongyr=substr(line,ongind+1,4) + # printf("3.%d
",thistime3) + if(thistime3",thistime3) + } + } + + if(ongt>thistime3) + { + # if(ongsm) + # print"BREAK!
" + break; + } + # else + # ongsm=1; + if(ongft ~ /^[0-9]+[a-z]$/) + { + f=int(substr(ongft,1,ongind-2)) + s=substr(ongft,ongind-1,1) + } + else + { + f=int(ongft) + s="" + } + # print"f."f"."s"
" + } + close(ongtimefile) + } + } + } + + if (s!="") + { + if(argtab[s] != "") + s2=argtab[s] + else + s2=s + # n=-1 + } + + if(flast && argtab["cfrt"]=="") + f=last + + if(argtab["special"] != "") + { + specialfile=datapath argtab["story"]"/"sprintf(argtab["special"],f,s) + line="" + undertext="" + + while((getline line < specialfile)>0) + { + gsub(/[\r\n]/, "", line) + + if (line == "" && !undertext) + { + undertext=1 + argtab["text"]="" + continue + } + + if (undertext) + { + argtab["text"] = argtab["text"] line "\n" + } + else + { + + eq=index(line, "=") + argtab[substr(line, 1, eq-1)]=substr(line, eq+1) + } + } + close (specialfile) + } + + line="" + while((getline line < ongtimefile)>0) + { + ongind=index(line," ") + ongft=substr(line,1,ongind-1) + ongt=substr(line,ongind+9,2)"."substr(line,ongind+6,2)"."substr(line,ongind+1,4)", "substr(line,ongind+12,2)":"substr(line,ongind+15,2)" UTC" + if(ongft ~ /^[0-9]+[a-z]$/) + ongf=int(substr(ongft,1,ongind-2)) substr(ongft,ongind-1,1) + else + ongf=int(ongft) + + if(ongf==(f s) && ongt ~ /^[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9][0-9][0-9], [0-9][0-9]:[0-9][0-9] UTC$/) + ongtimetext=ongt + } + close(ongtimefile) + + if ("alt" in argtab) + alt=htmlescape(argtab["alt"],"less","bb") + else + { + for(i=0; i=alttabn[i] && alttabn[i]>=lastalt) + { + alt=htmlescape(alttab[i],"less","bb") + lastalt=alttabn[i] + } + } + } + + if(argtab["number"]!="") + numberformat=argtab["number"] + else + { + # if (sf!="") + numberformat="%u%s" + # else + # numberformat="%u" + } + + framedir= (argtab["framedir"]!="" ? argtab["framedir"] : "/aftertime/"argtab["story"]"/") + # if(sf!="") + # { + title=htmlescape(sprintf(argtab["title"(e>0 ? "-"e : "")],f,s2),"less","bb") + frame=framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f,s) + if (system("[ -f " framepath frame" ]")!=0) + { + frame= framedir sprintf(argtab["frame"],f,s) + title=htmlescape(sprintf(argtab["title"],f,s2),"less","bb") + noenh=1 + } + otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"]),s2) + # } + # else + # { + # s="" + # title=htmlescape(sprintf(argtab["title"(e>0 ? "-"e : "")],f),"less","bb") + # frame= framedir sprintf(argtab["frame"(e>0 ? "-"e : "")],f) + # if (system("[ -f " framepath frame" ]")!=0) + # { + # frame= framedir sprintf(argtab["frame"],f) + # title=htmlescape(sprintf(argtab["title"],f,s),"less","bb") + # noenh=1 + # } + # otherviewerurl=sprintf(argtab["otherviewerurl"], f+int(argtab["othervieweroffset"])) + # } + + dynamicframe="/aftertime/frame?story="argtab["story"](max_enhance>0?"&e="e:"")"&f="f s + + if((f>last || fthis_sf)) && argtab["cfrt"]!="") + frame= framedir argtab["cfrt"] + + border= int(argtab["border"]) + if(argtab["width"]!="") + width= int(argtab["width"]) + 2*border + else + width="100%" + max_enhance=int(argtab["enhance"]) + + if (this_sf=="") + { + next_f= f+1 + next_s= "" + } + else if(s=="") + { + next_f=f + next_s="a" + } + else if(s>=this_sf) + { + next_f= f+1 + next_s= "" + } + else + { + next_f = f + next_s = num2ch[ch2num[s]+1] + } + + if(this_sf!="" && s!="") + { + prev_f = f + prev_s = num2ch[ch2num[s]-1] + } + else if(prev_sf!="") + { + prev_f = f-1 + prev_s = prev_sf + } + else + { + prev_f = f-1 + prev_s = "" + } + + if(prev_s!=""){ + if(argtab[prev_s]!=""){ + prev_s2=argtab[prev_s] + } + else + { + prev_s2=prev_s + } + } + else + prev_s2 = "" + if (next_s!="") + { + if(argtab[next_s]!=""){ + next_s2=argtab[next_s] + } + else + { + next_s2=next_s + } + } + else + next_s2 = "" + + print "" + print "" + print ""title" • time after Time viewer • Bicycles on the Moon" + print "" + print "" + print "" + print "" + print "0?"&e="e:"")"&f="first"\">" + if(f>first) + { + print "0?"&e="e:"")"&f="prev_f prev_s"\">" + } + if(f0?"&e="e:"")"&f="next_f next_s"\">" + print "0?"&e="e:"")"&f="next_f next_s"\">" + } + print "
" + print "\"1190.bicyclesonthemoon.info\"
" + print "

"title"

" + print "" + print "" + + if(ongoing==1) + { + # print "" + } + + if(onlyframe=="") + { + if(max_enhance>0) + { + print "" + } + + print "" + print "" + print "" + print "" + print "" + print "" + + if(ongtimetext!="") + { + if(argtab["ID"]!="") + { + print "" + } + # else if (argtab["otherviewerurl"]!="") + # { + # print "" + # } + else + print "" + } + + if(argtab["HTML"]!="" && b==0) + { + print "" + } + + for(i=-1; i<=n; ++i) + { + if(i<0) + noticepost=noticepath argtab["story"]"-i" + else + noticepost=noticepath argtab["story"]"-"sprintf("%04u%s",f,s)"-"sprintf("%02u",i+1) + # print "" + split("", noticetab, ":") + for(j=0;(getline line < noticepost)>0;++j) + { + gsub(/[\r\n]/,"",line) + eq=index(line,"=") + noticetab[substr(line, 1, eq-1)]=substr(line, eq+1) + } + close(noticepost) + if(j==0) + { + if(i<0) + continue; + else + break; + } + if(i>=0) + { + nposttime=noticetab["y"]noticetab["m"]noticetab["d"]noticetab["h"] + if (thistime=0) + print "" + print"" + } + else + { + print "" + } + } + + if(b>0) + { + if (argtab["BBHTML"]!="") + { + bbtext=argtab["BBHTML"] + } + else if (argtab["text"]!="") + { + bbtext=htmlescape(argtab["text"],"less","bb") + gsub(/ /,"\\  ",bbtext) + gsub(/ /," \\ ",bbtext) + } + + print "" + + ongbotdefined="" + ongbotfile= datapath argtab["story"] "/" ((argtab["pleaseongbot"]!="")?argtab["pleaseongbot"]:"pleaseongbot") + if (system("[ -f " ongbotfile " ]")==0) + ongbotdefined=1 + + if(ongbotdefined && ongoing>0 && state>0 && state<4 && f==last && b==(alt!=""?2:1)) + { + print "" + } + if(b==1 && alt!="") + print "" + } + else + print "" + + if(argtab["otherviewerurl"]!="") + print "" + + print "" + + print "" + + print "" + } + print "
" + if(onlyframe!="") + print "0?"&e="e:"")"&f="f s"\">" + print "0 && state <2 && f==last)?dynamicframe:frame)"\" alt=\""title"\" title=\""alt"\" border=\""border"\">" + if(onlyframe!="") + print "" + print "
" + if(state<3) + { + # ongtime=int(argtab["ongtime"]) + # dt = (3600*ongtime - ( int(substr(thistime2,5,2)) + 60*int(substr(thistime2,3,2)) + 3600*( int(substr(thistime2,1,2))%int(argtab["ongtime"]) ) ))%(ongtime*3600) + # ss=(dt>0 ? sprintf("%02u",dt%60) : "NG") + # mm=sprintf("%02u",int(dt/60)%60) + # hh=sprintf("%02u",int(dt/3600)) + dt=nextong-thistime4 + if (dt<-5) + { + ss="EE" + mm="EE" + hh="EE" + } + else if (dt>0) + { + ss=sprintf("%02u",dt%60) + mm=sprintf("%02u",int(dt/60)%60) + if ((dt/3600)>99) + hh="EE" + else + hh=sprintf("%02u",int(dt/3600)) + } + else { + ss="NG" + mm="00" + hh="00" + } + } + else + { + ss="EE" + mm="EE" + hh="EE" + } + # hh=nextong" "thistime4 + timecolor=(state>1?"br":"ni") + + print "
"hh":"mm":"ss"
[" + for(i=0;i<=max_enhance;++i) + { + if(i!=0) + print "|" + # if(sf!="") + enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f,s) + # else + # enhancedframe = framedir sprintf(argtab["frame"(i>0?"-"i:"")],f) + + + if (system("[ -f " framepath enhancedframe" ]")==0) + { + if(i==e) + print""argtab["enhance-"i]"" + else + print"0)?("&b="b):"")"\">"argtab["enhance-"i]"" + } + else + print argtab["enhance-"i] + } + print "]
0?"&e="e:"")"&f="first"\">|< "sprintf(numberformat,first,"")""(f>first?"0?"&e="e:"")"&f="prev_f prev_s"\">< "sprintf(numberformat,prev_f,prev_s2)"":"")""(f0?"&e="e:"")"&f="next_f next_s"\">"sprintf(numberformat,next_f,next_s2)" >":"")"0?"&e="e:"")"&f="last"\">"sprintf(numberformat,last,"")" >|
"ongtimetext"
"ongtimetext"
"ongtimetext"
"argtab["HTML"]"
"noticetab["subject_h"]" "(noticetab["ID"]!=""?"        (OTT time travel)":"")"
"((noticetab["HTML"]!="")?noticetab["HTML"]:noticetab["BBHTML"])"
0?"&e="e:"")"&f="f s"&n="i+1"\">"noticetab["subject_h"]"
" + print"[url="botcastleurl"/aftertime/viewer?story="argtab["story"](max_enhance>0?"&e="e:"")"&f="f s"][img]"botcastleurl frame"[/img][/url]"(bbtext!=""?"
"bbtext:"")(b>1 && alt!=""?"[spoiler]"alt"[/spoiler]":"") + print"
" + print "
" + print "[]" + print "" + if(e>0 && noenh=="") + print "" + print "
[0?"&e="e:"")"&f="f s"&b=2\">spoiler]
[0?"&e="e:"")"&f="f s"&b=1\">bbcode]
["argtab["otherviewertext"]"]
Go to frame:" + print "" + if(max_enhance>0) + print "" + print "" + print "" + if(ongtimetext!="" && ongoing==0) + { + # print ongoing + # print"" + # print "" + # if(max_enhance>0) + # print "" + # print "" + print "" + # print "
" + } + + print"
Go to story:
Aftertime ONGsystem
" + + print "
1190.bicyclesonthemoon.info" + print "
" + + +} + +function htmlescape(name,less,br, len,iii,escaped,ch) +{ + len=length(name) + escaped="" + for(iii=1;iii<=len;++iii) + { + ch=substr(name,iii,1); + if(ch == "\n") + escaped = escaped ((br!="")?"
":"&#"ch2dec[ch]";") + else if(ch =="\r") + escaped = escaped ((br!="")?"":"&#"ch2dec[ch]";") + else if(ch ~ /[\" ]/ && less=="")#"#"\"" + escaped = escaped "&#"ch2dec[ch]";" + else if(ch ~ /[=<>&]/) + escaped = escaped "&#"ch2dec[ch]";" + else + escaped = escaped ch + } + return escaped +}