/* * Copyright 2017 Chris Xiong * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /* * Get content of a post * query parameters: * p=: post file name * returned object: * HTML fragment of the post */ #include #include #include #include #include #include #include #include "cgiutils.hpp" #define stripr(s) s[strlen(s)-1]=='\n'?s[strlen(s)-1]=0:0 std::vector fn; char buf[262144]; size_t sz; void encrypt() { std::string b(buf,sz); for(size_t p=b.find("",p); std::string attrib=b.substr(p+11,tag_end-p-11); DOMAttrib a(attrib); std::string cont=b.substr(tag_end+1,b.find("",p)-tag_end-1); unsigned hash=5381; std::string key=a.getAttrib("key"); a.eraseAttrib("key"); for(size_t j=0;j(&cont[j]); cont[j]^=key[j%key.length()]; } a.setAttrib("encont",base64_encode(cont)); a.setAttrib("hash",std::to_string(hash)); a.setAttrib("id","encrypted"+std::to_string(i)); cont="Encrypted content here. Click here to decrypt."; b.replace(p,b.find("",p)-p,""+cont); p=b.find("",p); } memcpy(buf,b.c_str(),b.length());sz=b.length(); } int main(int argc,char** argv,char** envp) { QueryStrParser a; HTTPHeader h; if(!a.exist("p")){h.setStatusCode(400);h.print();return 0;} FILE* f=fopen(("/var/www/html/blog/content/"+a.value("p")+".txt").c_str(),"r"); if(!f){h.setStatusCode(400);h.print();return 0;} h.appendHeader("Content-type: text/plain; charset=utf-8"); h.print(); sz=fread(buf,sizeof(char),262144,f); encrypt(); fwrite(buf,sizeof(char),sz,stdout); fclose(f); return 0; }