diff --git a/htroot/htdocsdefault/dir.html b/htroot/htdocsdefault/dir.html index 9b09cc623..c84450f01 100644 --- a/htroot/htdocsdefault/dir.html +++ b/htroot/htdocsdefault/dir.html @@ -59,8 +59,26 @@ - - + +
Welcome! You are identified and authorized as "#[ident]#".#[logout]#Welcome! You are identified and authorized as "#(ident)#Administrator::Uploader::Downloader::not authorized#(/ident)#". + #(logout)# +
+ +  (enter empty account) +
+ :: +
+ +  (enter empty account) +
+ :: +
+ +  (enter empty account) +
+ :: + #(/logout)# +
@@ -69,13 +87,98 @@ - + + +
Service
#[service]#
+ #(service)# + + + + + + + + + +
New Directory:
+ +   + +
+
File Upload:
+ Resource =  + +
+ Description = 
+ Indexing : 
+ +
+
+ :: + You are granted to view directory listings and do downloads in this directory.
+ If you want to upload, please log in as user 'upload' + :: + No service available. + #(/service)# +
- + + +
Account
#[account]#
+ #(account)# + + + + + + + + + +
upload:
+ +   + +
+
download:
+ +   + +
+
+ :: +
+ + +
+ :: +
+ + +
+
+ + +
+ :: +
+ + +
+
+ + +
+
+ + +
+ #(/account)# +
@@ -83,7 +186,23 @@ - + + +
Info
#[info]#
+ #(info)# + Admin and download accounts are necessary to grant their services to clients; + no password is required for the download-account unless you set one. + Files uploaded and indexed here have a special index entry 'yacyshare'; + if you want to find files that are indexed in any share zone, add the word 'yacyshare' to the search words. + :: + Uploaders are not granted to delete files or directories. If you want to do this, log-in as admin. + :: + Download is granted even if no download account has been defined.
+ If you are an administrator and you wish to block non-authorized downloades, please log in as user 'admin' and set a download password. + :: + You must log-in to upload or download. + #(/info)# +
diff --git a/htroot/htdocsdefault/dir.java b/htroot/htdocsdefault/dir.java index 2eba16340..4eb87d196 100644 --- a/htroot/htdocsdefault/dir.java +++ b/htroot/htdocsdefault/dir.java @@ -1,6 +1,5 @@ // dir.java // ----------------------- -// part of the AnomicHTTPD caching proxy // (C) by Michael Peter Christen; mc@anomic.de // first published on http://www.anomic.de // Frankfurt, Germany, 2004, 2005 @@ -52,6 +51,7 @@ import java.io.File; import java.io.IOException; import de.anomic.net.URL; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.Map; @@ -71,6 +71,8 @@ import de.anomic.server.serverMemory; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; import de.anomic.server.logging.serverLog; +import de.anomic.tools.dirlistComparator; +import de.anomic.tools.md5DirFileFilter; import de.anomic.yacy.yacyCore; import de.anomic.yacy.yacySeed; import de.anomic.data.userDB; @@ -222,10 +224,14 @@ public class dir { // if authorized, generate directory tree listing if ((adminAuthorization) || (uploadAuthorization) || (downloadAuthorization)) { // generate dir listing - final String[] list = dir.list(); - File f, fmd5; + md5DirFileFilter fileFilter = new md5DirFileFilter(); + final File[] list = dir.listFiles(fileFilter); + + // sorting the dir list + dirlistComparator comparator = new dirlistComparator(); + Arrays.sort(list,comparator); + String md5s, description; - Date d; // tree += "path = " + path + "

