Fotobot
Get data from your photovoltaic plant
webpage.cpp
Go to the documentation of this file.
1 
7 #include "webpage.h"
8 #include "static.h"
9 #include "version.h"
10 #include <QVariant>
11 #include <QDateTime>
12 
14  m_needs_access_data = true;
15  m_needs_change_settings = true;
16  m_response = NULL;
17  m_cacheable = false;
18 }
19 
20 void WebPage::service(HttpRequest& request, HttpResponse& response) {
21  m_response = &response;
22  m_request = &request;
23 
24  if(!m_cacheable) {
25  response.setHeader("Cache-Control", "private, must-revalidate, max-age=0");
26  response.setHeader("Pragma", "no-cache");
27  }
28 
29  if (needsLogin(request,response)) {
30  return;
31  }
32 
33  servicePrivate (request);
34  writeHeader (request,response);
35  response.write (m_body);
36  writeFooter (request,response);
37 }
38 
39 void WebPage::redirect(const QString& location) {
40  setStatus(301, "Moved Permanently");
41  setHeader("Location", location.toUtf8());
42  setHeader("Content-Type", "text/html; charset=utf-8");
43  write(tr("<h1>Moved Permanently</h1><p>The document has moved <a href=\"%1\">here</a>.</p>\n").arg(location));
44 }
45 
46 QString WebPage::percentEncode(const QString& s) {
47  return QString(s.toUtf8().toPercentEncoding());
48 }
49 
50 void WebPage::writeFooter(HttpRequest& request, HttpResponse& response) {
51  Q_UNUSED(request);
52  response.write("</div><!-- content -->\n"
53  "</div><!-- page -->\n"
54  "</body></html>");
55 }
56 
60 void WebPage::writeHeader(HttpRequest& request, HttpResponse& response) {
61  QString body ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n"
62  " \"http://www.w3.org/TR/html4/strict.dtd\">\n"
63  "<html><head>\n"
64  "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"
65  "<title>Fotobot</title>\n"
66  "<link href=\"/style.css\" rel=\"stylesheet\" type=\"text/css\">\n"
67  "<script type=\"text/javascript\">\n");
68  body.append(m_javascript);
69  body.append(tr("</script>\n"
70  "</head>\n"
71  "<body>\n"
72  "<div id=\"page\">\n"
73  "<div id=\"header\">\n"
74  "<div id=\"logo\">\n"
75  "<h1>Fotobot</h1>\n"
76  "<p>Collects data from your photovoltaic plant<br/>Made by <a href=\"http://hobrasoft.cz/\">Hobrasoft s.r.o.</a></p>\n"
77  "<p class=\"clear\"></p></div><!-- logo -->\n"
78  "<div id=\"menu\">\n"
79  "<ul>\n"
80  ));
81  body.append(QString("<li><a href=\"/\">%1</a></li>\n").arg(tr("Main Page")));
82  body.append(QString("<li><a href=\"/export\">%1</a></li>\n").arg(tr("Current data")));
83  body.append(QString("<li><a href=\"/settings\">%1</a><ul>\n").arg(tr("Settings")));
84  body.append(QString("<li><a href=\"/lines\">%1</a></li>\n").arg(tr("Lines")));
85  body.append(QString("<li><a href=\"/invertors\">%1</a></li>\n").arg(tr("Invertors")));
86  body.append(QString("<li><a href=\"/interfaceboxes\">%1</a></li>\n").arg(tr("Interfaceboxes")));
87  body.append(QString("<li><a href=\"/interfaceboxes?action=restart\">%1</a></li>\n").arg(tr("Interfaceboxes restart")));
88  body.append(QString("<li><a href=\"/geocoordinates\">%1</a></li>\n").arg(tr("Geographical coordinates")));
89  #ifdef GENTOO
90  body.append(QString("<li><a href=\"/network\">%1</a></li>\n").arg(tr("Network settings")));
91  #endif
92  body.append(QString("<li><a href=\"/login?action=chpw\">%1</a></li>\n").arg(tr("Change Password")));
93  body.append(QString("<li><a href=\"/users\">%1</a></li>\n").arg(tr("Users")));
94  body.append("</ul></li>\n");
95 
96  HttpSession session=Static::sessionStore->getSession(request,response);
97  if (session.contains("username")) {
98  body.append(QString("<li><a href=\"/login?logout=true\">%1</a></li>").arg(tr("Log out")));
99  } else {
100  body.append(QString("<li><a href=\"/login\">%1</a></li>\n").arg(tr("Log in")));
101  }
102 
103  body.append("</ul><p class=\"clear\"></p></div><!-- menu -->\n");
104  body.append("</div><!-- header -->\n");
105 
106  QString message = QString::fromUtf8(QByteArray::fromPercentEncoding(request.getParameter("message")));
107  if(!message.isEmpty()) {
108  body.append(QString("<p class=\"message\">%1</p>").arg(message));
109  }
110 
111  body.append("<div id=\"content\">");
112  response.write(body.toUtf8());
113 }
114 
115 
116 void WebPage::about() {
117  write(QString("<h2>%1</h2>\n").arg(tr("About")));
118  write(QString("<p>%1 %2</p>\n").arg(tr("Version")).arg(VERSION));
119  write(tr(
120  "<p>Application Fotobot is made by <a href=\"http://hobrasoft.cz\">Hobrasoft s.r.o.</a>\n"
121  "It is a part of complex photovoltaic suite:</p>\n"
122  "<ul>\n"
123  "<li><a href=http://hobrasoft.cz/en/fotomon/fotomon>Fotomon</a> - monitoring, analyses and report making software for central monitoring services.</li>\n"
124  "<li><a href=http://fm.solartec.cz/>Fotoweb</a> - web for photovoltaic system owner, a lot of graphs, businness information and detailed operating log for every photovoltaic plant.</li>\n"
125  "<li><a href=http://hobrasoft.cz/en/fotomon/fotobot>Fotobot</a> - simple but very quick application to collect data from your photovoltaic plant.</li>\n"
126  "<li><a href=http://hobrasoft.cz/en/fotobothw>FotobotHW</a> - small but powerfull computer to collect data from photovoltaic plant. Based on Linux, BeagleBone, Hobrasoft 4&nbsp;&times;&nbsp;RS232</li>\n"
127  "</ul>\n"
128  "<p>Home page: <a href=\"http://hobrasoft.cz/fotobot\">http://hobrasoft.cz/fotobot</a></p>\n"
129  "<p>Application Fotobot is available under <a href=\"http://www.gnu.org/copyleft/gpl.html\">GPL license</a></p>"
130  ));
131 }
132 
WebPage()
Definition: webpage.cpp:13
static HttpSessionStore * sessionStore
Definition: static.h:57
virtual void writeHeader(HttpRequest &request, HttpResponse &response)
Definition: webpage.cpp:60