From 01b97ef3f80c53f4f7ed65e339da4d0935b90689 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 6 Feb 2009 15:06:19 +0000 Subject: [PATCH] added new cybertag-tracking feature that was inspired by itgrl from the forum discussion in http://forum.yacy-websuche.de/viewtopic.php?p=12612#p12612 The feature will provide two basic entities: - you can integrate image links which point to your yacy installation anywhere in the web. the image can be loaded with This will place a invisible 1-pixel image. If you change the icon=invisible to icon=redpill, you will see a red pill Use this, to track your activity in the web. - you can view your tracks at http://localhost:8080/Tracks.html - There is a public api to your tracks at http://localhost:8080/api/tracks_p.json which needs authentication git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5581 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .classpath | 98 +++++++++--------- build.xml | 2 +- htroot/ConfigBasic.html | 5 +- htroot/Trails.html | 67 ++++++++++++ htroot/Trails.java | 13 +++ htroot/api/trail_p.java | 47 +++++++++ htroot/api/trail_p.json | 8 ++ htroot/cytag.java | 89 ++++++++++++++++ htroot/env/grafics/invisible.png | Bin 0 -> 143 bytes htroot/env/grafics/mcemailh.gif | Bin 423 -> 0 bytes htroot/env/grafics/redpillmini.png | Bin 0 -> 482 bytes htroot/index.html | 1 + source/de/anomic/http/httpHeader.java | 6 +- source/de/anomic/http/httpd.java | 2 +- source/de/anomic/http/httpdFileHandler.java | 7 +- .../anomic/kelondro/order/DateFormatter.java | 5 + .../de/anomic/plasma/plasmaSwitchboard.java | 3 + source/de/anomic/server/serverCore.java | 3 - .../de/anomic/server/servletProperties.java | 1 + 19 files changed, 295 insertions(+), 62 deletions(-) create mode 100644 htroot/Trails.html create mode 100644 htroot/Trails.java create mode 100644 htroot/api/trail_p.java create mode 100644 htroot/api/trail_p.json create mode 100644 htroot/cytag.java create mode 100644 htroot/env/grafics/invisible.png delete mode 100644 htroot/env/grafics/mcemailh.gif create mode 100644 htroot/env/grafics/redpillmini.png diff --git a/.classpath b/.classpath index c8ae866ba..c57d83ee4 100644 --- a/.classpath +++ b/.classpath @@ -1,49 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build.xml b/build.xml index a2b3aa334..1de828c63 100644 --- a/build.xml +++ b/build.xml @@ -184,7 +184,7 @@ - + diff --git a/htroot/ConfigBasic.html b/htroot/ConfigBasic.html index 1f1a403fb..c60f32407 100644 --- a/htroot/ConfigBasic.html +++ b/htroot/ConfigBasic.html @@ -25,7 +25,7 @@ Your YaCy Peer needs some basic information to operate properly

