a37d50f92270991aaee786d85b725ceca053c335
[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                 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 \r
70         }\r
71 \r
72         if(showgenericupdate)\r
73         {\r
74                 content+="Check for new versions at the <a href=\"http://"+fcphost+":"+fproxyport+"/USK@0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/69/\">FMS Freesite</a><br>";\r
75         }\r
76 \r
77         content+="Use these pages to administer your FMS installation.";\r
78         content+="</p>";\r
79 \r
80         st=m_db->Prepare("SELECT COUNT(*) FROM tblMessageInserts WHERE Inserted='false';");\r
81         st.Step();\r
82         if(st.RowReturned())\r
83         {\r
84                 st.ResultText(0,messagecountstr);\r
85         }\r
86         content+="Messages waiting to be inserted:"+messagecountstr+"<br>";\r
87         st=m_db->Prepare("SELECT COUNT(*) FROM tblFileInserts WHERE Key IS NULL;");\r
88         st.Step();\r
89         if(st.RowReturned())\r
90         {\r
91                 st.ResultText(0,filecountstr);\r
92         }\r
93         content+="Files waiting to be inserted:"+filecountstr+"<br>";\r
94 \r
95         content+="<p class=\"paragraph\">";\r
96         content+="<form name=\"frmshutdown\" method=\"POST\">";\r
97         content+="<input type=\"hidden\" name=\"formaction\" value=\"shutdown\">";\r
98         content+="<input type=\"submit\" value=\"Shutdown FMS\">";\r
99         content+="</form>";\r
100         content+="</p>";\r
101 \r
102         return StringFunctions::Replace(m_template,"[CONTENT]",content);\r
103 }\r
104 \r
105 const bool HomePage::WillHandleURI(const std::string &uri)\r
106 {\r
107         return true;\r
108 }\r