diff --git a/htroot/Blacklist_p.java b/htroot/Blacklist_p.java index 86492be38..1b39f5da5 100644 --- a/htroot/Blacklist_p.java +++ b/htroot/Blacklist_p.java @@ -34,7 +34,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.net.MalformedURLException; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -85,35 +84,48 @@ public class Blacklist_p { if(post.containsKey("testList")) { prop.put("testlist", "1"); String urlstring = post.get("testurl", ""); - if(!urlstring.startsWith("http://") && + if (!urlstring.startsWith("http://") && !urlstring.startsWith("https://") && !urlstring.startsWith("ftp://") && !urlstring.startsWith("smb://") && - !urlstring.startsWith("file://")) urlstring = "http://"+urlstring; - DigestURI testurl = null; - try { - testurl = new DigestURI(urlstring); - } catch (final MalformedURLException e) { testurl = null; } - if(testurl != null) { - prop.putHTML("testlist_url",testurl.toString()); - if(Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_CRAWLER, testurl)) - prop.put("testlist_listedincrawler", "1"); - if(Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_DHT, testurl)) - prop.put("testlist_listedindht", "1"); - if(Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_NEWS, testurl)) - prop.put("testlist_listedinnews", "1"); - if(Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_PROXY, testurl)) - prop.put("testlist_listedinproxy", "1"); - if(Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_SEARCH, testurl)) - prop.put("testlist_listedinsearch", "1"); - if(Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_SURFTIPS, testurl)) - prop.put("testlist_listedinsurftips", "1"); - } - else prop.put("testlist_url","not valid"); + !urlstring.startsWith("file://")) { + urlstring = "http://"+urlstring; + } + DigestURI testurl; + try { + testurl = new DigestURI(urlstring); + } catch (final MalformedURLException e) { + testurl = null; + } + if(testurl != null) { + prop.putHTML("testlist_url",testurl.toString()); + if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_CRAWLER, testurl)) { + prop.put("testlist_listedincrawler", "1"); + } + if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_DHT, testurl)) { + prop.put("testlist_listedindht", "1"); + } + if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_NEWS, testurl)) { + prop.put("testlist_listedinnews", "1"); + } + if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_PROXY, testurl)) { + prop.put("testlist_listedinproxy", "1"); + } + if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_SEARCH, testurl)) { + prop.put("testlist_listedinsearch", "1"); + } + if (Switchboard.urlBlacklist.isListed(Blacklist.BLACKLIST_SURFTIPS, testurl)) { + prop.put("testlist_listedinsurftips", "1"); + } + } else { + prop.put("testlist_url","not valid"); + } } - if (post.containsKey("selectList")) { - blacklistToUse = post.get("selectedListName"); - if (blacklistToUse != null && blacklistToUse.length() == 0) blacklistToUse = null; + if (post.containsKey("selectList")) { + blacklistToUse = post.get("selectedListName"); + if (blacklistToUse != null && blacklistToUse.length() == 0) { + blacklistToUse = null; + } } if (post.containsKey("createNewList")) { /* =========================================================== @@ -135,7 +147,9 @@ public class Blacklist_p { blacklistToUse = null; } else { - if (!blacklistToUse.endsWith(".black")) blacklistToUse += ".black"; + if (!blacklistToUse.endsWith(".black")) { + blacklistToUse += ".black"; + } if (!dirlist.contains(blacklistToUse)) { try { @@ -146,8 +160,8 @@ public class Blacklist_p { ListManager.updateListSet(BLACKLIST_SHARED, blacklistToUse); // activate it for all known blacklist types - for (int blTypes = 0; blTypes < supportedBlacklistTypes.length; blTypes++) { - ListManager.updateListSet(supportedBlacklistTypes[blTypes] + ".BlackLists", blacklistToUse); + for (final String supportedBlacklistType : supportedBlacklistTypes) { + ListManager.updateListSet(supportedBlacklistType + ".BlackLists", blacklistToUse); } } catch (final IOException e) {/* */} } else { @@ -176,8 +190,8 @@ public class Blacklist_p { Log.logWarning("Blacklist", "file "+ blackListFile +" could not be deleted!"); } - for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) { - ListManager.removeFromListSet(supportedBlacklistTypes[blTypes] + ".BlackLists",blacklistToUse); + for (final String supportedBlacklistType : supportedBlacklistTypes) { + ListManager.removeFromListSet(supportedBlacklistType + ".BlackLists",blacklistToUse); } // remove it from the shared list @@ -199,11 +213,11 @@ public class Blacklist_p { return prop; } - for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) { - if (post.containsKey("activateList4" + supportedBlacklistTypes[blTypes])) { - ListManager.updateListSet(supportedBlacklistTypes[blTypes] + ".BlackLists",blacklistToUse); + for (final String supportedBlacklistType : supportedBlacklistTypes) { + if (post.containsKey("activateList4" + supportedBlacklistType)) { + ListManager.updateListSet(supportedBlacklistType + ".BlackLists",blacklistToUse); } else { - ListManager.removeFromListSet(supportedBlacklistTypes[blTypes] + ".BlackLists",blacklistToUse); + ListManager.removeFromListSet(supportedBlacklistType + ".BlackLists",blacklistToUse); } } @@ -234,14 +248,13 @@ public class Blacklist_p { * =========================================================== */ blacklistToUse = post.get("currentBlacklist", "").trim(); - String temp = null; final String[] selectedBlacklistEntries = post.getAll("selectedEntry.*"); if (selectedBlacklistEntries.length > 0) { - for (int i = 0; i < selectedBlacklistEntries.length; i++) { - temp = deleteBlacklistEntry(blacklistToUse, selectedBlacklistEntries[i], header, supportedBlacklistTypes); - if (temp != null) { + String temp = null; + for (final String selectedBlacklistEntry : selectedBlacklistEntries) { + if ((temp = deleteBlacklistEntry(blacklistToUse, selectedBlacklistEntry, header, supportedBlacklistTypes)) != null) { prop.put("LOCATION", temp); return prop; } @@ -256,7 +269,7 @@ public class Blacklist_p { * =========================================================== */ blacklistToUse = post.get("currentBlacklist", "").trim(); - String blentry = post.get("newEntry", "").trim(); + final String blentry = post.get("newEntry", "").trim(); // store this call as api call ListManager.switchboard.tables.recordAPICall(post, "Blacklist_p.html", WorkTables.TABLE_API_TYPE_CONFIGURATION, "add to blacklist: " + blentry); @@ -268,15 +281,14 @@ public class Blacklist_p { } ListManager.reloadBlacklists(); - } else if (action.equals("moveBlacklistEntry")) { + } else if ("moveBlacklistEntry".equals(action)) { /* =========================================================== * Move an entry from one blacklist to another * =========================================================== */ blacklistToUse = post.get("currentBlacklist", "").trim(); - String targetBlacklist = post.get("targetBlacklist"); - String temp = null; + final String targetBlacklist = post.get("targetBlacklist"); final String[] selectedBlacklistEntries = post.getAll("selectedEntry.*"); @@ -285,16 +297,14 @@ public class Blacklist_p { targetBlacklist != null && blacklistToUse != null && !targetBlacklist.equals(blacklistToUse)) { - for (int i = 0; i < selectedBlacklistEntries.length; i++) { - - temp = addBlacklistEntry(targetBlacklist, selectedBlacklistEntries[i], header, supportedBlacklistTypes); - if (temp != null) { + String temp; + for (final String selectedBlacklistEntry : selectedBlacklistEntries) { + if ((temp = addBlacklistEntry(targetBlacklist, selectedBlacklistEntry, header, supportedBlacklistTypes)) != null) { prop.put("LOCATION", temp); return prop; } - temp = deleteBlacklistEntry(blacklistToUse, selectedBlacklistEntries[i], header, supportedBlacklistTypes); - if (temp != null) { + if ((temp = deleteBlacklistEntry(blacklistToUse, selectedBlacklistEntry, header, supportedBlacklistTypes)) != null) { prop.put("LOCATION", temp); return prop; @@ -303,7 +313,7 @@ public class Blacklist_p { } ListManager.reloadBlacklists(); - } else if (action.equals("editBlacklistEntry")) { + } else if ("editBlacklistEntry".equals(action)) { /* =========================================================== * Edit entry of a blacklist @@ -328,14 +338,13 @@ public class Blacklist_p { for (int i = 0; i < selectedBlacklistEntries.length; i++) { if (!selectedBlacklistEntries[i].equals(editedBlacklistEntries[i])) { - temp = deleteBlacklistEntry(blacklistToUse, selectedBlacklistEntries[i], header, supportedBlacklistTypes); - if (temp != null) { + + if ((temp = deleteBlacklistEntry(blacklistToUse, selectedBlacklistEntries[i], header, supportedBlacklistTypes)) != null) { prop.put("LOCATION", temp); return prop; } - temp = addBlacklistEntry(blacklistToUse, editedBlacklistEntries[i], header, supportedBlacklistTypes); - if (temp != null) { + if ((temp = addBlacklistEntry(blacklistToUse, editedBlacklistEntries[i], header, supportedBlacklistTypes)) != null) { prop.put("LOCATION", temp); return prop; } @@ -357,7 +366,7 @@ public class Blacklist_p { prop.put(DISABLED + EDIT + "editList", selectedEntries.length); } } - } else if (action.equals("selectRange")) { + } else if ("selectRange".equals(action)) { blacklistToUse = post.get("currentBlacklist"); } @@ -561,8 +570,6 @@ public class Blacklist_p { SearchEventCache.cleanupEvents(true); return null; } - - /** * This method deletes a blacklist entry. @@ -570,20 +577,20 @@ public class Blacklist_p { * @param oldEntry the entry that is to be deleted * @param supportedBlacklistTypes */ - public static void deleteBlacklistEntry( + private static void deleteBlacklistEntry( final File listsPath, final String blacklistToUse, String oldEntry, final String[] supportedBlacklistTypes) { // load blacklist data from file - final ArrayList list = FileUtils.getListArray(new File(listsPath, blacklistToUse)); + final List list = FileUtils.getListArray(new File(listsPath, blacklistToUse)); // delete the old entry from file if (list != null) { - for (int i=0; i < list.size(); i++) { - if ((list.get(i)).equals(oldEntry)) { - list.remove(i); + for (final String entry : list) { + if (entry.equals(oldEntry)) { + list.remove(entry); break; } } @@ -597,9 +604,9 @@ public class Blacklist_p { pos = oldEntry.length(); oldEntry = oldEntry + "/.*"; } - for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) { - if (ListManager.listSetContains(supportedBlacklistTypes[blTypes] + ".BlackLists",blacklistToUse)) { - Switchboard.urlBlacklist.remove(supportedBlacklistTypes[blTypes],oldEntry.substring(0, pos), oldEntry.substring(pos + 1)); + for (final String supportedBlacklistType : supportedBlacklistTypes) { + if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists",blacklistToUse)) { + Switchboard.urlBlacklist.remove(supportedBlacklistType,oldEntry.substring(0, pos), oldEntry.substring(pos + 1)); } } } @@ -612,7 +619,7 @@ public class Blacklist_p { * @param newEntry the entry that is to be added * @param supportedBlacklistTypes */ - public static void addBlacklistEntry( + private static void addBlacklistEntry( final File listsPath, final String blacklistToUse, String newEntry, @@ -654,9 +661,9 @@ public class Blacklist_p { } // add to blacklist - for (int blTypes = 0; blTypes < supportedBlacklistTypes.length; blTypes++) { - if (ListManager.listSetContains(supportedBlacklistTypes[blTypes] + ".BlackLists", blacklistToUse)) { - Switchboard.urlBlacklist.add(supportedBlacklistTypes[blTypes], newEntry.substring(0, pos), newEntry.substring(pos + 1)); + for (final String supportedBlacklistType : supportedBlacklistTypes) { + if (ListManager.listSetContains(supportedBlacklistType + ".BlackLists", blacklistToUse)) { + Switchboard.urlBlacklist.add(supportedBlacklistType, newEntry.substring(0, pos), newEntry.substring(pos + 1)); } } } diff --git a/htroot/Blog.java b/htroot/Blog.java index 874928060..9fa8c0391 100644 --- a/htroot/Blog.java +++ b/htroot/Blog.java @@ -90,12 +90,12 @@ public class Blog { final int start = post.getInt("start",0); //indicates from where entries should be shown final int num = post.getInt("num",10); //indicates how many entries should be shown - if(!hasRights){ + if (!hasRights) { final UserDB.Entry userentry = sb.userDB.proxyAuth(header.get(RequestHeader.AUTHORIZATION, "xxxxxx")); - if(userentry != null && userentry.hasRight(UserDB.Entry.BLOG_RIGHT)){ + if (userentry != null && userentry.hasRight(UserDB.Entry.BLOG_RIGHT)) { hasRights=true; - } else if(post.containsKey("login")) { - //opens login window if login link is clicked - contrib [MN] + } else if (post.containsKey("login")) { + //opens login window if login link is clicked prop.put("AUTHENTICATE","admin log-in"); } } @@ -105,7 +105,7 @@ public class Blog { String StrAuthor = post.get("author", ""); - if (StrAuthor.equals("anonymous")) { + if ("anonymous".equals(StrAuthor)) { StrAuthor = sb.blogDB.guessAuthor(ip); if (StrAuthor == null || StrAuthor.length() == 0) { @@ -124,7 +124,7 @@ public class Blog { author = StrAuthor.getBytes(); } - if(hasRights && post.containsKey("delete") && post.get("delete").equals("sure")) { + if (hasRights && post.containsKey("delete") && "sure".equals(post.get("delete"))) { page = sb.blogDB.readBlogEntry(pagename); for (final String comment : page.getComments()) { sb.blogCommentDB.delete(comment); @@ -137,7 +137,7 @@ public class Blog { pagename = DEFAULT_PAGE; } - if (post.containsKey("submit") && (hasRights)) { + if (post.containsKey("submit") && hasRights) { // store a new/edited blog-entry byte[] content; try { @@ -146,12 +146,13 @@ public class Blog { content = post.get("content", "").getBytes(); } - Date date = null; + final Date date; List comments = null; //set name for new entry or date for old entry - if(pagename.equals(DEFAULT_PAGE)) { + if (DEFAULT_PAGE.equals(pagename)) { pagename = String.valueOf(System.currentTimeMillis()); + date = null; } else { page = sb.blogDB.readBlogEntry(pagename); comments = page.getComments(); @@ -213,7 +214,7 @@ public class Blog { prop.put("mode", "3"); //access denied (no rights) } } - else if(post.get("delete", "").equals("try")) { + else if("try".equals(post.get("delete", ""))) { if(hasRights) { prop.put("mode", "4"); prop.putHTML("mode_pageid", pagename); @@ -246,7 +247,7 @@ public class Blog { else { // show blog-entry/entries prop.put("mode", "0"); //viewing - if(pagename.equals(DEFAULT_PAGE)) { + if(DEFAULT_PAGE.equals(pagename)) { // XXX: where are "peername" and "address" used in the template? // XXX: "clientname" is already set to the peername, no need for a new setting prop.putHTML("peername", sb.peers.mySeed().getName()); @@ -274,43 +275,44 @@ public class Blog { final boolean hasRights, final boolean xml) { - final Iterator i = switchboard.blogDB.getBlogIterator(false); - String pageid; - int count = 0; //counts how many entries are shown to the user - if(xml) num = 0; - final int nextstart = start+num; //indicates the starting offset for next results - int prevstart = start-num; //indicates the starting offset for previous results - boolean prev = false; //indicates if there were previous comments to the ones that are dispalyed - if (start > 0) prev = true; - while(i.hasNext() && (num == 0 || num > count)) { - pageid = i.next(); - if(0 < start--) continue; - putBlogEntry( - prop, - switchboard.blogDB.readBlogEntry(pageid), - address, - count++, - hasRights, - xml); - } - prop.put("mode_entries", count); + final Iterator i = switchboard.blogDB.getBlogIterator(false); - if(i.hasNext()) { - prop.put("mode_moreentries", "1"); //more entries are availible - prop.put("mode_moreentries_start", nextstart); - prop.put("mode_moreentries_num", num); - } else { - prop.put("moreentries", "0"); + int count = 0; //counts how many entries are shown to the user + if (xml) { + num = 0; + } + final int nextstart = start+num; //indicates the starting offset for next results + int prevstart = start-num; //indicates the starting offset for previous results + + while (i.hasNext() && (num == 0 || num > count)) { + if(0 < start--) continue; + putBlogEntry( + prop, + switchboard.blogDB.readBlogEntry(i.next()), + address, + count++, + hasRights, + xml); + } + prop.put("mode_entries", count); + + if (i.hasNext()) { + prop.put("mode_moreentries", "1"); //more entries are availible + prop.put("mode_moreentries_start", nextstart); + prop.put("mode_moreentries_num", num); + } else { + prop.put("moreentries", "0"); + } + + if (start > 0) { + prop.put("mode_preventries", "1"); + if (prevstart < 0) { + prevstart = 0; } - - if(prev) { - prop.put("mode_preventries", "1"); - if (prevstart < 0) prevstart = 0; - prop.put("mode_preventries_start", prevstart); - prop.put("mode_preventries_num", num); - } else prop.put("mode_preventries", "0"); - - + prop.put("mode_preventries_start", prevstart); + prop.put("mode_preventries_num", num); + } else prop.put("mode_preventries", "0"); + return prop; } @@ -337,7 +339,7 @@ public class Blog { } // comments - if(entry.getCommentMode() == 0) { + if (entry.getCommentMode() == 0) { prop.put("mode_entries_" + number + "_commentsactive", "0"); } else { prop.put("mode_entries_" + number + "_commentsactive", "1"); @@ -352,14 +354,14 @@ public class Blog { prop.put("mode_entries_" + number + "_address", address); prop.put("mode_entries_" + number + "_ip", entry.getIp()); - if(xml) { + if (xml) { prop.put("mode_entries_" + number + "_page", entry.getPage()); prop.put("mode_entries_" + number + "_timestamp", entry.getTimestamp()); } else { prop.putWiki("mode_entries_" + number + "_page", entry.getPage()); } - if(hasRights) { + if (hasRights) { prop.put("mode_entries_" + number + "_admin", "1"); prop.put("mode_entries_" + number + "_admin_pageid",entry.getKey()); } else { diff --git a/htroot/BlogComments.java b/htroot/BlogComments.java index 1ec18d567..1b6095c00 100644 --- a/htroot/BlogComments.java +++ b/htroot/BlogComments.java @@ -93,7 +93,7 @@ public class BlogComments { String StrAuthor = post.get("author", "anonymous"); - if (StrAuthor.equals("anonymous")) { + if ("anonymous".equals(StrAuthor)) { StrAuthor = sb.blogDB.guessAuthor(ip); if (StrAuthor == null || StrAuthor.length() == 0) { @@ -126,9 +126,10 @@ public class BlogComments { if (post.containsKey("submit") && page.getCommentMode() != 0 && pageExists) { // store a new/edited blog-entry byte[] content; - if(!post.get("content", "").equals("")) - { - if(post.get("subject", "").equals("")) post.putHTML("subject", "no title"); + if (!"".equals(post.get("content", ""))) { + if ("".equals(post.get("subject", ""))) { + post.putHTML("subject", "no title"); + } try { content = post.get("content", "").getBytes("UTF-8"); } catch (final UnsupportedEncodingException e) { @@ -183,19 +184,18 @@ public class BlogComments { } } - if(hasRights && post.containsKey("delete") && post.containsKey("page") && post.containsKey("comment")) { - if(page.removeComment(post.get("comment"))) { - sb.blogCommentDB.delete(post.get("comment")); - } + if (hasRights && post.containsKey("delete") && post.containsKey("page") && + post.containsKey("comment") && page.removeComment(post.get("comment"))) { + sb.blogCommentDB.delete(post.get("comment")); } - if(hasRights && post.containsKey("allow") && post.containsKey("page") && post.containsKey("comment")) { + if (hasRights && post.containsKey("allow") && post.containsKey("page") && post.containsKey("comment")) { final BlogBoardComments.CommentEntry entry = sb.blogCommentDB.read(post.get("comment")); entry.allow(); sb.blogCommentDB.write(entry); } - if(post.containsKey("preview") && page.getCommentMode() != 0) { + if (post.containsKey("preview") && page.getCommentMode() != 0) { //preview the page prop.put("mode", "1");//preview prop.putHTML("mode_pageid", pagename); @@ -214,7 +214,7 @@ public class BlogComments { } else { // show blog-entry/entries prop.put("mode", "0"); //viewing - if(pagename.equals("blog_default")) { + if("blog_default".equals(pagename)) { prop.put("LOCATION","Blog.html"); } else { //show 1 blog entry @@ -235,7 +235,7 @@ public class BlogComments { prop.put("mode_comments", page.getCommentsSize()); prop.put("mode_date", dateString(page.getDate())); prop.putWiki("mode_page", page.getPage()); - if(hasRights) { + if (hasRights) { prop.put("mode_admin", "1"); prop.put("mode_admin_pageid", page.getKey()); } @@ -246,19 +246,23 @@ public class BlogComments { String pageid; BlogBoardComments.CommentEntry entry; boolean xml = false; - if(post.containsKey("xml")) { + if (post.containsKey("xml")) { xml = true; } int count = 0; //counts how many entries are shown to the user int start = post.getInt("start",0); //indicates from where entries should be shown int num = post.getInt("num",10); //indicates how many entries should be shown - boolean prev = false; //indicates if there were previous comments to the ones that are dispalyed - if(xml) num = 0; - if (start < 0) start = 0; - if (start > 1) prev = true; - final int nextstart = start+num; //indicates the starting offset for next results - int prevstart = start-num; //indicates the starting offset for previous results - while(i.hasNext() && count < num) { + + if (xml) { + num = 0; + } + if (start < 0) { + start = 0; + } + + final int nextstart = start + num; //indicates the starting offset for next results + int prevstart = start - num; //indicates the starting offset for previous results + while (i.hasNext() && count < num) { pageid = i.next(); @@ -269,17 +273,17 @@ public class BlogComments { entry = sb.blogCommentDB.read(pageid); - if (commentMode == 2 && !hasRights && !entry.isAllowed()) + if (commentMode == 2 && !hasRights && !entry.isAllowed()) { continue; + } prop.put("mode", "0"); prop.put("mode_entries_"+count+"_pageid", entry.getKey()); - if(!xml) { + if (!xml) { prop.putHTML("mode_entries_"+count+"_subject", new String(entry.getSubject(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_author", new String(entry.getAuthor(),"UTF-8")); prop.putWiki("mode_entries_"+count+"_page", entry.getPage()); - } - else { + } else { prop.putHTML("mode_entries_"+count+"_subject", new String(entry.getSubject(),"UTF-8")); prop.putHTML("mode_entries_"+count+"_author", new String(entry.getAuthor(),"UTF-8")); prop.put("mode_entries_"+count+"_page", entry.getPage()); @@ -301,15 +305,15 @@ public class BlogComments { else prop.put("mode_entries_"+count+"_admin", 0); ++count; } - prop.put("mode_entries", count); - if(i.hasNext()) { + prop.put ("mode_entries", count); + if (i.hasNext()) { prop.put("mode_moreentries", "1"); //more entries are availible prop.put("mode_moreentries_start", nextstart); prop.put("mode_moreentries_num", num); prop.put("mode_moreentries_pageid", page.getKey()); } else prop.put("mode_moreentries", "0"); - if(prev) { + if (start > 1) { prop.put("mode_preventries", "1"); if (prevstart < 0) prevstart = 0; prop.put("mode_preventries_start", prevstart); @@ -328,7 +332,9 @@ public class BlogComments { private static void messageForwardingViaEmail(final Switchboard sb, final MessageBoard.entry msgEntry) { try { - if (!Boolean.parseBoolean(sb.getConfig("msgForwardingEnabled","false"))) return; + if (!Boolean.parseBoolean(sb.getConfig("msgForwardingEnabled","false"))) { + return; + } // get the recipient address final String sendMailTo = sb.getConfig("msgForwardingTo","root@localhost").trim(); diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.java index 6fe153b57..d09ed0757 100644 --- a/htroot/Bookmarks.java +++ b/htroot/Bookmarks.java @@ -49,6 +49,8 @@ import net.yacy.kelondro.util.DateFormatter; import de.anomic.crawler.CrawlProfile; import de.anomic.data.BookmarkHelper; import de.anomic.data.BookmarksDB; +import de.anomic.data.BookmarksDB.Bookmark; +import de.anomic.data.BookmarksDB.Tag; import de.anomic.data.ListManager; import de.anomic.data.UserDB; import de.anomic.search.Segments; @@ -56,6 +58,7 @@ import de.anomic.search.Switchboard; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; import de.anomic.yacy.yacyNewsPool; +import java.util.Map; public class Bookmarks { @@ -82,11 +85,14 @@ public class Bookmarks { prop.clear(); sb = (Switchboard) env; user = sb.userDB.getUser(header); - isAdmin=(sb.verifyAuthentication(header, true) || user!= null && user.hasRight(UserDB.Entry.BOOKMARK_RIGHT)); + isAdmin = (sb.verifyAuthentication(header, true) || user!= null && user.hasRight(UserDB.Entry.BOOKMARK_RIGHT)); // set user name - if(user != null) username=user.getUserName(); - else if(isAdmin) username="admin"; + if (user != null) { + username=user.getUserName(); + } else if(isAdmin) { + username="admin"; + } prop.putHTML("user", username); //redirect to userpage @@ -96,17 +102,15 @@ public class Bookmarks { */ // set peer address - final String address = sb.peers.mySeed().getPublicAddress(); - prop.put("address", address); + prop.put("address", sb.peers.mySeed().getPublicAddress()); //defaultvalues if(isAdmin) { - prop.put("mode", "1"); + prop.put("mode", "1"); prop.put("admin", "1"); prop.put("display", "0"); - } else { - prop.put("mode", "0"); + prop.put("mode", "0"); prop.put("admin", "0"); prop.put("display", "0"); } @@ -119,80 +123,82 @@ public class Bookmarks { prop.put("mode_public", "1"); //1=is public prop.put("mode_feed", "0"); //no newsfeed - if(post != null){ - if(!isAdmin){ - if(post.containsKey("login")){ - prop.put("AUTHENTICATE","admin log-in"); - } - }else if(post.containsKey("mode")){ - final String mode=post.get("mode"); - if(mode.equals("add")){ - prop.put("mode", "2"); - prop.put("display", "1"); - display = 1; - }else if(mode.equals("importxml")){ - prop.put("mode", "3"); - prop.put("display", "1"); - display = 1; - } - }else if(post.containsKey("add")){ //add an Entry - final String url=post.get("url"); - final String title=post.get("title"); - final String description=post.get("description"); - String tagsString = post.get("tags"); - String pathString = post.get("path"); - if(pathString.equals("")){ - pathString="/unsorted"; //default folder - } - tagsString=tagsString+","+pathString; - final Set tags=ListManager.string2set(BookmarkHelper.cleanTagsString(tagsString)); - final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username); - if(bookmark != null){ - bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title); - bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description); - if(user!=null){ - bookmark.setOwner(user.getUserName()); - } - if((post.get("public")).equals("public")){ - bookmark.setPublic(true); - publishNews(url, title, description, tagsString); - }else{ - bookmark.setPublic(false); - } - if(post.containsKey("feed") && (post.get("feed")).equals("feed")){ - bookmark.setFeed(true); - }else{ - bookmark.setFeed(false); - } - bookmark.setTags(tags, true); - sb.bookmarksDB.saveBookmark(bookmark); - //}else{ - //ERROR - } - }else if(post.containsKey("edit")){ - final String urlHash=post.get("edit"); - prop.put("mode", "2"); - prop.put("display", "1"); - display = 1; - if (urlHash.length() == 0) { - prop.put("mode_edit", "0"); // create mode - prop.putHTML("mode_title", post.get("title")); - prop.putHTML("mode_description", post.get("description")); - prop.putHTML("mode_url", post.get("url")); - prop.putHTML("mode_tags", post.get("tags")); - prop.putHTML("mode_path", post.get("path")); - prop.put("mode_public", "0"); - prop.put("mode_feed", "0"); - } else { + if (post != null) { + if (!isAdmin) { + if(post.containsKey("login")){ + prop.put("AUTHENTICATE","admin log-in"); + } + } else if (post.containsKey("mode")) { + final String mode=post.get("mode"); + if ("add".equals(mode)) { + prop.put("mode", "2"); + prop.put("display", "1"); + display = 1; + } else if ("importxml".equals(mode)){ + prop.put("mode", "3"); + prop.put("display", "1"); + display = 1; + } + } else if(post.containsKey("add")) { //add an Entry + final String url=post.get("url"); + final String title=post.get("title"); + final String description=post.get("description"); + String tagsString = post.get("tags"); + String pathString = post.get("path"); + if(pathString == null || "".equals(pathString)){ + pathString="/unsorted"; //default folder + } + tagsString = tagsString + "," + pathString; + final Set tags=ListManager.string2set(BookmarkHelper.cleanTagsString(tagsString)); + final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username); + + if (bookmark != null) { + bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title); + bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description); + + if (user!=null) { + bookmark.setOwner(user.getUserName()); + } + + if ((post.get("public")).equals("public")) { + bookmark.setPublic(true); + publishNews(url, title, description, tagsString); + } else { + bookmark.setPublic(false); + } + + if(post.containsKey("feed") && ("feed".equals(post.get("feed")))){ + bookmark.setFeed(true); + } else { + bookmark.setFeed(false); + } + + bookmark.setTags(tags, true); + sb.bookmarksDB.saveBookmark(bookmark); + } + + } else if (post.containsKey("edit")) { + final String urlHash = post.get("edit"); + prop.put("mode", "2"); + prop.put("display", "1"); + display = 1; + if (urlHash.length() == 0) { + prop.put("mode_edit", "0"); // create mode + prop.putHTML("mode_title", post.get("title")); + prop.putHTML("mode_description", post.get("description")); + prop.putHTML("mode_url", post.get("url")); + prop.putHTML("mode_tags", post.get("tags")); + prop.putHTML("mode_path", post.get("path")); + prop.put("mode_public", "0"); + prop.put("mode_feed", "0"); + } else { final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.getBookmark(urlHash); if (bookmark == null) { // try to get the bookmark from the LURL database final URIMetadataRow urlentry = sb.indexSegments.urlMetadata(Segments.Process.PUBLIC).load(urlHash.getBytes(), null, 0); - Document[] documents = null; if (urlentry != null) try { final URIMetadataRow.Components metadata = urlentry.metadata(); - documents = sb.loader.loadDocuments(sb.loader.request(metadata.url(), true, false), CrawlProfile.CacheStrategy.IFEXIST, 5000, Long.MAX_VALUE); - Document document = Document.mergeDocuments(metadata.url(), null, documents); + final Document document = Document.mergeDocuments(metadata.url(), null, sb.loader.loadDocuments(sb.loader.request(metadata.url(), true, false), CrawlProfile.CacheStrategy.IFEXIST, 5000, Long.MAX_VALUE)); prop.put("mode_edit", "0"); // create mode prop.put("mode_url", metadata.url().toNormalform(false, true)); prop.putHTML("mode_title", metadata.dc_title()); @@ -211,11 +217,13 @@ public class Bookmarks { prop.put("mode_url", bookmark.getUrl()); //TODO: XSS protection - how is this stored? prop.putHTML("mode_tags", bookmark.getTagsString()); prop.putHTML("mode_path",bookmark.getFoldersString()); + if (bookmark.getPublic()) { prop.put("mode_public", "1"); } else { prop.put("mode_public", "0"); } + if (bookmark.getFeed()) { prop.put("mode_feed", "1"); } else { @@ -223,40 +231,46 @@ public class Bookmarks { } } } - } else if(post.containsKey("htmlfile")){ - boolean isPublic=false; - if((post.get("public")).equals("public")){ - isPublic=true; - } - String tags=post.get("tags"); - if(tags.equals("")){ - tags="unsorted"; - } - Log.logInfo("BOOKMARKS", "I try to import bookmarks from HTML-file"); - try { - final File file=new File(post.get("htmlfile")); - BookmarkHelper.importFromBookmarks(sb.bookmarksDB, new DigestURI(file), post.get("htmlfile$file"), tags, isPublic); - } catch (final MalformedURLException e) {} - Log.logInfo("BOOKMARKS", "success!!"); - }else if(post.containsKey("xmlfile")){ - boolean isPublic=false; - if((post.get("public")).equals("public")){ - isPublic=true; - } - BookmarkHelper.importFromXML(sb.bookmarksDB, post.get("xmlfile$file"), isPublic); - }else if(post.containsKey("delete")){ - final String urlHash=post.get("delete"); - sb.bookmarksDB.removeBookmark(urlHash); - } - if(post.containsKey("tag")){ - tagName=post.get("tag"); - } - if(post.containsKey("start")){ - start=Integer.parseInt(post.get("start")); - } - if(post.containsKey("num")){ - max_count=Integer.parseInt(post.get("num")); - } + } else if(post.containsKey("htmlfile")){ + final boolean isPublic = "public".equals(post.get("public")); + + String tags = post.get("tags"); + if("".equals(tags)){ + tags="unsorted"; + } + + Log.logInfo("BOOKMARKS", "Trying to import bookmarks from HTML-file"); + + try { + final File file=new File(post.get("htmlfile")); + BookmarkHelper.importFromBookmarks(sb.bookmarksDB, new DigestURI(file), post.get("htmlfile$file"), tags, isPublic); + } catch (final MalformedURLException e) {} + + Log.logInfo("BOOKMARKS", "success!!"); + + } else if (post.containsKey("xmlfile")) { + + final boolean isPublic = "public".equals(post.get("public")); + BookmarkHelper.importFromXML(sb.bookmarksDB, post.get("xmlfile$file"), isPublic); + + } else if (post.containsKey("delete")) { + + final String urlHash=post.get("delete"); + sb.bookmarksDB.removeBookmark(urlHash); + + } + + if (post.containsKey("tag")) { + tagName = post.get("tag"); + } + + if (post.containsKey("start")) { + start = Integer.parseInt(post.get("start")); + } + + if (post.containsKey("num")) { + max_count = Integer.parseInt(post.get("num")); + } } // END if(post != null) if (display == 0) { @@ -270,78 +284,75 @@ public class Bookmarks { //----------------------- // create bookmark list //----------------------- - int count=0; + int count = 0; Iterator it = null; - BookmarksDB.Bookmark bookmark; - Set tags; - Iterator tagsIt; - int tagCount; - - prop.put("display_num-bookmarks", sb.bookmarksDB.bookmarksSize()); + + prop.put("display_num-bookmarks", sb.bookmarksDB.bookmarksSize()); - count=0; - if(!tagName.equals("")){ - prop.put("display_selected", ""); - it=sb.bookmarksDB.getBookmarksIterator(tagName, isAdmin); - }else{ - prop.put("display_selected", " selected=\"selected\""); - it=sb.bookmarksDB.getBookmarksIterator(isAdmin); + if(!"".equals(tagName)){ + prop.put("display_selected", ""); + it = sb.bookmarksDB.getBookmarksIterator(tagName, isAdmin); + } else { + prop.put("display_selected", " selected=\"selected\""); + it = sb.bookmarksDB.getBookmarksIterator(isAdmin); } //skip the first entries (display next page) - count=0; + count = 0; while(count < start && it.hasNext()){ - it.next(); - count++; + it.next(); + count++; } - count=0; - while(count 0 && tname.charAt(0) != '/') { - prop.putHTML("display_bookmarks_"+count+"_tags_"+tagCount+"_tag", tname); - tagCount++; - } - } - prop.put("display_bookmarks_"+count+"_tags", tagCount); - prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash()); - count++; - } + //List Tags. + final Set tags = bookmark.getTags(); + int tagCount=0; + for (final String tag : tags) { + if (tag.length() > 0 && tag.charAt(0) != '/') { + prop.putHTML("display_bookmarks_" + count + "_tags_" + tagCount + "_tag", tag); + tagCount++; + } + } + prop.put("display_bookmarks_"+count+"_tags", tagCount); + prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash()); + count++; + } } + prop.putHTML("display_tag", tagName); prop.put("display_start", start); - if(it.hasNext()){ - prop.put("display_next-page", "1"); - prop.put("display_next-page_start", start+max_count); - prop.putHTML("display_next-page_tag", tagName); - prop.put("display_next-page_num", max_count); + + if (it.hasNext()) { + prop.put("display_next-page", "1"); + prop.put("display_next-page_start", start+max_count); + prop.putHTML("display_next-page_tag", tagName); + prop.put("display_next-page_num", max_count); } - if(start >= max_count){ - start=start-max_count; - if(start <0){ - start=0; - } - prop.put("display_prev-page", "1"); - prop.put("display_prev-page_start", start); - prop.putHTML("display_prev-page_tag", tagName); - prop.put("display_prev-page_num", max_count); + if (start >= max_count) { + start = start-max_count; + if (start <0){ + start = 0; + } + prop.put("display_prev-page", "1"); + prop.put("display_prev-page_start", start); + prop.putHTML("display_prev-page_tag", tagName); + prop.put("display_prev-page_num", max_count); } prop.put("display_bookmarks", count); @@ -359,79 +370,84 @@ public class Bookmarks { private static void printTagList(final String id, final String tagName, final int comp, final int max, final boolean opt){ int count=0; - BookmarksDB.Tag tag; - Iterator it = null; + + final Iterator it; - if (tagName.equals("")) { - it = sb.bookmarksDB.getTagIterator(isAdmin, comp, max); + if ("".equals(tagName)) { + it = sb.bookmarksDB.getTagIterator(isAdmin, comp, max); } else { - it = sb.bookmarksDB.getTagIterator(tagName, isAdmin, comp, max); + it = sb.bookmarksDB.getTagIterator(tagName, isAdmin, comp, max); } + while(it.hasNext()){ - tag=it.next(); - if ((!tag.getTagName().startsWith("/")) && (!tag.getTagName().equals(""))) { - prop.putHTML("display_"+id+"_"+count+"_name", tag.getFriendlyName()); - prop.putHTML("display_"+id+"_"+count+"_tag", tag.getTagName()); - prop.put("display_"+id+"_"+count+"_num", tag.size()); - if (opt){ - if(tagName.equals(tag.getFriendlyName())){ - prop.put("display_"+id+"_"+count+"_selected", " selected=\"selected\""); - } else { - prop.put("display_"+id+"_"+count+"_selected", ""); - } - } else { - // font-size is pseudo-rounded to 2 decimals - prop.put("display_"+id+"_"+count+"_size", Math.round((1.1+Math.log(tag.size())/4)*100)/100.); - } - count++; - } + final Tag tag = it.next(); + if (!tag.getTagName().startsWith("/") && !"".equals(tag.getTagName())) { + prop.putHTML("display_"+id+"_"+count+"_name", tag.getFriendlyName()); + prop.putHTML("display_"+id+"_"+count+"_tag", tag.getTagName()); + prop.put("display_"+id+"_"+count+"_num", tag.size()); + if (opt) { + if (tag.getFriendlyName().equals(tagName)){ + prop.put("display_"+id+"_"+count+"_selected", " selected=\"selected\""); + } else { + prop.put("display_"+id+"_"+count+"_selected", ""); + } + } else { + // font-size is pseudo-rounded to 2 decimals + prop.put("display_"+id+"_"+count+"_size", Math.round((1.1+Math.log(tag.size())/4)*100)/100.); + } + count++; + } } prop.put("display_"+id, count); } - private static int recurseFolders(final Iterator it, String root, int count, final boolean next, final String prev){ - String fn=""; - BookmarksDB.Bookmark bookmark; + private static int recurseFolders(final Iterator it, String root, int count, final boolean next, final String prev) { - if (next) fn = it.next(); - else fn = prev; - - if(fn.equals("\uffff")) { - int i = prev.replaceAll("[^/]","").length(); - while(i>0){ - prop.put("display_folderlist_"+count+"_folder", ""); - count++; - i--; - } - return count; + final String fn = (next) ? it.next() : prev; + + if("\uffff".equals(fn)) { + int i = prev.replaceAll("[^/]","").length(); + while( i>0 ){ + prop.put("display_folderlist_"+count+"_folder", ""); + count++; + i--; + } + return count; } - if(fn.startsWith((root.equals("/") ? root : root+"/"))){ - prop.put("display_folderlist_"+count+"_folder", "
  • "+fn.replaceFirst(root+"/*","")+"
      "); - count++; - final Iterator bit=sb.bookmarksDB.getBookmarksIterator(fn, isAdmin); - while(bit.hasNext()){ - bookmark=sb.bookmarksDB.getBookmark(bit.next()); - if(bookmark == null) break; - prop.put("display_folderlist_"+count+"_folder", "
    • "+ bookmark.getTitle()+"
    • "); - count++; - } - if(it.hasNext()){ - count = recurseFolders(it, fn, count, true, fn); - } + if (fn.startsWith((root.equals("/") ? root : root+"/"))) { + prop.put("display_folderlist_"+count+"_folder", "
    • "+fn.replaceFirst(root+"/*","")+"
        "); + count++; + final Iterator bit = sb.bookmarksDB.getBookmarksIterator(fn, isAdmin); + + while (bit.hasNext()) { + Bookmark bookmark=sb.bookmarksDB.getBookmark(bit.next()); + if(bookmark == null) { + break; + } + prop.put("display_folderlist_" + count + "_folder", "
      • " + bookmark.getTitle() + "
      • "); + count++; + } + + if (it.hasNext()) { + count = recurseFolders(it, fn, count, true, fn); + } + } else { - prop.put("display_folderlist_"+count+"_folder", "
    • "); - count++; - root = root.replaceAll("(/.[^/]*$)", ""); - if(root.equals("")) root = "/"; - count = recurseFolders(it, root, count, false, fn); + prop.put("display_folderlist_"+count+"_folder", "
  • "); + count++; + root = root.replaceAll("(/.[^/]*$)", ""); + if ("".equals(root)) { + root = "/"; + } + count = recurseFolders(it, root, count, false, fn); } return count; } private static void publishNews(final String url, final String title, final String description, final String tagsString) { // create a news message - final HashMap map = new HashMap(); + final Map map = new HashMap(); map.put("url", url.replace(',', '|')); map.put("title", title.replace(',', ' ')); map.put("description", description.replace(',', ' ')); diff --git a/htroot/ConfigAccounts_p.java b/htroot/ConfigAccounts_p.java index 817031217..aa87141fe 100644 --- a/htroot/ConfigAccounts_p.java +++ b/htroot/ConfigAccounts_p.java @@ -1,4 +1,4 @@ -//User_p.java +//Config_Accounts_p.java //----------------------- //part of the AnomicHTTPD caching proxy //(C) by Michael Peter Christen; mc@yacy.net @@ -42,24 +42,26 @@ import de.anomic.http.server.HTTPDemon; import de.anomic.search.Switchboard; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; +import java.util.Map; public class ConfigAccounts_p { public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { + final serverObjects prop = new serverObjects(); final Switchboard sb = Switchboard.getSwitchboard(); - UserDB.Entry entry=null; + UserDB.Entry entry = null; // admin password boolean localhostAccess = sb.getConfigBool("adminAccountForLocalhost", false); - if ((post != null) && (post.containsKey("setAdmin"))) { - localhostAccess = post.get("access", "").equals("localhost"); - final String user = (post == null) ? "" : post.get("adminuser", ""); - final String pw1 = (post == null) ? "" : post.get("adminpw1", ""); - final String pw2 = (post == null) ? "" : post.get("adminpw2", ""); + if (post != null && post.containsKey("setAdmin")) { + localhostAccess = "localhost".equals(post.get("access", "")); + final String user = (post == null) ? "" : post.get("adminuser", ""); + final String pw1 = (post == null) ? "" : post.get("adminpw1", ""); + final String pw2 = (post == null) ? "" : post.get("adminpw2", ""); // may be overwritten if new password is given - if ((user.length() > 0) && (pw1.length() > 3) && (pw1.equals(pw2))) { + if (user.length() > 0 && pw1.length() > 3 && pw1.equals(pw2)) { // check passed. set account: env.setConfig(HTTPDemon.ADMIN_ACCOUNT_B64MD5, Digest.encodeMD5Hex(Base64Order.standardCoder.encodeString(user + ":" + pw1))); env.setConfig("adminAccount", ""); @@ -107,32 +109,34 @@ public class ConfigAccounts_p { prop.put("address", ""); prop.put("timelimit", ""); prop.put("timeused", ""); - final String[] rightNames=UserDB.Entry.RIGHT_NAMES.split(","); - final String[] rights=UserDB.Entry.RIGHT_TYPES.split(","); - int i; - for(i=0;i rightsSet=new HashMap(); - for(i=0;i rightsSet = new HashMap(); + + for(final String right : rights) { + rightsSet.put(right, post.containsKey(right)&&(post.get(right)).equals("on") ? "true" : "false"); } - final HashMap mem=new HashMap(); + + final Map mem = new HashMap(); if( post.get("current_user").equals("newuser")){ //new user - if(!pw1.equals("")){ //change only if set - mem.put(UserDB.Entry.MD5ENCODED_USERPWD_STRING, Digest.encodeMD5Hex(username+":"+pw1)); - } - mem.put(UserDB.Entry.USER_FIRSTNAME, firstName); - mem.put(UserDB.Entry.USER_LASTNAME, lastName); - mem.put(UserDB.Entry.USER_ADDRESS, address); - mem.put(UserDB.Entry.TIME_LIMIT, timeLimit); - mem.put(UserDB.Entry.TIME_USED, timeUsed); - for(i=0;i it = sb.userDB.iterator(true); int numUsers=0; - while(it.hasNext()){ + while (it.hasNext()) { entry = it.next(); - if (entry == null) continue; + if (entry == null) { + continue; + } prop.putHTML("users_"+numUsers+"_user", entry.getUserName()); numUsers++; } diff --git a/htroot/ConfigAppearance_p.java b/htroot/ConfigAppearance_p.java index de0380299..baf9ff433 100644 --- a/htroot/ConfigAppearance_p.java +++ b/htroot/ConfigAppearance_p.java @@ -96,7 +96,7 @@ public class ConfigAppearance_p { // load skin from URL final String url = post.get("url"); - Iterator it; + final Iterator it; try { final DigestURI u = new DigestURI(url); it = FileUtils.strings(u.get(MultiProtocolURI.yacybotUserAgent, 10000)); @@ -112,12 +112,13 @@ public class ConfigAppearance_p { while (it.hasNext()) { bw.write(it.next() + "\n"); } + bw.close(); } catch (final IOException e) { prop.put("status", "2");// error saving the skin return prop; } - if (post.containsKey("use_skin") && (post.get("use_skin", "")).equals("on")) { + if (post.containsKey("use_skin") && "on".equals(post.get("use_skin", ""))) { changeSkin(sb, skinPath, url.substring(url.lastIndexOf('/'), url.length())); } } @@ -126,8 +127,10 @@ public class ConfigAppearance_p { if (skinFiles.contains(selectedSkin)) { changeSkin(sb, skinPath, selectedSkin); } - for (Map.Entry entry: post.entrySet()) { - if (entry.getKey().startsWith("color_")) env.setConfig(entry.getKey(), "#" + entry.getValue()); + for (final Map.Entry entry: post.entrySet()) { + if (entry.getKey().startsWith("color_")) { + env.setConfig(entry.getKey(), "#" + entry.getValue()); + } } } } @@ -136,7 +139,7 @@ public class ConfigAppearance_p { skinFiles = FileUtils.getDirListing(skinPath, SKIN_FILENAME_FILTER); Collections.sort(skinFiles); int count = 0; - for (String skinFile : skinFiles) { + for (final String skinFile : skinFiles) { if (skinFile.endsWith(".css")) { prop.put("skinlist_" + count + "_file", skinFile); prop.put("skinlist_" + count + "_name", skinFile.substring(0, skinFile.length() - 4)); @@ -148,9 +151,8 @@ public class ConfigAppearance_p { // write colors from generic skin Iterator i = env.configKeys(); - String key; while (i.hasNext()) { - key = i.next(); + final String key = i.next(); if (key.startsWith("color_")) prop.put(key, env.getConfig(key, "#000000").substring(1)); } return prop; diff --git a/htroot/api/blacklists.java b/htroot/api/blacklists.java index 93db2cef4..d3faa19cf 100644 --- a/htroot/api/blacklists.java +++ b/htroot/api/blacklists.java @@ -16,29 +16,30 @@ public class blacklists { ListManager.listsPath = new File(ListManager.switchboard.getDataPath(),ListManager.switchboard.getConfig("listManager.listsPath", "DATA/LISTS")); final List dirlist = FileUtils.getDirListing(ListManager.listsPath); - int blacklistCount=0; + int blacklistCount = 0; final String blackListName = (post == null) ? "" : post.get("listname", ""); - List list; - int count; if (dirlist != null) { - for (String element : dirlist) { - if (blackListName.equals("") || element.equals(blackListName)) { + for (final String element : dirlist) { + if ("".equals(blackListName) || element.equals(blackListName)) { prop.putXML("lists_" + blacklistCount + "_name", element); if (ListManager.listSetContains("BlackLists.Shared", element)) { - list = FileUtils.getListArray(new File(ListManager.listsPath, element)); + final List list = FileUtils.getListArray(new File(ListManager.listsPath, element)); - count=0; - for (int j=0;j list; int count; if (dirlist != null) { - for (String element : dirlist) { - if (blackListName.equals("") || element.equals(blackListName)) { + for (final String element : dirlist) { + if ("".equals(blackListName) || element.equals(blackListName)) { prop.putXML("lists_" + blacklistCount + "_name", element); if (ListManager.listSetContains("BlackLists.Shared", element)) { @@ -37,24 +36,24 @@ public class blacklists_p { } final String[] types = Blacklist.BLACKLIST_TYPES_STRING.split(","); - for (int j=0; j list = FileUtils.getListArray(new File(ListManager.listsPath, element)); count=0; - for (int j=0;j tags=ListManager.string2set(BookmarkHelper.cleanTagsString(tagsString)); - final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username); - if(bookmark != null){ - bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title); - bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description); - if(user!=null){ - bookmark.setOwner(user.getUserName()); - } - if((post.get("public")).equals("public")){ - bookmark.setPublic(true); - publishNews(url, title, description, tagsString); - }else{ - bookmark.setPublic(false); - } - if(post.containsKey("feed") && (post.get("feed")).equals("feed")){ - bookmark.setFeed(true); - }else{ - bookmark.setFeed(false); - } - bookmark.setTags(tags, true); - sb.bookmarksDB.saveBookmark(bookmark); - prop.put("result", "1"); - } else { - // ERROR - prop.put("result", "0"); - } + if (post != null) { + if (!isAdmin) { + // force authentication if desired + if(post.containsKey("login")){ + prop.put("AUTHENTICATE","admin log-in"); + } + return prop; + } + final String url=post.get("url",""); + final String title=post.get("title",url); + final String description=post.get("description",""); + String tagsString = post.get("tags",""); + String pathString = post.get("path","/unsorted"); + tagsString= tagsString + "," + pathString; + final Set tags = ListManager.string2set(BookmarkHelper.cleanTagsString(tagsString)); + final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username); + if(bookmark != null){ + bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title); + bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description); + if(user!=null){ + bookmark.setOwner(user.getUserName()); + } + if("public".equals(post.get("public"))){ + bookmark.setPublic(true); + publishNews(url, title, description, tagsString); + }else{ + bookmark.setPublic(false); + } + if(post.containsKey("feed") && "feed".equals(post.get("feed"))){ + bookmark.setFeed(true); + }else{ + bookmark.setFeed(false); + } + bookmark.setTags(tags, true); + sb.bookmarksDB.saveBookmark(bookmark); + prop.put("result", "1"); + } else { + // ERROR + prop.put("result", "0"); + } } // return rewrite properties return prop; } private static void publishNews(final String url, final String title, final String description, final String tagsString) { // create a news message - final HashMap map = new HashMap(8); + final Map map = new HashMap(8); map.put("url", url.replace(',', '|')); map.put("title", title.replace(',', ' ')); map.put("description", description.replace(',', ' ')); diff --git a/htroot/api/config_p.java b/htroot/api/config_p.java index 9c4aefdc1..dde234c32 100644 --- a/htroot/api/config_p.java +++ b/htroot/api/config_p.java @@ -10,37 +10,36 @@ import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; public class config_p { - - + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { // return variable that accumulates replacements //plasmaSwitchboard switchboard = (plasmaSwitchboard) env; final serverObjects prop = new serverObjects(); - String key; //change a Key - if(post != null && post.containsKey("key") && post.containsKey("value")){ - key=post.get("key"); - final String value=post.get("value"); - if(!key.equals("")){ + if(post != null && post.containsKey("key") && post.containsKey("value")) { + final String key = post.get("key"); + final String value = post.get("value"); + if(!"".equals(key)) { env.setConfig(key, value); } } - Iterator keys = env.configKeys(); + final Iterator keys = env.configKeys(); final List list = new ArrayList(250); - while(keys.hasNext()){ + + while (keys.hasNext()) { list.add(keys.next()); } + Collections.sort(list); - keys = list.iterator(); int count=0; - while(keys.hasNext()){ - key = keys.next(); - prop.putHTML("options_"+count+"_key", key); - prop.putHTML("options_"+count+"_value", env.getConfig(key, "ERROR")); + + for (final String key : list) { + prop.putHTML("options_" + count + "_key", key); + prop.putHTML("options_" + count + "_value", env.getConfig(key, "ERROR")); count++; } prop.put("options", count); @@ -50,6 +49,3 @@ public class config_p { } } - - -