3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.web;
21 import java.io.IOException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import org.sonews.daemon.Main;
25 import org.sonews.util.StringTemplate;
28 * Main sonews webpage servlet.
29 * @author Christian Lins
32 public class SonewsServlet extends AbstractSonewsServlet
35 private static final long serialVersionUID = 2392837459834L;
38 public void doGet(HttpServletRequest res, HttpServletResponse resp)
43 connectToNewsserver();
46 int connectedClients = 0;
50 printlnToNewsserver("XDAEMON LOG CONNECTED_CLIENTS");
52 line = readlnFromNewsserver();
53 if(!line.startsWith("200 "))
55 throw new IOException("XDAEMON command not allowed by server");
57 line = readlnFromNewsserver();
58 connectedClients = Integer.parseInt(line);
59 line = readlnFromNewsserver(); // Read the "."
61 printlnToNewsserver("XDAEMON LOG HOSTED_NEWS");
62 line = readlnFromNewsserver();
63 if(!line.startsWith("200 "))
65 throw new IOException("XDAEMON command not allowed by server");
67 line = readlnFromNewsserver();
68 hostedNews = Integer.parseInt(line);
69 line = readlnFromNewsserver(); // read the "."
71 printlnToNewsserver("XDAEMON LOG HOSTED_GROUPS");
72 line = readlnFromNewsserver();
73 if(!line.startsWith("200 "))
75 throw new IOException("XDAEMON command not allowed by server");
77 line = readlnFromNewsserver();
78 hostedGroups = Integer.parseInt(line);
79 line = readlnFromNewsserver(); // read the "."
81 printlnToNewsserver("XDAEMON LOG POSTED_NEWS_PER_HOUR");
82 line = readlnFromNewsserver();
83 if(!line.startsWith("200 "))
85 throw new IOException("XDAEMON command not allowed by server");
87 String postedNewsPerHour = readlnFromNewsserver();
88 readlnFromNewsserver();
90 printlnToNewsserver("XDAEMON LOG GATEWAYED_NEWS_PER_HOUR");
91 line = readlnFromNewsserver();
92 if(!line.startsWith("200 "))
94 throw new IOException("XDAEMON command not allowed by server");
96 String gatewayedNewsPerHour = readlnFromNewsserver();
97 line = readlnFromNewsserver();
99 printlnToNewsserver("XDAEMON LOG FEEDED_NEWS_PER_HOUR");
100 line = readlnFromNewsserver();
101 if(!line.startsWith("200 "))
103 throw new IOException("XDAEMON command not allowed by server");
105 String feededNewsPerHour = readlnFromNewsserver();
106 line = readlnFromNewsserver();
108 StringTemplate tmpl = getTemplate("SonewsServlet.tmpl");
109 tmpl.set("SERVERNAME", hello.split(" ")[2]);
110 tmpl.set("STARTDATE", Main.STARTDATE);
111 tmpl.set("ACTIVE_CONNECTIONS", connectedClients);
112 tmpl.set("STORED_NEWS", hostedNews);
113 tmpl.set("SERVED_NEWSGROUPS", hostedGroups);
114 tmpl.set("POSTED_NEWS", postedNewsPerHour);
115 tmpl.set("GATEWAYED_NEWS", gatewayedNewsPerHour);
116 tmpl.set("FEEDED_NEWS", feededNewsPerHour);
117 tmpl.set("TITLE", "Overview");
119 resp.getWriter().println(tmpl.toString());
120 resp.getWriter().flush();
121 resp.setStatus(HttpServletResponse.SC_OK);
123 disconnectFromNewsserver();