return SimpleFormatter.format(date);
}
public static serverObjects respond(final RequestHeader header, serverObjects post, final serverSwitch env) throws IOException {
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();
if (post == null) {
post = new serverObjects();
post.put("page", "start");
}
prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
String access = sb.getConfig("WikiAccess", "admin");
final String pagename = get(post, "page", "start");
final String ip = get(post, HeaderFramework.CONNECTION_PROP_CLIENTIP, "127.0.0.1");
String author = get(post, "author", ANONYMOUS);
if (author.equals(ANONYMOUS)) {
author = WikiBoard.guessAuthor(ip);
if (author == null) {
author = (sb.peers.mySeed() == null) ? ANONYMOUS : sb.peers.mySeed().get("Name", ANONYMOUS);
}
}
if (post != null && post.containsKey("access")) {
// only the administrator may change the access right
if (!sb.verifyAuthentication(header)) {
// check access right for admin
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
access = post.get("access", "admin");
sb.setConfig("WikiAccess", access);
}
if (access.equals("admin")) {
prop.put("mode_access", "0");
} else if (access.equals("all")) {
prop.put("mode_access", "1");
}
WikiBoard.Entry page = sb.wikiDB.read(pagename);
if (post != null && post.containsKey("submit")) {
if ((access.equals("admin") && (!sb.verifyAuthentication(header)))) {
// check access right for admin
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}
// store a new page
byte[] content;
content = UTF8.getBytes(post.get("content", ""));
final WikiBoard.Entry newEntry = sb.wikiDB.newEntry(pagename, author, ip, post.get("reason", "edit"), content);
sb.wikiDB.write(newEntry);
// create a news message
final Map<String, String> map = new HashMap<String, String>();
map.put("page", pagename);
map.put("author", author.replace(',', ' '));
if (!sb.isRobinsonMode() && post.get("content", "").trim().length() > 0 && !ByteBuffer.equals(page.page(), content)) {
sb.peers.newsPool.publishMyNews(sb.peers.mySeed(), NewsPool.CATEGORY_WIKI_UPDATE, map);
}
page = newEntry;
prop.putHTML("LOCATION", "/Wiki.html?page=" + pagename);
prop.put("LOCATION", prop.get("LOCATION"));
}
if (post != null && post.containsKey("edit")) {
if ((access.equals("admin") && (!sb.verifyAuthentication(header)))) {
// check access right for admin
prop.put("AUTHENTICATE", "admin log-in"); // force log-in
return prop;
}