Commit 859d0d68 authored by jan.koester's avatar jan.koester
Browse files

run now s now root user

parent 7ac214c8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3,8 +3,8 @@ project(guestbook)

find_package(libnetplus REQUIRED)
find_package(libcmdplus REQUIRED)
find_package(httppp REQUIRED)
find_package(htmlpp REQUIRED)
find_package(libhttppp REQUIRED)
find_package(libhtmlpp REQUIRED)

add_executable(guestbook main.cpp)

+17 −9
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#ifndef Windows
#include <unistd.h>
#include <sys/stat.h>
#include <pwd.h>
#define libpath(V)  ("/var/lib/guestbook/"#V)
#else
#define libpath(V)  ""(#V)""
@@ -33,7 +34,7 @@ struct Browser {

class Controller : public libhttppp::HttpEvent {
public:
    Controller(netplus::socket* serversocket) : HttpEvent(serversocket){
    Controller(netplus::socket& serversocket) : HttpEvent(serversocket){
        try{
            page.loadFile(index,HPAGE);
            rpage.loadFile(rindex,RHPAGE);
@@ -42,10 +43,10 @@ public:
        }
    };

    void BrowserDetect(libhttppp::HttpRequest *curreq,Browser &bws){
    void BrowserDetect(libhttppp::HttpRequest &curreq,Browser &bws){
        std::string txt;

        for(libhttppp::HttpHeader::HeaderData::Values *usa=curreq->getHeaderData("user-agent")->getfirstValue(); usa; usa=usa->nextvalue() ){
        for(libhttppp::HttpHeader::HeaderData::Values *usa=curreq.getHeaderData("user-agent")->getfirstValue(); usa; usa=usa->nextvalue() ){
            txt+=usa->getvalue();
        }

@@ -90,19 +91,19 @@ public:
    }


    void RequestEvent(libhttppp::HttpRequest *curreq,int tid,ULONG_PTR args){
    void RequestEvent(libhttppp::HttpRequest &curreq,int tid,ULONG_PTR args){
            try {
                libhttppp::HttpForm gform;

                if(curreq->getRequestType()==POSTREQUEST){
                if(curreq.getRequestType()==POSTREQUEST){
                    try{
                        std::string guestname,guestentry;
                        gform.parse(curreq);
                        for (libhttppp::HttpForm::UrlcodedForm::Data * cururlform = gform.UrlFormData.getFormData(); cururlform;
                             cururlform = cururlform->nextData()) {
                            if(strcmp("guestname",cururlform->getKey())==0){
                            if("guestname"==cururlform->getKey()){
                                guestname=cururlform->getValue();
                            }else if(strcmp("guestentry",cururlform->getKey())==0){
                            }else if(cururlform->getKey()=="guestentry"){
                                guestentry=cururlform->getValue();
                            }
                             }
@@ -118,7 +119,7 @@ public:
                             }
                    }catch(libhttppp::HTTPException &e){
                        std::cout << e.what() << std::endl;
                        std::cout.write(curreq->RecvData.data(),curreq->RecvData.size()) <<std::endl;
                        std::cout.write(curreq.RecvData.data(),curreq.RecvData.size()) <<std::endl;
                        return;
                    }
                }
@@ -183,7 +184,7 @@ public:
                    curres.setState(HTTP500);
                    curres.setVersion(HTTPVERSION(2.0));
                    curres.setContentLength(0);
                    curres.send(curreq, e.what(), strlen(e.what()));
                    curres.send(curreq, e.what(),e.what().length());
                }
            }
    }
@@ -218,6 +219,13 @@ public:
            pidf.close();

            Controller ctl(getServerSocket());

            struct passwd *pwd = new passwd;
            char pwbuf[255];
            getpwnam_r("guestbook",pwd,pwbuf,255,&pwd);
            setuid(pwd->pw_uid);
            delete pwd;

            ctl.runEventloop();
#else
        Controller ctl(getServerSocket());