diff --git a/bin/importmediawiki.sh b/bin/importmediawiki.sh index b520dc321..df1b4c7ae 100755 --- a/bin/importmediawiki.sh +++ b/bin/importmediawiki.sh @@ -1,3 +1,3 @@ #!/usr/bin/env sh cd "`dirname $0`" -./apicall.sh /IndexImportMediawiki_p.html?file=$1 > /dev/null +./protectedPostApiCall.sh "IndexImportMediawiki_p.html" "file=$1" diff --git a/htroot/ConfigAccountList_p.html b/htroot/ConfigAccountList_p.html new file mode 100644 index 000000000..036a56502 --- /dev/null +++ b/htroot/ConfigAccountList_p.html @@ -0,0 +1,29 @@ + + + + YaCy '#[clientname]#': User Accounts + #%env/templates/metas.template%# + + + + #%env/templates/header.template%# + #%env/templates/submenuUseCaseAccount.template%# +

User List

+ +
User Accounts + + + + + #{userlist}# + + + + #{/userlist}# +
UserFirst nameLast nameAddressLast AccessRightsTimeTraffic
#[username]##[firstname]##[lastname]##[address]##[lastaccess]##[rights]##[time]##[traffic]#
+ +
+ +#%env/templates/footer.template%# + + diff --git a/htroot/ConfigAccountList_p.java b/htroot/ConfigAccountList_p.java new file mode 100644 index 000000000..e6ee44f63 --- /dev/null +++ b/htroot/ConfigAccountList_p.java @@ -0,0 +1,103 @@ +// ConfigAccountList_p.java +// ------------------------- +// (c) 2017 by reger24; https://github.com/reger24 +// +// This is a part of YaCy, a peer-to-peer based web search engine +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import java.util.Date; +import java.util.Iterator; +import net.yacy.cora.date.GenericFormatter; +import net.yacy.cora.protocol.RequestHeader; +import net.yacy.data.UserDB; +import net.yacy.data.UserDB.AccessRight; +import net.yacy.search.Switchboard; +import net.yacy.server.serverObjects; +import net.yacy.server.serverSwitch; + +public class ConfigAccountList_p { + + public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) { + + final serverObjects prop = new serverObjects(); + final Switchboard sb = (Switchboard) env; + UserDB.Entry entry; + + if (sb.userDB == null) { + prop.put("userlist", 0); + return prop; + } + + //Generate Userlist + final Iterator it = sb.userDB.iterator(true); + int numUsers = 0; + while (it.hasNext()) { + entry = it.next(); + if (entry == null) { + continue; + } + prop.putHTML("userlist_" + numUsers + "_username", entry.getUserName()); + prop.putHTML("userlist_" + numUsers + "_lastname", entry.getLastName()); + prop.putHTML("userlist_" + numUsers + "_firstname", entry.getFirstName()); + prop.putHTML("userlist_" + numUsers + "_address", entry.getAddress()); + if (entry.getLastAccess() != null) { + prop.put("userlist_" + numUsers + "_lastaccess", GenericFormatter.FORMAT_SIMPLE.format(new Date(entry.getLastAccess()))); + } else { + prop.put("userlist_" + numUsers + "_lastaccess", "never"); + } + + final AccessRight[] rights = AccessRight.values(); + String rightStr = ""; + for (final AccessRight right : rights) { + if (entry.hasRight(right)) { + if (rightStr.isEmpty()) { + rightStr = right.getFriendlyName(); + } else { + rightStr += ", " + right.getFriendlyName(); + } + } + } + prop.putHTML("userlist_" + numUsers + "_rights", rightStr); + + long percent; + if (entry.getTrafficLimit() != null) { + long limit = entry.getTrafficLimit(); + long used = entry.getTrafficSize(); + percent = used * 100 / limit; + prop.put("userlist_" + numUsers + "_time", percent); + } else { + prop.put("userlist_" + numUsers + "_time", ""); + } + + percent = -1; + if (entry.getTimeLimit() > 0) { + long limit = entry.getTimeLimit(); + long used = entry.getTimeUsed(); + percent = used * 100 / limit; + prop.put("userlist_" + numUsers + "_traffic", percent); + } else { + prop.put("userlist_" + numUsers + "_traffic", ""); + } + + + numUsers++; + } + prop.put("userlist", numUsers); + + // return rewrite properties + return prop; + } +} diff --git a/htroot/ConfigAccounts_p.html b/htroot/ConfigAccounts_p.html index 40bd836aa..4a95fc370 100644 --- a/htroot/ConfigAccounts_p.html +++ b/htroot/ConfigAccounts_p.html @@ -75,7 +75,7 @@
User Accounts -
+
Select user
@@ -84,7 +84,7 @@ + or goto user account list
 
