X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fhttp%2Ffmshttprequesthandlerfactory.cpp;fp=src%2Fhttp%2Ffmshttprequesthandlerfactory.cpp;h=819b02b06ced6c969673a841fffb8d0ead8c041d;hb=dec33c63afafabf83c3039e916725cac6faef9b3;hp=0000000000000000000000000000000000000000;hpb=9b22dd53fe62e312c1647310b7ec43aa127090af;p=fms.git
diff --git a/src/http/fmshttprequesthandlerfactory.cpp b/src/http/fmshttprequesthandlerfactory.cpp
new file mode 100644
index 0000000..819b02b
--- /dev/null
+++ b/src/http/fmshttprequesthandlerfactory.cpp
@@ -0,0 +1,93 @@
+#include "../../include/http/fmshttprequesthandlerfactory.h"
+#include "../../include/option.h"
+#include "../../include/stringfunctions.h"
+#include "../../include/http/pages/homepage.h"
+#include "../../include/http/pages/optionspage.h"
+#include "../../include/http/pages/createidentitypage.h"
+#include "../../include/http/pages/localidentitiespage.h"
+#include "../../include/http/pages/confirmpage.h"
+#include "../../include/http/pages/showcaptchapage.h"
+#include "../../include/http/pages/announceidentitypage.h"
+#include "../../include/http/pages/execquerypage.h"
+#include "../../include/http/pages/boardspage.h"
+#include "../../include/http/pages/insertedfilespage.h"
+#include "../../include/http/pages/addpeerpage.h"
+#include "../../include/http/pages/peerdetailspage.h"
+#include "../../include/http/pages/controlboardpage.h"
+#include "../../include/http/pages/peermaintenancepage.h"
+#include "../../include/http/pages/peertrustpage.h"
+
+FMSHTTPRequestHandlerFactory::FMSHTTPRequestHandlerFactory()
+{
+ // set template
+ std::string templatestr="
Home
Could not open template.htm! Place in program directory and restart!
[CONTENT]";
+ FILE *infile=fopen("template.htm","r+b");
+ if(infile)
+ {
+ fseek(infile,0,SEEK_END);
+ long len=ftell(infile);
+ std::vector data(len,0);
+ fseek(infile,0,SEEK_SET);
+ fread(&data[0],1,len,infile);
+ fclose(infile);
+ templatestr.assign(data.begin(),data.end());
+ }
+ else
+ {
+ m_log->error("HTTPThread::HTTPThread could not open template.htm");
+ }
+
+ // push back page handlers
+ m_pagehandlers.push_back(new OptionsPage(templatestr));
+ m_pagehandlers.push_back(new CreateIdentityPage(templatestr));
+ m_pagehandlers.push_back(new LocalIdentitiesPage(templatestr));
+ m_pagehandlers.push_back(new ConfirmPage(templatestr));
+ m_pagehandlers.push_back(new ShowCaptchaPage());
+ m_pagehandlers.push_back(new AnnounceIdentityPage(templatestr));
+ m_pagehandlers.push_back(new ExecQueryPage(templatestr));
+ m_pagehandlers.push_back(new BoardsPage(templatestr));
+ m_pagehandlers.push_back(new InsertedFilesPage(templatestr));
+ m_pagehandlers.push_back(new AddPeerPage(templatestr));
+ m_pagehandlers.push_back(new PeerDetailsPage(templatestr));
+ m_pagehandlers.push_back(new ControlBoardPage(templatestr));
+ m_pagehandlers.push_back(new PeerMaintenancePage(templatestr));
+ m_pagehandlers.push_back(new PeerTrustPage(templatestr));
+ // homepage must be last - catch all page handler
+ m_pagehandlers.push_back(new HomePage(templatestr));
+
+ // initialize the access control list
+ std::string aclstr;
+ std::vector aclparts;
+ Option::Instance()->Get("HTTPAccessControl",aclstr);
+ StringFunctions::Split(aclstr,",",aclparts);
+ for(std::vector::iterator i=aclparts.begin(); i!=aclparts.end(); i++)
+ {
+ m_acl.Add((*i));
+ }
+}
+
+FMSHTTPRequestHandlerFactory::~FMSHTTPRequestHandlerFactory()
+{
+
+ for(std::vector::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++)
+ {
+ delete (*i);
+ }
+
+}
+
+Poco::Net::HTTPRequestHandler *FMSHTTPRequestHandlerFactory::createRequestHandler(const Poco::Net::HTTPServerRequest &request)
+{
+ if(m_acl.IsAllowed(request.clientAddress().host()))
+ {
+ for(std::vector::iterator i=m_pagehandlers.begin(); i!=m_pagehandlers.end(); i++)
+ {
+ if((*i)->WillHandleURI(request.getURI()))
+ {
+ // we need to return a new object because the HTTPServer will destory it when it's done.
+ return (*i)->New();
+ }
+ }
+ }
+ return 0;
+}