version 0.3.4
[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")\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                 std::string currentmajor=VERSION_MAJOR;\r
40                 std::string currentminor=VERSION_MINOR;\r
41                 std::string currentrelease=VERSION_RELEASE;\r
42                 std::string major="";\r
43                 std::string minor="";\r
44                 std::string release="";\r
45                 std::string freesite="";\r
46                 st.ResultText(0,major);\r
47                 st.ResultText(1,minor);\r
48                 st.ResultText(2,release);\r
49                 st.ResultText(3,freesite);\r
50 \r
51                 if(currentmajor<major || (currentmajor==major && currentminor<minor) || (currentmajor==major && currentminor==minor && currentrelease<release))\r
52                 {\r
53                         content+="<b>You are running an old version of FMS.  Please update here: <a href=\"http://"+fcphost+":"+fproxyport+"/"+freesite+"\">FMS "+major+"."+minor+"."+release+"</a></b><br>";\r
54                         showgenericupdate=false;\r
55                 }\r
56 \r
57         }\r
58 \r
59         if(showgenericupdate)\r
60         {\r
61                 content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/63/\">FMS Freesite</a><br>";\r
62         }\r
63 \r
64         content+="Use these pages to administer your FMS installation.";\r
65         content+="</p>";\r
66 \r
67         st=m_db->Prepare("SELECT COUNT(*) FROM tblMessageInserts WHERE Inserted='false';");\r
68         st.Step();\r
69         if(st.RowReturned())\r
70         {\r
71                 st.ResultText(0,messagecountstr);\r
72         }\r
73         content+="Messages waiting to be inserted:"+messagecountstr+"<br>";\r
74         st=m_db->Prepare("SELECT COUNT(*) FROM tblFileInserts WHERE Key IS NULL;");\r
75         st.Step();\r
76         if(st.RowReturned())\r
77         {\r
78                 st.ResultText(0,filecountstr);\r
79         }\r
80         content+="Files waiting to be inserted:"+filecountstr+"<br>";\r
81 \r
82         content+="<p class=\"paragraph\">";\r
83         content+="<form name=\"frmshutdown\" method=\"POST\">";\r
84         content+="<input type=\"hidden\" name=\"formaction\" value=\"shutdown\">";\r
85         content+="<input type=\"submit\" value=\"Shutdown FMS\">";\r
86         content+="</form>";\r
87         content+="</p>";\r
88 \r
89         return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
90 }\r
91 \r
92 const bool HomePage::WillHandleURI(const std::string &uri)\r
93 {\r
94         return true;\r
95 }\r