Article(javax.mail.Message) now has a safe method to read the byte body from the given message object (fixes #16).
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.daemon.command;
21 import java.io.IOException;
22 import java.net.InetSocketAddress;
23 import java.util.List;
24 import org.sonews.config.Config;
25 import org.sonews.daemon.NNTPConnection;
26 import org.sonews.storage.StorageBackendException;
27 import org.sonews.storage.StorageManager;
28 import org.sonews.feed.FeedManager;
29 import org.sonews.feed.Subscription;
30 import org.sonews.storage.Channel;
31 import org.sonews.storage.Group;
32 import org.sonews.util.Stats;
35 * The XDAEMON command allows a client to get/set properties of the
36 * running server daemon. Only locally connected clients are allowed to
38 * The restriction to localhost connection can be suppressed by overriding
39 * the sonews.xdaemon.host bootstrap config property.
40 * @author Christian Lins
43 public class XDaemonCommand implements Command
47 public String[] getSupportedCommandStrings()
49 return new String[]{"XDAEMON"};
53 public boolean hasFinished()
59 public String impliedCapability()
65 public boolean isStateful()
70 private void channelAdd(String[] commands, NNTPConnection conn)
71 throws IOException, StorageBackendException
73 String groupName = commands[2];
74 if(StorageManager.current().isGroupExisting(groupName))
76 conn.println("400 group " + groupName + " already existing!");
80 StorageManager.current().addGroup(groupName, Integer.parseInt(commands[3]));
81 conn.println("200 group " + groupName + " created");
85 // TODO: Refactor this method to reduce complexity!
87 public void processLine(NNTPConnection conn, String line, byte[] raw)
88 throws IOException, StorageBackendException
90 InetSocketAddress addr = (InetSocketAddress)conn.getSocketChannel().socket()
91 .getRemoteSocketAddress();
92 if(addr.getHostName().equals(
93 Config.inst().get(Config.XDAEMON_HOST, "localhost")))
95 String[] commands = line.split(" ", 4);
96 if(commands.length == 3 && commands[1].equalsIgnoreCase("LIST"))
98 if(commands[2].equalsIgnoreCase("CONFIGKEYS"))
100 conn.println("100 list of available config keys follows");
101 for(String key : Config.AVAILABLE_KEYS)
107 else if(commands[2].equalsIgnoreCase("PEERINGRULES"))
109 List<Subscription> pull =
110 StorageManager.current().getSubscriptions(FeedManager.TYPE_PULL);
111 List<Subscription> push =
112 StorageManager.current().getSubscriptions(FeedManager.TYPE_PUSH);
113 conn.println("100 list of peering rules follows");
114 for(Subscription sub : pull)
116 conn.println("PULL " + sub.getHost() + ":" + sub.getPort()
117 + " " + sub.getGroup());
119 for(Subscription sub : push)
121 conn.println("PUSH " + sub.getHost() + ":" + sub.getPort()
122 + " " + sub.getGroup());
128 conn.println("401 unknown sub command");
131 else if(commands.length == 3 && commands[1].equalsIgnoreCase("DELETE"))
133 StorageManager.current().delete(commands[2]);
134 conn.println("200 article " + commands[2] + " deleted");
136 else if(commands.length == 4 && commands[1].equalsIgnoreCase("GROUPADD"))
138 channelAdd(commands, conn);
140 else if(commands.length == 3 && commands[1].equalsIgnoreCase("GROUPDEL"))
142 Group group = StorageManager.current().getGroup(commands[2]);
145 conn.println("400 group not found");
149 group.setFlag(Group.DELETED);
151 conn.println("200 group " + commands[2] + " marked as deleted");
154 else if(commands.length == 4 && commands[1].equalsIgnoreCase("SET"))
156 String key = commands[2];
157 String val = commands[3];
158 Config.inst().set(key, val);
159 conn.println("200 new config value set");
161 else if(commands.length == 3 && commands[1].equalsIgnoreCase("GET"))
163 String key = commands[2];
164 String val = Config.inst().get(key, null);
167 conn.println("100 config value for " + key + " follows");
173 conn.println("400 config value not set");
176 else if(commands.length >= 3 && commands[1].equalsIgnoreCase("LOG"))
179 if(commands.length > 3)
181 group = (Group)Channel.getByName(commands[3]);
184 if(commands[2].equalsIgnoreCase("CONNECTED_CLIENTS"))
186 conn.println("100 number of connections follow");
187 conn.println(Integer.toString(Stats.getInstance().connectedClients()));
190 else if(commands[2].equalsIgnoreCase("POSTED_NEWS"))
192 conn.println("100 hourly numbers of posted news yesterday");
193 for(int n = 0; n < 24; n++)
195 conn.println(n + " " + Stats.getInstance()
196 .getYesterdaysEvents(Stats.POSTED_NEWS, n, group));
200 else if(commands[2].equalsIgnoreCase("GATEWAYED_NEWS"))
202 conn.println("100 hourly numbers of gatewayed news yesterday");
203 for(int n = 0; n < 24; n++)
205 conn.println(n + " " + Stats.getInstance()
206 .getYesterdaysEvents(Stats.GATEWAYED_NEWS, n, group));
210 else if(commands[2].equalsIgnoreCase("TRANSMITTED_NEWS"))
212 conn.println("100 hourly numbers of news transmitted to peers yesterday");
213 for(int n = 0; n < 24; n++)
215 conn.println(n + " " + Stats.getInstance()
216 .getYesterdaysEvents(Stats.FEEDED_NEWS, n, group));
220 else if(commands[2].equalsIgnoreCase("HOSTED_NEWS"))
222 conn.println("100 number of overall hosted news");
223 conn.println(Integer.toString(Stats.getInstance().getNumberOfNews()));
226 else if(commands[2].equalsIgnoreCase("HOSTED_GROUPS"))
228 conn.println("100 number of hosted groups");
229 conn.println(Integer.toString(Stats.getInstance().getNumberOfGroups()));
232 else if(commands[2].equalsIgnoreCase("POSTED_NEWS_PER_HOUR"))
234 conn.println("100 posted news per hour");
235 conn.println(Double.toString(Stats.getInstance().postedPerHour(-1)));
238 else if(commands[2].equalsIgnoreCase("FEEDED_NEWS_PER_HOUR"))
240 conn.println("100 feeded news per hour");
241 conn.println(Double.toString(Stats.getInstance().feededPerHour(-1)));
244 else if(commands[2].equalsIgnoreCase("GATEWAYED_NEWS_PER_HOUR"))
246 conn.println("100 gatewayed news per hour");
247 conn.println(Double.toString(Stats.getInstance().gatewayedPerHour(-1)));
252 conn.println("401 unknown sub command");
255 else if(commands.length >= 3 && commands[1].equalsIgnoreCase("PLUGIN"))
261 conn.println("400 invalid command usage");
266 conn.println("501 not allowed");