Loading data/template/default/cookie.html +2 −1 Original line number Diff line number Diff line Loading @@ -11,10 +11,11 @@ </head> <body> <img alt="test" src="public/header.webp" > <div id="cookiebanner"></div> <div id="cookiebanner"> <div id="cookiesettings"> </div> <div id="cookieform"> </div> </div> </body> </html> src/auth.cpp +0 −2 Original line number Diff line number Diff line Loading @@ -222,8 +222,6 @@ LDAPLOGINUSERFOUND: #endif bool blogi::Auth::isLoggedIn(const int tid,libhttppp::HttpRequest *curreq,const char *ssid){ libhttppp::HttpCookie cookie; cookie.parse(curreq); try{ std::string storeid; _session->getSessionData(ssid,"uid",storeid); Loading src/blogi.cpp +29 −17 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. blogi::Blogi::Blogi(Config *blgcfg,netplus::socket *serversocket,bool debug) : HttpEvent(serversocket){ PlgArgs = new PluginArgs; PlgArgs->debug=debug; PlgArgs->config=blgcfg; Loading Loading @@ -92,6 +91,14 @@ blogi::Blogi::Blogi(Config *blgcfg,netplus::socket *serversocket,bool debug) : H PlgArgs->maxthreads=threads; libhtmlpp::HtmlPage cookiehtml; std::string cookhtmlfile=tplcfg.config->gettemplate(); cookhtmlfile.append("/"); cookhtmlfile.append("cookie.html"); cookiehtml.loadFile(CookieEl,cookhtmlfile.c_str()); addRule("blogi","technical","Technical Required","This Cookie is Required for Authentication and some Basic Funtions of this Blog",true); BlogiPlg = new Plugin(); for(int i=0; i<PlgArgs->config->getplgdirs(); ++i){ Loading Loading @@ -296,6 +303,13 @@ RETRY_REQUEST: libhttppp::HttpCookie cookie; libhttppp::HttpResponse curres; const char *sessid=nullptr; libhtmlpp::HtmlElement index; if(curreq->isMobile()) index=MIndex; else index=Index; try{ cookie.parse(curreq); for(libhttppp::HttpCookie::CookieData *curcookie=cookie.getfirstCookieData(); Loading @@ -303,19 +317,21 @@ RETRY_REQUEST: if(curcookie->getKey() && strcmp(curcookie->getKey(),"sessionid")==0) sessid=curcookie->getValue(); } if(!PlgArgs->session->exists(sessid) ) throw "session not exists"; if(!PlgArgs->session->exists(sessid) ){ throw "session not found !"; } }catch(...){ print(index); sessid=PlgArgs->session->createSession(); cookie.setcookie(&curres, "sessionid", sessid,nullptr,nullptr,-1,"/",false,"1","Lax"); curres.setState(HTTP307); curres.setVersion(HTTPVERSION(1.1)); *curres.setData("Location") << curreq->getRequest(); curres.setContentType("text/html"); curres.send(curreq, nullptr, 0); return; // cookie.setcookie(&curres, "sessionid", sessid,nullptr,nullptr,-1,"/",false,"1","Lax"); // curres.setState(HTTP307); // curres.setVersion(HTTPVERSION(1.1)); // *curres.setData("Location") << curreq->getRequest(); // curres.setContentType("text/html"); // curres.send(curreq, nullptr, 0); // return; } std::cerr << sessid << std::endl; try{ /*blogi internal pages and redirections*/ if(strcmp(curreq->getRequestURL(),"/")==0 || strcmp(curreq->getRequestURL(),PlgArgs->config->getprefix())==0){ Loading Loading @@ -347,13 +363,8 @@ RETRY_REQUEST: return; } if(!PlgArgs->theme->Controller(tid,curreq)){ libhtmlpp::HtmlElement index; if(curreq->isMobile()) index=MIndex; else index=Index; if(!PlgArgs->theme->Controller(tid,curreq)){ for(blogi::Plugin::PluginData *curplg=BlogiPlg->getFirstPlugin(); curplg; curplg=curplg->getNextPlg()){ if(curreq->isMobile()) curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Mobile,sessid); Loading @@ -368,6 +379,7 @@ RETRY_REQUEST: url+=api->getName(); if(strncmp(curreq->getRequestURL(),url.c_str(),url.length())==0){ if(api->Controller(tid,curreq,&index,sessid)){ std::cout << api->getName() << std::endl; return; } } Loading src/cookie.cpp +26 −3 Original line number Diff line number Diff line Loading @@ -39,25 +39,48 @@ void blogi::CookieBanner::setPermission(const char *sessionid,const char* prefix } void blogi::CookieBanner::addRule(const char* pref, const char* cookname, const char* dspname, const char* desc){ void blogi::CookieBanner::addRule(const char* pref, const char* cookname, const char* dspname, const char* desc,bool req){ Rule rule; std::copy(pref,pref+strlen(pref)+1,std::back_inserter<std::vector<char>>(rule.prefix)); std::copy(cookname,cookname+strlen(cookname)+1,std::back_inserter<std::vector<char>>(rule.name)); std::copy(dspname,dspname+strlen(dspname)+1,std::back_inserter<std::vector<char>>(rule.displayname)); std::copy(desc,desc+strlen(desc)+1,std::back_inserter<std::vector<char>>(rule.description)); rule.required=req; Rules.push_back(rule); } blogi::CookieBanner::Rule::Rule(blogi::CookieBanner::Rule& src){ void blogi::CookieBanner::print(libhtmlpp::HtmlElement& page){ libhtmlpp::HtmlTable ctable; libhtmlpp::HtmlElement cookel=CookieEl.getElementbyID("cookiebanner"),cookset; for(auto i : Rules){ ctable << libhtmlpp::HtmlTable::Row() << static_cast<const char *>(i.displayname.data()); } ctable.insert(&cookset); if(cookel.getElementbyID("cookiesettings")) cookel.getElementbyID("cookiesettings")->appendChild(&cookset); libhtmlpp::HtmlElement *idx=page.getElementbyTag("body"); if(idx) idx->appendChild(&cookel); } blogi::CookieBanner::Rule::Rule(const blogi::CookieBanner::Rule& src){ name=src.name; prefix=src.prefix; displayname=src.displayname; description=src.description; required=src.required; } blogi::CookieBanner::Rule & blogi::CookieBanner::Rule::operator=(blogi::CookieBanner::Rule& src){ blogi::CookieBanner::Rule & blogi::CookieBanner::Rule::operator=(const blogi::CookieBanner::Rule& src){ name=src.name; prefix=src.prefix; displayname=src.displayname; description=src.description; required=src.required; return *this; } src/cookie.h +8 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <vector> #include <htmlpp/html.h> #include "session.h" Loading @@ -34,9 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace blogi { class CookieBanner { public: void addRule(const char *pref,const char* cookname,const char* dspname,const char* desc); void addRule(const char *pref,const char* cookname,const char* dspname,const char* desc,bool req); bool getPermission(const char *sessionid,const char *prefix,const char *cookiename); void print(libhtmlpp::HtmlElement &page); protected: CookieBanner(){}; ~CookieBanner(){}; Loading @@ -45,14 +48,16 @@ namespace blogi { struct Rule{ Rule(){}; Rule(Rule &src); Rule &operator=(Rule &src); Rule(const Rule &src); Rule &operator=(const Rule &src); std::vector<char> name; std::vector<char> prefix; std::vector<char> displayname; std::vector<char> description; bool required; }; std::vector<Rule> Rules; libhtmlpp::HtmlElement CookieEl; }; }; Loading
data/template/default/cookie.html +2 −1 Original line number Diff line number Diff line Loading @@ -11,10 +11,11 @@ </head> <body> <img alt="test" src="public/header.webp" > <div id="cookiebanner"></div> <div id="cookiebanner"> <div id="cookiesettings"> </div> <div id="cookieform"> </div> </div> </body> </html>
src/auth.cpp +0 −2 Original line number Diff line number Diff line Loading @@ -222,8 +222,6 @@ LDAPLOGINUSERFOUND: #endif bool blogi::Auth::isLoggedIn(const int tid,libhttppp::HttpRequest *curreq,const char *ssid){ libhttppp::HttpCookie cookie; cookie.parse(curreq); try{ std::string storeid; _session->getSessionData(ssid,"uid",storeid); Loading
src/blogi.cpp +29 −17 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. blogi::Blogi::Blogi(Config *blgcfg,netplus::socket *serversocket,bool debug) : HttpEvent(serversocket){ PlgArgs = new PluginArgs; PlgArgs->debug=debug; PlgArgs->config=blgcfg; Loading Loading @@ -92,6 +91,14 @@ blogi::Blogi::Blogi(Config *blgcfg,netplus::socket *serversocket,bool debug) : H PlgArgs->maxthreads=threads; libhtmlpp::HtmlPage cookiehtml; std::string cookhtmlfile=tplcfg.config->gettemplate(); cookhtmlfile.append("/"); cookhtmlfile.append("cookie.html"); cookiehtml.loadFile(CookieEl,cookhtmlfile.c_str()); addRule("blogi","technical","Technical Required","This Cookie is Required for Authentication and some Basic Funtions of this Blog",true); BlogiPlg = new Plugin(); for(int i=0; i<PlgArgs->config->getplgdirs(); ++i){ Loading Loading @@ -296,6 +303,13 @@ RETRY_REQUEST: libhttppp::HttpCookie cookie; libhttppp::HttpResponse curres; const char *sessid=nullptr; libhtmlpp::HtmlElement index; if(curreq->isMobile()) index=MIndex; else index=Index; try{ cookie.parse(curreq); for(libhttppp::HttpCookie::CookieData *curcookie=cookie.getfirstCookieData(); Loading @@ -303,19 +317,21 @@ RETRY_REQUEST: if(curcookie->getKey() && strcmp(curcookie->getKey(),"sessionid")==0) sessid=curcookie->getValue(); } if(!PlgArgs->session->exists(sessid) ) throw "session not exists"; if(!PlgArgs->session->exists(sessid) ){ throw "session not found !"; } }catch(...){ print(index); sessid=PlgArgs->session->createSession(); cookie.setcookie(&curres, "sessionid", sessid,nullptr,nullptr,-1,"/",false,"1","Lax"); curres.setState(HTTP307); curres.setVersion(HTTPVERSION(1.1)); *curres.setData("Location") << curreq->getRequest(); curres.setContentType("text/html"); curres.send(curreq, nullptr, 0); return; // cookie.setcookie(&curres, "sessionid", sessid,nullptr,nullptr,-1,"/",false,"1","Lax"); // curres.setState(HTTP307); // curres.setVersion(HTTPVERSION(1.1)); // *curres.setData("Location") << curreq->getRequest(); // curres.setContentType("text/html"); // curres.send(curreq, nullptr, 0); // return; } std::cerr << sessid << std::endl; try{ /*blogi internal pages and redirections*/ if(strcmp(curreq->getRequestURL(),"/")==0 || strcmp(curreq->getRequestURL(),PlgArgs->config->getprefix())==0){ Loading Loading @@ -347,13 +363,8 @@ RETRY_REQUEST: return; } if(!PlgArgs->theme->Controller(tid,curreq)){ libhtmlpp::HtmlElement index; if(curreq->isMobile()) index=MIndex; else index=Index; if(!PlgArgs->theme->Controller(tid,curreq)){ for(blogi::Plugin::PluginData *curplg=BlogiPlg->getFirstPlugin(); curplg; curplg=curplg->getNextPlg()){ if(curreq->isMobile()) curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Mobile,sessid); Loading @@ -368,6 +379,7 @@ RETRY_REQUEST: url+=api->getName(); if(strncmp(curreq->getRequestURL(),url.c_str(),url.length())==0){ if(api->Controller(tid,curreq,&index,sessid)){ std::cout << api->getName() << std::endl; return; } } Loading
src/cookie.cpp +26 −3 Original line number Diff line number Diff line Loading @@ -39,25 +39,48 @@ void blogi::CookieBanner::setPermission(const char *sessionid,const char* prefix } void blogi::CookieBanner::addRule(const char* pref, const char* cookname, const char* dspname, const char* desc){ void blogi::CookieBanner::addRule(const char* pref, const char* cookname, const char* dspname, const char* desc,bool req){ Rule rule; std::copy(pref,pref+strlen(pref)+1,std::back_inserter<std::vector<char>>(rule.prefix)); std::copy(cookname,cookname+strlen(cookname)+1,std::back_inserter<std::vector<char>>(rule.name)); std::copy(dspname,dspname+strlen(dspname)+1,std::back_inserter<std::vector<char>>(rule.displayname)); std::copy(desc,desc+strlen(desc)+1,std::back_inserter<std::vector<char>>(rule.description)); rule.required=req; Rules.push_back(rule); } blogi::CookieBanner::Rule::Rule(blogi::CookieBanner::Rule& src){ void blogi::CookieBanner::print(libhtmlpp::HtmlElement& page){ libhtmlpp::HtmlTable ctable; libhtmlpp::HtmlElement cookel=CookieEl.getElementbyID("cookiebanner"),cookset; for(auto i : Rules){ ctable << libhtmlpp::HtmlTable::Row() << static_cast<const char *>(i.displayname.data()); } ctable.insert(&cookset); if(cookel.getElementbyID("cookiesettings")) cookel.getElementbyID("cookiesettings")->appendChild(&cookset); libhtmlpp::HtmlElement *idx=page.getElementbyTag("body"); if(idx) idx->appendChild(&cookel); } blogi::CookieBanner::Rule::Rule(const blogi::CookieBanner::Rule& src){ name=src.name; prefix=src.prefix; displayname=src.displayname; description=src.description; required=src.required; } blogi::CookieBanner::Rule & blogi::CookieBanner::Rule::operator=(blogi::CookieBanner::Rule& src){ blogi::CookieBanner::Rule & blogi::CookieBanner::Rule::operator=(const blogi::CookieBanner::Rule& src){ name=src.name; prefix=src.prefix; displayname=src.displayname; description=src.description; required=src.required; return *this; }
src/cookie.h +8 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ #include <vector> #include <htmlpp/html.h> #include "session.h" Loading @@ -34,9 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace blogi { class CookieBanner { public: void addRule(const char *pref,const char* cookname,const char* dspname,const char* desc); void addRule(const char *pref,const char* cookname,const char* dspname,const char* desc,bool req); bool getPermission(const char *sessionid,const char *prefix,const char *cookiename); void print(libhtmlpp::HtmlElement &page); protected: CookieBanner(){}; ~CookieBanner(){}; Loading @@ -45,14 +48,16 @@ namespace blogi { struct Rule{ Rule(){}; Rule(Rule &src); Rule &operator=(Rule &src); Rule(const Rule &src); Rule &operator=(const Rule &src); std::vector<char> name; std::vector<char> prefix; std::vector<char> displayname; std::vector<char> description; bool required; }; std::vector<Rule> Rules; libhtmlpp::HtmlElement CookieEl; }; };