"; if (list != null) { int filecount = 0, fileIdx = 0; @@ -233,66 +239,77 @@ public class dir { boolean dark = false; for (int i = 0; i < list.length; i++) { - if (!((list[i].startsWith("dir.")) || (list[i].endsWith(".md5")))) { - - prop.put("dirlist_" + fileIdx + "_dark" , dark?1:0); - - dark = !dark; - filecount++; - f = new File(dir, list[i]); - fmd5 = new File(dir, list[i] + ".md5"); - try { - if (fmd5.exists()) { - md5s = new String(serverFileUtils.read(fmd5)); - pos = md5s.indexOf('\n'); - if (pos >= 0) { - description = md5s.substring(pos + 1); - md5s = md5s.substring(0, pos); - } else { - description = ""; - } + + filecount++; + File f = list[i]; + String fileName = f.getName(); + + // changing table row color + prop.put("dirlist_" + fileIdx + "_dark" , dark?1:0); + dark = !dark; + + + // reading the content of the md5 file that belongs + // to the file + File fmd5 = new File(dir, fileName + ".md5"); + try { + if (fmd5.exists()) { + md5s = new String(serverFileUtils.read(fmd5)); + pos = md5s.indexOf('\n'); + if (pos >= 0) { + // the second line contains an optional description + description = md5s.substring(pos + 1); + // the first line contains the md5 sum of the file + md5s = md5s.substring(0, pos); } else { - // generate md5 on-the-fly - md5s = serverCodings.encodeMD5Hex(f); description = ""; - serverFileUtils.write((md5s + "\n" + description).getBytes("UTF-8"), fmd5); - } - } catch (IOException e) { - md5s = ""; + } + } else { + // generate md5 on-the-fly + md5s = serverCodings.encodeMD5Hex(f); description = ""; + serverFileUtils.write((md5s + "\n" + description).getBytes("UTF-8"), fmd5); } - d = new Date(f.lastModified()); - if (f.isDirectory()) { - prop.put("dirlist_" + fileIdx + "_dir" , 1); - prop.put("dirlist_" + fileIdx + "_dir_date" , dateString(d)); - prop.put("dirlist_" + fileIdx + "_dir_name" , list[i]); + } catch (IOException e) { + md5s = ""; + description = ""; + } + + // last modification date if the entry + prop.put("dirlist_" + fileIdx + "_dir_date" , dateString(new Date(f.lastModified()))); + // the entry name + prop.put("dirlist_" + fileIdx + "_dir_name" , fileName); + + if (f.isDirectory()) { + // the entry is a directory + prop.put("dirlist_" + fileIdx + "_dir" , 1); + } else { + // determine if we should display the description string or a preview image + boolean showImage = (description.length() == 0) && (fileName.endsWith(".jpg") || fileName.endsWith(".gif") || fileName.endsWith(".png")); + + // the entry is a file + prop.put("dirlist_" + fileIdx + "_dir" , 0); + // the file size + prop.put("dirlist_" + fileIdx + "_dir_size" , serverMemory.bytesToString(f.length()).replaceAll(" ", " ")); + // the unique url + prop.put("dirlist_" + fileIdx + "_dir_yacyhURL",yacyhURL(yacyCore.seedDB.mySeed, fileName, md5s)); + // the md5 sum of the file + prop.put("dirlist_" + fileIdx + "_dir_md5s",md5s); + // description mode: 0...image preview, 1...description text + prop.put("dirlist_" + fileIdx + "_dir_descriptionMode",showImage?0:1); + if (showImage) { + prop.put("dirlist_" + fileIdx + "_dir_descriptionMode_image",fileName); } else { - prop.put("dirlist_" + fileIdx + "_dir" , 0); - prop.put("dirlist_" + fileIdx + "_dir_date" , dateString(d)); - prop.put("dirlist_" + fileIdx + "_dir_name" , list[i]); - prop.put("dirlist_" + fileIdx + "_dir_size" , serverMemory.bytesToString(f.length()).replaceAll(" ", " ")); - prop.put("dirlist_" + fileIdx + "_dir_yacyhURL",yacyhURL(yacyCore.seedDB.mySeed, f.getName(), md5s)); - prop.put("dirlist_" + fileIdx + "_dir_md5s",md5s); - - boolean showImage = (description.length() == 0) && (list[i].endsWith(".jpg") || list[i].endsWith(".gif") || list[i].endsWith(".png")); - prop.put("dirlist_" + fileIdx + "_dir_descriptionMode",showImage?0:1); - if (showImage) { - prop.put("dirlist_" + fileIdx + "_dir_descriptionMode_image",list[i]); - } else { - prop.put("dirlist_" + fileIdx + "_dir_descriptionMode_text",description); - } - } - - prop.put("dirlist_" + fileIdx + "_adminAuthorization",adminAuthorization?1:0); - if (adminAuthorization) { - prop.put("dirlist_" + fileIdx + "_adminAuthorization_name",list[i]); - } - -// if (adminAuthorization) tree += " "; else tree += "
"; - fileIdx++; + prop.put("dirlist_" + fileIdx + "_dir_descriptionMode_text",description); + } } + + prop.put("dirlist_" + fileIdx + "_adminAuthorization",adminAuthorization?1:0); + prop.put("dirlist_" + fileIdx + "_adminAuthorization_name",fileName); + + fileIdx++; } - + prop.put("dirlist",filecount); prop.put("emptydir", filecount == 0 ? 1:0); } @@ -301,151 +318,37 @@ public class dir { prop.put("authenticated",0); } - - String ident = ""; - String account = ""; - String service = ""; - String info = ""; - String logout = ""; if (adminAuthorization) { - ident = "Administrator"; - account = "" + - "" + - "" + - "
upload:
" + - "" + - " " + - "" + - "
download:
" + - "" + - " " + - "" + - "
"; - logout = "
" + - "" + - " (enter empty account)" + - "
"; - service = "" + - "" + - "" + - "" + - "" + - "" + - "" + - "
New Directory:
" + - "" + - " " + - "" + - "
File Upload:
" + - "Resource = " + - "
" + - "Description = 
" + - "Indexing : 
" + - "" + - "
"; - info = "Admin and download accounts are necessary to grant their services to clients; " + - "no password is required for the download-account unless you set one. " + - "Files uploaded and indexed here have a special index entry 'yacyshare'; " + - "if you want to find files that are indexed in any share zone, add the word 'yacyshare' to the search words."; + prop.put("ident", 0); + prop.put("logout", 0); + prop.put("account", 0); + prop.put("service",0); + prop.put("info", 0); } else if (uploadAuthorization) { - ident = "Uploader"; - account = "
" + - "" + - "" + - "
"; - if (uploadAccountBase64MD5.length() == 0) { - logout = ""; - } else { - logout = "
" + - "" + - " (enter empty account)" + - "
"; - } - service = "" + - "" + - "" + - "" + - "" + - "" + - "" + - "
New Directory:
" + - "" + - " " + - "" + - "
File Upload:
" + - "Resource = " + - "
" + - "Description = 
" + - "Indexing : 
" + - "" + - "
"; - info = "Uploaders are not granted to delete files or directories. If you want to do this, log-in as admin."; + prop.put("ident", 1); + prop.put("logout", 1); + prop.put("account", 1); + prop.put("service",0); + prop.put("info", 1); } else if (downloadAuthorization) { - ident = "Downloader"; - account = "
" + - "" + - "" + - "
" + - "
" + - "" + - "" + - "
"; - if (downloadAccountBase64MD5.length() == 0) { - logout = ""; - } else { - logout = "
" + - "" + - " (enter empty account)" + - "
"; - service = "You are granted to view directory listings and do downloads in this directory.
" + - "If you want to upload, please log in as user 'upload'"; - info = "Download is granted even if no download account has been defined. " + - "If you are an administrator and you wish to block non-authorized downloades, please log in as user 'admin' " + - "and set a download password."; - } + prop.put("ident", 2); + prop.put("logout", 2); + prop.put("account", 2); + prop.put("service",1); + prop.put("info", 2); + } else { - ident = "not authorized"; - account = "
" + - "" + - "" + - "
" + - "
" + - "" + - "" + - "
" + - "
" + - "" + - "" + - "
"; - logout = ""; - service = "No service available."; - info = "You must log-in to upload or download."; + prop.put("ident", 3); + prop.put("logout", 3); + prop.put("account",3); + prop.put("service", 2); + prop.put("info", 3); } - prop.put("ident", ident); - prop.put("account", account); - prop.put("service", service); - prop.put("info", info); - prop.put("logout", logout); -// return rewrite properties + // return rewrite properties return prop; } - private static String formatLong(long l, int length) { - String r = "" + l; - for (int i = r.length(); i < length; i++) { r = " " + r; } - return r; - } - - // rDNS services: - // http://www.xdr2.net/reverse_DNS_lookup.asp - // http://remote.12dt.com/rns/ - // http://bl.reynolds.net.au/search/ - // http://www.declude.com/Articles.asp?ID=97 - // http://www.dnsstuff.com/ - - // listlist: http://www.aspnetimap.com/help/welcome/dnsbl.html - public static String yacyhURL(yacySeed seed, String filename, String md5) { return "http://share." + seed.getHexHash() + ".yacyh/" + filename + "?md5=" + md5; } diff --git a/source/de/anomic/tools/dirlistComparator.java b/source/de/anomic/tools/dirlistComparator.java new file mode 100644 index 000000000..00cf7671f --- /dev/null +++ b/source/de/anomic/tools/dirlistComparator.java @@ -0,0 +1,68 @@ +package de.anomic.tools; +// dirlistComparator.java +// ----------------------- +// (C) by Michael Peter Christen; mc@anomic.de +// first published on http://www.anomic.de +// Frankfurt, Germany, 2004, 2005 +// +// This file is contributed by Martin Thelian +// +// $LastChangedDate: 2006-08-06 10:09:39 +0200 (So, 06 Aug 2006) $ +// $LastChangedRevision: 2349 $ +// $LastChangedBy: theli $ +// +// 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 +// +// Using this software in any meaning (reading, learning, copying, compiling, +// running) means that you agree that the Author(s) is (are) not responsible +// for cost, loss of data or any harm that may be caused directly or indirectly +// by usage of this softare or this documentation. The usage of this software +// is on your own risk. The installation and usage (starting/running) of this +// software may allow other people or application to access your computer and +// any attached devices and is highly dependent on the configuration of the +// software which must be done by the user of the software; the author(s) is +// (are) also not responsible for proper configuration and usage of the +// software, even if provoked by documentation provided together with +// the software. +// +// Any changes to this file according to the GPL as documented in the file +// gpl.txt aside this file in the shipment you received can be done to the +// lines that follows this copyright notice here, but changes must not be +// done inside the copyright notive above. A re-distribution must contain +// the intact and unchanged copyright notice. +// Contributions and changes to the program code must be marked as such. +import java.io.File; +import java.util.Comparator; + + +public class dirlistComparator implements Comparator { + + public int compare(Object obj1, Object obj2) { + if (!(obj1 instanceof File)) throw new IllegalArgumentException(); + if (!(obj2 instanceof File)) throw new IllegalArgumentException(); + + File file1 = (File)obj1; + File file2 = (File)obj2; + + if (file1.isDirectory() && !file2.isDirectory()) { + return -1; + } else if (!file1.isDirectory() && file2.isDirectory()) { + return 1; + } else { + return file1.getName().compareToIgnoreCase(file2.getName()); + } + } + +} diff --git a/source/de/anomic/tools/md5DirFileFilter.java b/source/de/anomic/tools/md5DirFileFilter.java new file mode 100644 index 000000000..4d036a620 --- /dev/null +++ b/source/de/anomic/tools/md5DirFileFilter.java @@ -0,0 +1,57 @@ +package de.anomic.tools; +// md5DirFileFilter.java +// ----------------------- +// (C) by Michael Peter Christen; mc@anomic.de +// first published on http://www.anomic.de +// Frankfurt, Germany, 2004, 2005 +// +// This file is contributed by Martin Thelian +// +// $LastChangedDate: 2006-08-06 10:09:39 +0200 (So, 06 Aug 2006) $ +// $LastChangedRevision: 2349 $ +// $LastChangedBy: theli $ +// +// 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 +// +// Using this software in any meaning (reading, learning, copying, compiling, +// running) means that you agree that the Author(s) is (are) not responsible +// for cost, loss of data or any harm that may be caused directly or indirectly +// by usage of this softare or this documentation. The usage of this software +// is on your own risk. The installation and usage (starting/running) of this +// software may allow other people or application to access your computer and +// any attached devices and is highly dependent on the configuration of the +// software which must be done by the user of the software; the author(s) is +// (are) also not responsible for proper configuration and usage of the +// software, even if provoked by documentation provided together with +// the software. +// +// Any changes to this file according to the GPL as documented in the file +// gpl.txt aside this file in the shipment you received can be done to the +// lines that follows this copyright notice here, but changes must not be +// done inside the copyright notive above. A re-distribution must contain +// the intact and unchanged copyright notice. +// Contributions and changes to the program code must be marked as such. + +import java.io.File; +import java.io.FilenameFilter; + + +public class md5DirFileFilter implements FilenameFilter { + + public boolean accept(File dir, String name) { + return !(name.startsWith("dir.") || name.endsWith(".md5")); + } + +}