-
+
  1. ok Select a language for the interface:
    @@ -53,7 +53,8 @@ - + + diff --git a/htroot/Trails.html b/htroot/Trails.html new file mode 100644 index 000000000..befd1a2c1 --- /dev/null +++ b/htroot/Trails.html @@ -0,0 +1,67 @@ + + + + CyTag Trails + #%env/templates/metas.template%# + + + +#%env/templates/header.template%# + +
    + +#%env/templates/footer.template%# + + \ No newline at end of file diff --git a/htroot/Trails.java b/htroot/Trails.java new file mode 100644 index 000000000..07ffc728b --- /dev/null +++ b/htroot/Trails.java @@ -0,0 +1,13 @@ +import de.anomic.http.httpRequestHeader; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; +import de.anomic.server.servletProperties; + +//dummy class +public class Trails { + + public static servletProperties respond(final httpRequestHeader requestHeader, final serverObjects post, final serverSwitch env) { + final servletProperties prop = new servletProperties(); + return prop; + } +} diff --git a/htroot/api/trail_p.java b/htroot/api/trail_p.java new file mode 100644 index 000000000..f56f880a3 --- /dev/null +++ b/htroot/api/trail_p.java @@ -0,0 +1,47 @@ +// trail_p.java +// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany +// first published 06.02.2009 on http://www.yacy.net +// +// This is a part of YaCy. +// The Software shall be used for Good, not Evil. +// +// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $ +// $LastChangedRevision: 1986 $ +// $LastChangedBy: orbiter $ +// +// LICENSE +// +// 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 de.anomic.http.httpRequestHeader; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; + +public class trail_p { + + public static serverObjects respond(final httpRequestHeader header, final serverObjects post, final serverSwitch env) { + final plasmaSwitchboard sb = (plasmaSwitchboard) env; + final serverObjects prop = new serverObjects(); + + int c = 0; + for (String t: sb.trail) { + prop.put("trails_" + c++ + "_trail", t); // don't put in putHTML or putXML in, this is wrong! + } + prop.put("trails", c); + return prop; + } + +} diff --git a/htroot/api/trail_p.json b/htroot/api/trail_p.json new file mode 100644 index 000000000..fbb1d9c32 --- /dev/null +++ b/htroot/api/trail_p.json @@ -0,0 +1,8 @@ +{ + "trails": [ +#{trails}# +#[trail]#, +#{/trails}# +{} + ] +} \ No newline at end of file diff --git a/htroot/cytag.java b/htroot/cytag.java new file mode 100644 index 000000000..ce382b8b4 --- /dev/null +++ b/htroot/cytag.java @@ -0,0 +1,89 @@ +// cytag.java +// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany +// first published 06.02.2009 on http://www.yacy.net +// +// This is a part of YaCy. +// The Software shall be used for Good, not Evil. +// +// $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $ +// $LastChangedRevision: 1986 $ +// $LastChangedBy: orbiter $ +// +// LICENSE +// +// 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.awt.Image; +import java.io.File; +import java.io.IOException; +import java.util.Date; + +import de.anomic.htmlFilter.htmlFilterCharacterCoding; +import de.anomic.http.httpRequestHeader; +import de.anomic.kelondro.order.DateFormatter; +import de.anomic.kelondro.util.FileUtils; +import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverObjects; +import de.anomic.server.serverSwitch; +import de.anomic.ymage.ymageImageParser; + +public class cytag { + + public static Image respond(final httpRequestHeader header, final serverObjects post, final serverSwitch env) { + + final plasmaSwitchboard sb = (plasmaSwitchboard)env; + + // harvest request information + StringBuilder connect = new StringBuilder(); + connect.append('{'); + addJSON(connect, "time", DateFormatter.formatShortMilliSecond(new Date())); + addJSON(connect, "trail", header.get("Referer", "")); + addJSON(connect, "nick", (post == null) ? "" : post.get("nick", "")); + addJSON(connect, "tag", (post == null) ? "" : post.get("tag", "")); + addJSON(connect, "icon", (post == null) ? "" : post.get("icon", "")); + addJSON(connect, "ip", header.get("CLIENTIP", "")); + addJSON(connect, "agent", header.get("User-Agent", "")); + connect.append('}'); + + sb.trail.add(connect.toString()); + //Log.logInfo("CYTAG", "catched trail - " + connect.toString()); + + String defaultimage = "redpillmini.png"; + if (post != null && post.get("icon", "").equals("invisible")) defaultimage = "invisible.png"; + File iconfile = new File(sb.getRootPath(), "/htroot/env/grafics/" + defaultimage); + + byte[] imgb = null; + try { + imgb = FileUtils.read(iconfile); + } catch (final IOException e) { + return null; + } + if (imgb == null) return null; + + // read image + final Image image = ymageImageParser.parse("cytag.png", imgb); + + return image; + } + + private static final void addJSON(StringBuilder sb, String k, String v) { + if (sb.length() > 2) sb.append(','); + sb.append('\"'); + sb.append(k); + sb.append("\":\""); + sb.append(htmlFilterCharacterCoding.unicode2xml(v, true)); + sb.append('\"'); + } +} diff --git a/htroot/env/grafics/invisible.png b/htroot/env/grafics/invisible.png new file mode 100644 index 0000000000000000000000000000000000000000..91433addffc4acb96fcc3fc396e0e7842fea5174 GIT binary patch literal 143 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)gaEa{HEjtmSN`?>!lvI6zopr0KXL@y8r+H literal 0 HcmV?d00001 diff --git a/htroot/env/grafics/mcemailh.gif b/htroot/env/grafics/mcemailh.gif deleted file mode 100644 index 7f63a4c4103219e955455b02caf084fe67474f3a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 423 zcmV;Y0a*S=Nk%w1VP*gd0P_Gb|NsB)?(W^)-OS9)ySuxps;ZfpnTUvpcXxMYW@c4Y zRYXKYGcz+HA|eqH5dZ)HA^8LW00000EC2ui0A>IR000F45XecZrRQlzuK!@AAfaU> zLaBbv(*eapuC(_!HK4e8-8caX;W6kLU$q2JrF<*^N(E*2I7}Xbfks0}SS787VS+$B z8py?Fk}#N`QSw)(nNt|D#uEQ1Tr@v`El&W0Em8?j4NnF*ZW0;@cvcz?YB+^Xmyl;I zolcMpU`~e>fLk3J3N2%%qFN0ATA~0CQUD7HxTzfqQVVuaRkaO4JE^(=W|XvNq0a`k z61k?ydZ{xHv=pEM-P({d6Tr0w(F%=0bX$~!N~wM@!=SZ<;I*PL;ucHqwOcp%iSjn^ zo(u_I01OdOz=5s>3Q|C_5`!5+9tQzru!!$j$7nND5_0>ZCRHl}NUjuI$?1TaTV~?P z@^uA4!+Es)MQW15V6&esUv~VLhzl_TY6x+A;*BZ2f6^wz0C+%MCK=A?DJeq0(-L}M R?J3=I>*=YlswhMN06S#~tZx7S diff --git a/htroot/env/grafics/redpillmini.png b/htroot/env/grafics/redpillmini.png new file mode 100644 index 0000000000000000000000000000000000000000..7cb8bf2f508ba7281e69594be2384b997a1e1780 GIT binary patch literal 482 zcmeAS@N?(olHy`uVBq!ia0vp^LO{&P!3HGl@7M4HDVB6cUq=Rpjs4tz5?O(Kwj^(N z7l!{JxM1({$spwg9+AZi4BWyX%*Zfnjs#GUy~NYkmHj3Y8;1qYwh}LpI>{2(h!W@g z+}zZ>5(ej@)Wnk16ovB4k_-iRPv3y>Mm}){21YAS7sn8d^Su-IdNBtIw4Oh+cjxY# zM_bmgZM<~M%X*@23y0at8W!*9Zjq)Nw|_`Ac^tT8zCoy#+4Ya3OW^f2hK1knZ45AE zjQtcEJlE2mh2iZ4v!3)aACaF&c$%0UelUM6?%>#D;`)DU@zmyLFBP6xTqxSJaY`wxKmW;f*Hp4Eo)KA8!TIf}B-23+4u<`9oj0$ko!ho8`j$o> zo7LpmU(?jKKYx&9oMteq#q>i=&n9+Pcj2Y?O6~@h_8e6ZPFutzF85c>IgK;+`NLm& z&0%L^*Q+?LC`#YL6zFIsxlaE)>$dCco7==52A{qZz_n!Rj`!Q#UrPBgFOs;XnW4RB z{=PuvkFrzu|GRjikLAT4V diff --git a/source/de/anomic/http/httpHeader.java b/source/de/anomic/http/httpHeader.java index 760801674..bf32cb33a 100644 --- a/source/de/anomic/http/httpHeader.java +++ b/source/de/anomic/http/httpHeader.java @@ -277,14 +277,14 @@ public class httpHeader extends TreeMap implements Map disallowZippedContentEncoding = new HashSet(Arrays.asList(new String[]{ - ".gz", ".tgz", ".jpg", ".jpeg", ".gif", ".zip", ".rar", ".bz2", ".lha", ".jar", ".rpm", ".arc", ".arj", ".wmv", ".png", ".ico", ".bmp" + ".gz", ".tgz", ".jpg", ".jpeg", ".png", ".mp3", ".mov", ".avi", ".gif", ".zip", ".rar", ".bz2", ".lha", ".jar", ".rpm", ".arc", ".arj", ".wmv", ".ico", ".bmp" })); // static objects diff --git a/source/de/anomic/http/httpdFileHandler.java b/source/de/anomic/http/httpdFileHandler.java index de7ddc91c..5c5cd74f7 100644 --- a/source/de/anomic/http/httpdFileHandler.java +++ b/source/de/anomic/http/httpdFileHandler.java @@ -787,6 +787,7 @@ public final class httpdFileHandler { templatePatterns.put(servletProperties.PEER_STAT_VERSION, switchboard.getConfig("version", "")); templatePatterns.put(servletProperties.PEER_STAT_UPTIME, ((System.currentTimeMillis() - serverCore.startupTime) / 1000) / 60); // uptime in minutes templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTNAME, switchboard.getConfig("peerName", "anomic")); + templatePatterns.putHTML(servletProperties.PEER_STAT_CLIENTID, ((plasmaSwitchboard) switchboard).webIndex.seedDB.myID()); templatePatterns.put(servletProperties.PEER_STAT_MYTIME, DateFormatter.formatShortSecond()); //System.out.println("respond props: " + ((tp == null) ? "null" : tp.toString())); // debug } catch (final InvocationTargetException e) { @@ -972,8 +973,8 @@ public final class httpdFileHandler { // write the file to the client targetDate = new Date(targetFile.lastModified()); final long contentLength = (zipContent)?-1:targetFile.length()-rangeStartOffset; - final String contentEncoding = (zipContent)?"gzip":null; - final String transferEncoding = (!httpVersion.equals(httpHeader.HTTP_VERSION_1_1))?null:(zipContent)?"chunked":null; + final String contentEncoding = (zipContent) ? "gzip" : null; + final String transferEncoding = (httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && zipContent) ? "chunked" : null; if (!httpVersion.equals(httpHeader.HTTP_VERSION_1_1) && zipContent) forceConnectionClose(conProp); httpd.sendRespondHeader(conProp, out, httpVersion, statusCode, null, mimeType, contentLength, targetDate, null, header, contentEncoding, transferEncoding, nocache); @@ -1026,7 +1027,7 @@ public final class httpdFileHandler { } catch (final Exception e) { try { // doing some errorhandling ... - e.printStackTrace(); + //e.printStackTrace(); int httpStatusCode = 400; final String httpStatusText = null; final StringBuilder errorMessage = new StringBuilder(2000); diff --git a/source/de/anomic/kelondro/order/DateFormatter.java b/source/de/anomic/kelondro/order/DateFormatter.java index a221ee771..9703f0627 100644 --- a/source/de/anomic/kelondro/order/DateFormatter.java +++ b/source/de/anomic/kelondro/order/DateFormatter.java @@ -323,6 +323,11 @@ public final class DateFormatter { return format(FORMAT_SHORT_SECOND, date); } + public static String formatShortMilliSecond(final Date date) { + return format(FORMAT_SHORT_MILSEC, date); + } + + /** * Identical to {@link #formatShortDay(Date, TimeZone)}, but for short second format. */ diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.java index 21d92f57a..bed911d32 100644 --- a/source/de/anomic/plasma/plasmaSwitchboard.java +++ b/source/de/anomic/plasma/plasmaSwitchboard.java @@ -236,6 +236,7 @@ public final class plasmaSwitchboard extends serverAbstractSwitch networkWhitelist, networkBlacklist; + public List trail; public serverProcessor indexingDocumentProcessor; public serverProcessor indexingCondensementProcessor; @@ -270,6 +271,8 @@ public final class plasmaSwitchboard extends serverAbstractSwitch(); + // load values from configs this.plasmaPath = getConfigPath(plasmaSwitchboardConstants.PLASMA_PATH, plasmaSwitchboardConstants.PLASMA_PATH_DEFAULT); this.log.logConfig("Plasma DB Path: " + this.plasmaPath.toString()); diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java index f1a0f50db..97aa21365 100644 --- a/source/de/anomic/server/serverCore.java +++ b/source/de/anomic/server/serverCore.java @@ -645,9 +645,6 @@ public final class serverCore extends serverAbstractBusyThread implements server this.in.close(); this.out.close(); - // sleep for a while - //try {Thread.sleep(500);} catch (final InterruptedException e) {} - // close everything this.controlSocket.close(); diff --git a/source/de/anomic/server/servletProperties.java b/source/de/anomic/server/servletProperties.java index 62ea97f5d..3fdbb8d01 100644 --- a/source/de/anomic/server/servletProperties.java +++ b/source/de/anomic/server/servletProperties.java @@ -34,6 +34,7 @@ public class servletProperties extends serverObjects { public static final String PEER_STAT_UPTIME = "uptime"; public static final String PEER_STAT_MYTIME = "mytime"; public static final String PEER_STAT_CLIENTNAME = "clientname"; + public static final String PEER_STAT_CLIENTID = "clientid"; private String prefix="";