#// verify.awk #// Check if post belongs to user #// 25.04.2015 #// #// Copyright (C) 2015 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="=" for(i=0;i<256;++i) { ch=sprintf("%c",i) hex=sprintf("%02X",i); ch2hex[ch]=hex hex2ch[hex]=ch } if(reversed!="") { ok=1 fail=0 } else { ok=0 fail=1 } } { gsub(/[\r\n]/,"",$0) eq=index($0,"=") argtab[substr($0,1,eq-1)]=substr($0,eq+1) } END{ if(argtab["username"]==""||argtab["password"]==""||(urldecode(argtab["username"])==name&&urldecode(argtab["password"])==pass)) exit ok else exit 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 urldecode(ht ,i,j,un,num) { while ((i=match(ht, /%[0-9a-fA-F][0-9a-fA-F]/))!=0)# { un=un substr(ht, 1, i-1) ht=substr(ht, i) num=toupper(substr(ht, 2, 2)) un=un hex2ch[num] ht=substr(ht, 4) } un=un ht return un }