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