@@ -128,7 +128,7 @@
-
+ #%env/templates/footer.template%# diff --git a/htroot/ConfigAccounts_p.java b/htroot/ConfigAccounts_p.java index 7ab11efc9..2b5a39f88 100644 --- a/htroot/ConfigAccounts_p.java +++ b/htroot/ConfigAccounts_p.java @@ -55,7 +55,7 @@ public class ConfigAccounts_p { /* Acquire a transaction token for the next POST form submission */ prop.put(TransactionManager.TRANSACTION_TOKEN_PARAM, TransactionManager.getTransactionToken(header)); - final Switchboard sb = Switchboard.getSwitchboard(); + final Switchboard sb = (Switchboard) env; UserDB.Entry entry = null; // admin password @@ -156,8 +156,8 @@ public class ConfigAccounts_p { //user != current_user //user=from userlist //current_user = edited user - } else if (post.containsKey("user") && !"newuser".equals(post.get("user"))){ - TransactionManager.checkPostTransaction(header, post); + } else if (post.containsKey("user") && !"newuser".equals(post.get("user"))) { + TransactionManager.checkPostTransaction(header, post); if (post.containsKey("change_user")) { //defaults for newuser are set above entry = sb.userDB.getEntry(post.get("user")); @@ -183,7 +183,7 @@ public class ConfigAccounts_p { sb.userDB.removeEntry(post.get("user")); } } else if (post.containsKey("change")) { //New User / edit User - TransactionManager.checkPostTransaction(header, post); + TransactionManager.checkPostTransaction(header, post); prop.put("text", "0"); prop.put("error", "0"); @@ -270,7 +270,24 @@ public class ConfigAccounts_p { prop.putHTML("text_username", username); prop.put("text", "2"); }//edit user + prop.putHTML("username", username); + if (entry != null) { + //TODO: set username read-only in html + prop.putHTML("current_user", entry.getUserName()); + prop.putHTML("username", entry.getUserName()); + prop.putHTML("firstname", entry.getFirstName()); + prop.putHTML("lastname", entry.getLastName()); + prop.putHTML("address", entry.getAddress()); + prop.put("timelimit", entry.getTimeLimit()); + prop.put("timeused", entry.getTimeUsed()); + int count = 0; + for (final AccessRight right : rights) { + prop.put("rights_" + count + "_set", entry.hasRight(right) ? "1" : "0"); + count++; + } + prop.put("rights", count); + } } //Generate Userlist diff --git a/htroot/ConfigSearchPage_p.html b/htroot/ConfigSearchPage_p.html index fa133af3b..1abb99c57 100644 --- a/htroot/ConfigSearchPage_p.html +++ b/htroot/ConfigSearchPage_p.html @@ -121,12 +121,6 @@ #(/search.navigation.location)# - - - -
:: +

#(status)#::

+ #(/status)#

