Fotobot
Get data from your photovoltaic plant
Public Member Functions | Private Member Functions | Private Attributes | List of all members
NetworkController Class Reference
Inheritance diagram for NetworkController:
WebPage MRequestHandler

Public Member Functions

 NetworkController ()
 
void servicePrivate (HttpRequest &request)
 
- Public Member Functions inherited from WebPage
 WebPage ()
 
virtual void service (HttpRequest &request, HttpResponse &response)
 
void redirect (const QString &location)
 
- Public Member Functions inherited from MRequestHandler
 MRequestHandler ()
 

Private Member Functions

 Q_DISABLE_COPY (NetworkController)
 
void actionApply (HttpRequest &request)
 
void getConfigValues ()
 

Private Attributes

QString m_hostname
 
bool m_ipv4_dhcp
 
QString m_ipv4_addr
 
QString m_ipv4_mask
 
QString m_ipv4_router
 
QString m_ipv4_dns
 

Additional Inherited Members

- Static Public Member Functions inherited from WebPage
static QString percentEncode (const QString &s)
 
- Protected Member Functions inherited from WebPage
void setStatus (int code, QByteArray description)
 
void setHeader (QByteArray name, QByteArray value)
 
void setHeader (QByteArray name, int value)
 
void write (QByteArray data)
 
void write (QString data)
 
void write (const char *data)
 
void about ()
 
HttpSession getSession ()
 
virtual void writeHeader (HttpRequest &request, HttpResponse &response)
 
virtual void writeFooter (HttpRequest &request, HttpResponse &response)
 
- Protected Member Functions inherited from MRequestHandler
bool needsLogin (HttpRequest &request, HttpResponse &response)
 
- Protected Attributes inherited from WebPage
QString m_javascript
 
- Protected Attributes inherited from MRequestHandler
bool m_needs_access_data
 
bool m_needs_change_settings
 
bool m_cacheable
 

Detailed Description

Definition at line 16 of file networkcontroller.h.

Constructor & Destructor Documentation

NetworkController::NetworkController ( )

Constructor

Definition at line 19 of file networkcontroller.cpp.

19  {
20 }

Member Function Documentation

void NetworkController::actionApply ( HttpRequest &  request)
private

Read form HTTP post reply and load into the line

Definition at line 119 of file networkcontroller.cpp.

119  {
120  m_hostname = request.getParameter("hostname");
121  m_ipv4_dhcp = ( request.getParameter("ipv4_dhcp") == "Y") ? true : false;
122  m_ipv4_addr = request.getParameter("ipv4_addr");
123  m_ipv4_mask = request.getParameter("ipv4_mask");
124  m_ipv4_router = request.getParameter("ipv4_router");
125  m_ipv4_dns = request.getParameter("ipv4_dns");
126 
127  QFile host(CONFIG_HOSTNAME);
128  if (!host.open(QIODevice::WriteOnly | QIODevice::Text)) {
129  qDebug() << "Could not open /etc/conf.d/hostname for writing";
130  write( tr("Sorry, it is not possible to write to /etc/conf.d/hostname").toUtf8() );
131  return;
132  }
133  host.write("# This file is generated by fotobot application\n");
134  host.write("# Your changes will be overwritten\n\n");
135  host.write( QString("hostname=\"%1\"\n").arg(m_hostname).toUtf8() );
136  host.close();
137 
138  QFile net(CONFIG_NET);
139  if (!net.open(QIODevice::WriteOnly | QIODevice::Text)) {
140  qDebug() << "Could not open /etc/conf.d/hostname for writing";
141  write( tr("Sorry, it is not possible to write to /etc/conf.d/net").toUtf8() );
142  return;
143  }
144  net.write("# This file is generated by fotobot application\n");
145  net.write("# Your changes will be overwritten\n\n");
146  if (m_ipv4_dhcp) {
147  net.write( "dns_servers_eth0=\"8.8.8.8\"\n" );
148  net.write( "config_eth0=\"dhcp\"\n" );
149  net.write( "fallback_eth0=\"192.168.1.111 netmask 255.255.255.0\"\n" );
150  } else {
151  net.write( QString("config_eth0=\"%1 netmask %2\"\n").arg(m_ipv4_addr).arg(m_ipv4_mask).toUtf8() );
152  net.write( QString("routes_eth0=\"%1\"\n").arg(m_ipv4_router).toUtf8() );
153  net.write( QString("dns_servers_eth0=\"%1\"\n").arg(m_ipv4_dns).toUtf8() );
154  }
155  net.close();
156 
157  write( tr("<h2>Restarting....</h2>\n<p>Device is restarting now. Please wait few minutes and then refresh this page.</p>").toUtf8() );
158 
159  QProcess *restart = new QProcess();
160  restart->start("/usr/bin/fotobot-reboot");
161 
162 }
void NetworkController::servicePrivate ( HttpRequest &  request)
virtual

Generates the response

Implements WebPage.

Definition at line 22 of file networkcontroller.cpp.

22  {
23  QByteArray action = request.getParameter("action");
24  if (action.startsWith("apply")) {
25  actionApply(request);
26  return;
27  }
28 
29  getConfigValues();
30 
31  write(QString(
32  "<h2>%1</h2>\n"
33  "<table class=\"formTable\">\n"
34  "<form>\n"
35  "<input type=\"hidden\" name=\"action\" value=\"apply\"/>\n"
36  "<tr><td>%2</td><td><input type=\"text\" name=\"hostname\" value=\"%3\"></td></tr>\n"
37  "<tr><td>%4</td><td><input type=\"checkbox\" name=\"ipv4_dhcp\" value=\"Y\" %5></td></tr>\n"
38  "<tr><td>%6</td><td><input type=\"text\" name=\"ipv4_addr\" value=\"%7\"></td></tr>\n"
39  "<tr><td>%8</td><td><input type=\"text\" name=\"ipv4_mask\" value=\"%9\"></td></tr>\n"
40  "<tr><td>%10</td><td><input type=\"text\" name=\"ipv4_router\" value=\"%11\"></td></tr>\n"
41  "<tr><td>%12</td><td><input type=\"text\" name=\"ipv4_dns\" value=\"%13\"></td></tr>\n"
42  "<tr><td></td><td><input type=\"submit\" value=\"OK\"></td></tr>\n"
43  "</form></table>\n" )
44  .arg(tr("Network settings"))
45  .arg(tr("Hostname:")) .arg( m_hostname )
46  .arg(tr("Use DHCP:")) .arg( (m_ipv4_dhcp) ? "checked" : "" )
47  .arg(tr("IPv4 address:")) .arg( m_ipv4_addr )
48  .arg(tr("IPv4 mask:")) .arg( m_ipv4_mask )
49  .arg(tr("IPv4 router:")) .arg( m_ipv4_router )
50  .arg(tr("IPv4 dns server:")) .arg( m_ipv4_dns )
51  .toUtf8()
52  );
53 
54 }
void actionApply(HttpRequest &request)

The documentation for this class was generated from the following files: