ec4ea3298faf550cd9f0fd06eca2d82a57365803
[fms.git] / src / http / pages / homepage.cpp
1 #include "../../../include/http/pages/homepage.h"\r
2 #include "../../../include/stringfunctions.h"\r
3 #include "../../../include/global.h"\r
4 #include "../../../include/fmsapp.h"\r
5 #include "../../../include/option.h"\r
6 \r
7 #ifdef XMEM\r
8         #include <xmem.h>\r
9 #endif\r
10 \r
11 const std::string HomePage::GeneratePage(const std::string &method, const std::map<std::string,std::string> &queryvars)\r
12 {\r
13 \r
14         std::string messagecountstr="";\r
15         std::string filecountstr="";\r
16         std::string fcphost="127.0.0.1";\r
17         std::string fproxyport="8888";\r
18 \r
19         Option::Instance()->Get("FCPHost",fcphost);\r
20         Option::Instance()->Get("FProxyPort",fproxyport);\r
21 \r
22         if(queryvars.find("formaction")!=queryvars.end() && (*queryvars.find("formaction")).second=="shutdown" && ValidateFormPassword(queryvars))\r
23         {\r
24                 m_log->trace("HomePage::GeneratePage requested shutdown");\r
25                 ((FMSApp *)&FMSApp::instance())->Terminate();\r
26         }\r
27 \r
28         std::string content="<h2>Home</h2>";\r
29         content+="<p class=\"paragraph\">";\r
30         content+="<b>FMS version ";\r
31         content+=FMS_VERSION;\r
32         content+="</b><br>";\r
33 \r
34         bool showgenericupdate=true;\r
35         SQLite3DB::Statement st=m_db->Prepare("SELECT Major, Minor, Release, PageKey FROM tblFMSVersion ORDER BY Major DESC, Minor DESC, Release DESC LIMIT 1;");\r
36         st.Step();\r
37         if(st.RowReturned())\r
38         {\r
39                 int major=0;\r
40                 int minor=0;\r
41                 int release=0;\r
42                 int currentmajor=0;\r
43                 int currentminor=0;\r
44                 int currentrelease=0;\r
45                 std::string freesite="";\r
46                 std::string majorstr="";\r
47                 std::string minorstr="";\r
48                 std::string releasestr="";\r
49 \r
50                 StringFunctions::Convert(VERSION_MAJOR,currentmajor);\r
51                 StringFunctions::Convert(VERSION_MINOR,currentminor);\r
52                 StringFunctions::Convert(VERSION_RELEASE,currentrelease);\r
53 \r
54                 st.ResultInt(0,major);\r
55                 st.ResultInt(1,minor);\r
56                 st.ResultInt(2,release);\r
57                 st.ResultText(3,freesite);\r
58 \r
59                 StringFunctions::Convert(major,majorstr);\r
60                 StringFunctions::Convert(minor,minorstr);\r
61                 StringFunctions::Convert(release,releasestr);\r
62 \r
63                 if(currentmajor<major || (currentmajor==major && currentminor<minor) || (currentmajor==major && currentminor==minor && currentrelease<release))\r
64                 {\r
65                         content+="<b>You are running an old version of FMS.  Please update here: <a href=\"http://"+fcphost+":"+fproxyport+"/"+freesite+"\">FMS "+majorstr+"."+minorstr+"."+releasestr+"</a></b><br>";\r
66                         content+="You can see the release info <a href=\"versioninfo.htm?Major="+majorstr+"&Minor="+minorstr+"&Release="+releasestr+"\">here</a><br>";\r
67                         showgenericupdate=false;\r
68                 }\r
69                 else\r
70                 {\r
71                         content+="<a href=\"versioninfo.htm\">Release info</a><br>";\r
72                 }\r
73 \r
74         }\r
75 \r
76         if(showgenericupdate)\r
77         {\r
78                 content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/"+FMS_FREESITE_USK+"\">FMS Freesite</a><br>";\r
79         }\r
80 \r
81         content+="Use these pages to administer your FMS installation.";\r
82         content+="</p>";\r
83 \r
84         st=m_db->Prepare("SELECT COUNT(*) FROM tblMessageInserts WHERE Inserted='false';");\r
85         st.Step();\r
86         if(st.RowReturned())\r
87         {\r
88                 st.ResultText(0,messagecountstr);\r
89         }\r
90         content+="Messages waiting to be inserted:"+messagecountstr+"<br>";\r
91         st=m_db->Prepare("SELECT COUNT(*) FROM tblFileInserts WHERE Key IS NULL;");\r
92         st.Step();\r
93         if(st.RowReturned())\r
94         {\r
95                 st.ResultText(0,filecountstr);\r
96         }\r
97         content+="Files waiting to be inserted:"+filecountstr+"<br>";\r
98 \r
99         content+="<p class=\"paragraph\">";\r
100         content+="<form name=\"frmshutdown\" method=\"POST\">";\r
101         content+=CreateFormPassword();\r
102         content+="<input type=\"hidden\" name=\"formaction\" value=\"shutdown\">";\r
103         content+="<input type=\"submit\" value=\"Shutdown FMS\">";\r
104         content+="</form>";\r
105         content+="</p>";\r
106 \r
107         return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
108 }\r
109 \r
110 const bool HomePage::WillHandleURI(const std::string &uri)\r
111 {\r
112         return true;\r
113 }\r