Import Process
Thread:
#[thread]#
diff --git a/htroot/IndexImportMediawiki_p.java b/htroot/IndexImportMediawiki_p.java index 37a1c6b87..574892d46 100644 --- a/htroot/IndexImportMediawiki_p.java +++ b/htroot/IndexImportMediawiki_p.java @@ -23,22 +23,45 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import java.io.File; +import java.net.MalformedURLException; +import net.yacy.cora.document.id.MultiProtocolURL; import net.yacy.cora.protocol.RequestHeader; +import net.yacy.data.TransactionManager; import net.yacy.document.importer.MediawikiImporter; import net.yacy.search.Switchboard; import net.yacy.server.serverObjects; import net.yacy.server.serverSwitch; +/** + * Import of MediaWiki dump files in the local index. + */ public class IndexImportMediawiki_p { - public static serverObjects respond(@SuppressWarnings("unused") final RequestHeader header, final serverObjects post, final serverSwitch env) { + /** + * Run conditions : + * - no MediaWiki import thread is running : allow to start a new import by filling the "file" parameter + * - the MediaWiki import thread is running : returns monitoring information. + * @param header servlet request header + * @param post request parameters. Supported keys : + *
    + *
  • file : a dump file path on this YaCy server local file system
  • + *
+ * @param env server environment + * @return the servlet answer object + */ + public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { final serverObjects prop = new serverObjects(); final Switchboard sb = (Switchboard) env; if (MediawikiImporter.job != null && MediawikiImporter.job.isAlive()) { // one import is running, no option to insert anything prop.put("import", 1); + final String jobErrorMessage = MediawikiImporter.job.status(); + if( jobErrorMessage != null && !jobErrorMessage.isEmpty()) { + prop.put("import_status", 1); + prop.put("import_status_message", jobErrorMessage); + } prop.put("import_thread", "running"); prop.put("import_dump", MediawikiImporter.job.source()); prop.put("import_count", MediawikiImporter.job.count()); @@ -49,28 +72,63 @@ public class IndexImportMediawiki_p { prop.put("import_remainingMinutes", (MediawikiImporter.job.remainingTime() / 60) % 60); } else { prop.put("import", 0); + if(MediawikiImporter.job != null) { + /* Report eventual fail report from the last terminated import (for example an HTTP 404 status) + * that else could be missed by the user because of page refresh */ + final String jobErrorMessage = MediawikiImporter.job.status(); + if( jobErrorMessage != null && !jobErrorMessage.isEmpty()) { + prop.put("import_prevStatus", 1); + prop.put("import_prevStatus_message", jobErrorMessage); + } + } if (post == null) { prop.put("import_status", 0); + + /* Acquire a transaction token for the next POST form submission */ + final String token = TransactionManager.getTransactionToken(header); + prop.put(TransactionManager.TRANSACTION_TOKEN_PARAM, token); + prop.put("import_" + TransactionManager.TRANSACTION_TOKEN_PARAM, token); + } else { if (post.containsKey("file")) { + /* Check the transaction is valid */ + TransactionManager.checkPostTransaction(header, post); + String file = post.get("file"); - if (file.startsWith("file://")) file = file.substring(7); - if (file.startsWith("http")) { - prop.put("import_dump", ""); - prop.put("import_thread", "Error: file argument must be a path to a document in the local file system"); - } else { - final File sourcefile = new File(file); - if (sourcefile.exists()) { - MediawikiImporter.job = new MediawikiImporter(sourcefile, sb.surrogatesInPath); - MediawikiImporter.job.start(); - prop.put("import_dump", MediawikiImporter.job.source()); - prop.put("import_thread", "started"); - } else { - prop.put("import_dump", ""); - prop.put("import_thread", "Error: file not found ["+sourcefile+"]"); - } - } - prop.put("import", 1); + MultiProtocolURL sourceURL = null; + int status = 0; + String sourceFilePath = ""; + try { + sourceURL = new MultiProtocolURL(file); + if(sourceURL.isFile()) { + final File sourcefile = sourceURL.getFSFile(); + sourceFilePath = sourcefile.getAbsolutePath(); + if (!sourcefile.exists()) { + status = 2; + } else if (!sourcefile.canRead()) { + status = 3; + } else if (sourcefile.isDirectory()) { + status = 4; + } + } + } catch (MalformedURLException e) { + status = 1; + } + if (status == 0) { + MediawikiImporter.job = new MediawikiImporter(sourceURL, sb.surrogatesInPath); + MediawikiImporter.job.start(); + prop.put("import_dump", MediawikiImporter.job.source()); + prop.put("import_thread", "started"); + prop.put("import", 1); + } else { + prop.put("import_status", status); + prop.put("import_status_sourceFile", sourceFilePath); + + /* Acquire a transaction token for the next POST form submission */ + final String token = TransactionManager.getTransactionToken(header); + prop.put(TransactionManager.TRANSACTION_TOKEN_PARAM, token); + prop.put("import_" + TransactionManager.TRANSACTION_TOKEN_PARAM, token); + } prop.put("import_count", 0); prop.put("import_speed", 0); prop.put("import_runningHours", 0); diff --git a/htroot/IndexImportWarc_p.html b/htroot/IndexImportWarc_p.html index d6003bc9e..0d490eb9e 100644 --- a/htroot/IndexImportWarc_p.html +++ b/htroot/IndexImportWarc_p.html @@ -22,13 +22,16 @@ You can download warc archives for example here Internet Archive.

-
- - -
- -
-
+
+
+
+
+
or
+
+
+
+
+
diff --git a/htroot/IndexImportWarc_p.java b/htroot/IndexImportWarc_p.java index f503fe98b..6a3127952 100644 --- a/htroot/IndexImportWarc_p.java +++ b/htroot/IndexImportWarc_p.java @@ -18,6 +18,10 @@ import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import net.yacy.cora.document.id.MultiProtocolURL; +import net.yacy.cora.protocol.ClientIdentification; import net.yacy.cora.protocol.RequestHeader; import net.yacy.document.importer.WarcImporter; @@ -45,23 +49,42 @@ public class IndexImportWarc_p { } else { prop.put("import", 0); if (post != null) { - if (post.containsKey("file")) { - String file = post.get("file"); - final File sourcefile = new File(file); - if (sourcefile.exists()) { - try { - WarcImporter wi = new WarcImporter(sourcefile); - wi.start(); - prop.put("import_thread", "started"); - } catch (FileNotFoundException ex) { - prop.put("import_thread", "Error: file not found [" + file + "]"); + if (post.containsKey("file") || post.containsKey("url")) { + String filename = post.get("file"); + if (filename != null && filename.length() > 0) { + final File sourcefile = new File(filename); + if (sourcefile.exists()) { + try { + WarcImporter wi = new WarcImporter(sourcefile); + wi.start(); + prop.put("import_thread", "started"); + } catch (FileNotFoundException ex) { + prop.put("import_thread", "Error: file not found [" + filename + "]"); + } + prop.put("import", 1); + prop.put("import_warcfile", filename); + } else { + prop.put("import_warcfile", ""); + prop.put("import_thread", "Error: file not found [" + filename + "]"); } - prop.put("import_warcfile", file); } else { - prop.put("import_warcfile", ""); - prop.put("import_thread", "Error: file not found [" + file + "]"); + String urlstr = post.get("url"); + if (urlstr != null && urlstr.length() > 0) { + try { + MultiProtocolURL url = new MultiProtocolURL(urlstr); + WarcImporter wi = new WarcImporter(url.getInputStream(ClientIdentification.yacyInternetCrawlerAgent), urlstr); + wi.start(); + prop.put("import_thread", "started"); + } catch (MalformedURLException ex) { + prop.put("import_thread", ex.getMessage()); + } catch (IOException ex) { + prop.put("import_thread", ex.getMessage()); + } + prop.put("import", 1); + prop.put("import_warcfile", urlstr); + } } - prop.put("import", 1); + prop.put("import_count", 0); prop.put("import_speed", 0); prop.put("import_runningHours", 0); diff --git a/htroot/TransNews_p.html b/htroot/TransNews_p.html index 7e69deedb..840764502 100644 --- a/htroot/TransNews_p.html +++ b/htroot/TransNews_p.html @@ -14,7 +14,8 @@ You can share your local addition to translations and distribute it to other peers. The remote peer can vote on your translation and add it to the own local translation.
(#[transsize]# entries available)   -   You can check your outgoing messages here +   You can check your outgoing messages here. + To edit or add local translations you can use Translator_p.html.

#(errmsg)#::

Please activate a different language here

#(/errmsg)# diff --git a/htroot/yacy/message.java b/htroot/yacy/message.java index 9f46515d4..59a07e3ca 100644 --- a/htroot/yacy/message.java +++ b/htroot/yacy/message.java @@ -59,11 +59,15 @@ public final class message { } public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) { - if (post == null || env == null) { return null; } // return variable that accumulates replacements final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); + + prop.put("messagesize", "0"); + prop.put("attachmentsize", "0"); + prop.put("response", "-1"); // request rejected + if ((post == null) || (env == null)) return prop; if (!Protocol.authentifyRequest(post, env)) return prop; @@ -74,22 +78,17 @@ public final class message { final int messagesize = 10240; final int attachmentsize = 0; - prop.put("messagesize", "0"); - prop.put("attachmentsize", "0"); - final String youare = post.get("youare", ""); // seed hash of the target peer, needed for network stability // check if we are the right target and requester has correct information about this peer if ((sb.peers.mySeed() == null) || (!(sb.peers.mySeed().hash.equals(youare)))) { // this request has a wrong target - prop.put("response", "-1"); // request rejected return prop; } - if ((sb.isRobinsonMode()) && - (!((sb.isPublicRobinson()) || - (sb.isInMyCluster(header.getRemoteAddr()))))) { + if ((sb.isRobinsonMode()) + && (!((sb.isPublicRobinson()) + || (sb.isInMyCluster(header.getRemoteAddr()))))) { // if we are a robinson cluster, answer only if this client is known by our network definition - prop.put("response", "-1"); // request rejected return prop; } @@ -107,7 +106,7 @@ public final class message { // post: post message to message board final String otherSeedString = post.get("myseed", ""); if (otherSeedString.isEmpty()) { - prop.put("response", "-1"); // request rejected + // request rejected return prop; } //Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time @@ -115,20 +114,20 @@ public final class message { try { otherSeed = Seed.genRemoteSeed(otherSeedString, false, ias == null ? null : ias.getHostAddress()); } catch (final IOException e) { - prop.put("response", "-1"); // don't accept messages for bad seeds + // don't accept messages for bad seeds return prop; } String subject = crypt.simpleDecode(post.get("subject", "")); // message's subject String message = crypt.simpleDecode(post.get("message", "")); // message body if (subject == null || message == null) { - prop.put("response", "-1"); // don't accept empty messages + // don't accept empty messages return prop; } message = message.trim(); subject = subject.trim(); if (subject.isEmpty() || message.isEmpty()) { - prop.put("response", "-1"); // don't accept empty messages + // don't accept empty messages return prop; } @@ -156,7 +155,6 @@ public final class message { } } -// System.out.println("respond = " + prop.toString()); // return rewrite properties return prop; diff --git a/htroot/yacysearchtrailer.html b/htroot/yacysearchtrailer.html index 0057f9b7d..d72c11f2e 100644 --- a/htroot/yacysearchtrailer.html +++ b/htroot/yacysearchtrailer.html @@ -156,14 +156,6 @@ function toggleVisibility(name, count) { } } -#(nav-domains)#:: - - -#(/nav-domains)# #(nav-languages)#::