Package de.anomic.server

Examples of de.anomic.server.serverObjects


   
  static serverObjects prop;
 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
    final Switchboard sb = (Switchboard) env;
    prop = new serverObjects();       
        final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);

       
View Full Code Here


 
  private static Switchboard sb = null;
 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
       
        final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
       
        if(isAdmin || isAuthUser) {      
          final String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
            byte[] urlHash = null;
            try {
            if(post.containsKey(YMarkEntry.BOOKMARKS_ID)) {
              urlHash = post.get(YMarkEntry.BOOKMARKS_ID).getBytes();
            } else if(post.containsKey(YMarkEntry.BOOKMARK.URL.key())) {
          urlHash = YMarkUtil.getBookmarkId(post.get(YMarkEntry.BOOKMARK.URL.key()));
            } else {
              prop.put("result", "0");
              return prop;
            }
            sb.tables.bookmarks.deleteBookmark(bmk_user, urlHash);
            prop.put("result", "1");
      } catch (IOException e) {
        Log.logException(e);
      } catch (RowSpaceExceededException e) {
        Log.logException(e);
      }
        } else {
          prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG);
        }      
        // return rewrite properties
        return prop;
  }
View Full Code Here

  private static Switchboard sb = null;
  private static serverObjects prop = null;
 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        sb = (Switchboard) env;
        prop = new serverObjects();
       
        final UserDB.Entry user = sb.userDB.getUser(header);
        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
       
View Full Code Here

import de.anomic.server.serverSwitch;

public class IndexImportOAIPMHList_p {

    public static serverObjects respond(final RequestHeader header, serverObjects post, final serverSwitch env) {
        final serverObjects prop = new serverObjects();
        final Switchboard sb = (Switchboard) env;

        prop.put("refresh", 0);
        prop.put("import", 0);
        prop.put("source", 0);
       
        if (post != null && post.containsKey("source")) {
            final Set<String> oaiRoots = OAIListFriendsLoader.getListFriends(sb.loader).keySet();
           
            boolean dark = false;
            int count = 0;
            for (final String root: oaiRoots) {
                prop.put("source_table_" + count + "_dark", (dark) ? "1" : "0");
                prop.put("source_table_" + count + "_count", count);
                prop.put("source_table_" + count + "_source", CharacterCoding.unicode2html(root, true));
                prop.put("source_table_" + count + "_loadurl", "<a href=\"/IndexImportOAIPMH_p.html?urlstart=" + CharacterCoding.unicode2html(root, true) + "\" target=\"_top\">" + CharacterCoding.unicode2html(root, true) + "</a>");
                dark = !dark;
                count++;
            }
            prop.put("source_table", count);
            prop.put("source_num", count);
            prop.put("source", 1);
        }
       
        if (post != null && post.containsKey("import")) {
            final List<OAIPMHImporter> jobs = new ArrayList<OAIPMHImporter>();
            for (OAIPMHImporter job: OAIPMHImporter.runningJobs.keySet()) jobs.add(job);
            for (OAIPMHImporter job: OAIPMHImporter.startedJobs.keySet()) jobs.add(job);
            for (OAIPMHImporter job: OAIPMHImporter.finishedJobs.keySet()) jobs.add(job);
           
            boolean dark = false;
            int count = 0;
            for (final OAIPMHImporter job: jobs) {
                prop.put("import_table_" + count + "_dark", (dark) ? "1" : "0");
                prop.put("import_table_" + count + "_thread", (job.isAlive()) ? "<img src=\"/env/grafics/loading.gif\" alt=\"running\" />" : "finished");
                prop.putXML("import_table_" + count + "_source", job.source());
                prop.put("import_table_" + count + "_chunkCount", job.chunkCount());
                prop.put("import_table_" + count + "_recordsCount", job.count());
                prop.put("import_table_" + count + "_completeListSize", job.getCompleteListSize());
                prop.put("import_table_" + count + "_speed", job.speed());
                dark = !dark;
                count++;
            }
            prop.put("import_table", count);
            prop.put("import", 1);
            prop.put("refresh", 1);
        }
        return prop;
    }
View Full Code Here

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
       
        // return variable that accumulates replacements
        final serverObjects prop = new serverObjects();

        // update seed info
        sb.updateMySeed();

        prop.putHTML("peername", sb.peers.mySeed().getName());
        prop.putHTML("peerdomain", sb.peers.mySeed().getName().toLowerCase());
        prop.putHTML("peeraddress", sb.peers.mySeed().getPublicAddress());
        prop.put("hostname", env.myPublicIP());
        prop.put("hostip", Domains.dnsResolve(env.myPublicIP()).getHostAddress());      
        prop.put("port", serverCore.getPortNr(env.getConfig("port","8090")));
        prop.put("clientip", header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, ""));

        final String peertype = (sb.peers.mySeed() == null) ? yacySeed.PEERTYPE_JUNIOR : sb.peers.mySeed().get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_VIRGIN);
        final boolean senior = (peertype.equals(yacySeed.PEERTYPE_SENIOR)) || (peertype.equals(yacySeed.PEERTYPE_PRINCIPAL));
        if (senior) { prop.put("couldcan", "can"); } else { prop.put("couldcan", "could"); }
        if (senior) { prop.put("seniorinfo", "This peer runs in senior mode which means that your peer can be accessed using the addresses shown above."); } else { prop.putHTML("seniorinfo", "<b>Nobody can access your peer from the outside of your intranet. You must open your firewall and/or set a 'virtual server' in the settings of your router to enable access to the addresses as shown below.</b>"); }
        final File wwwpath = env.getDataPath("htDocsPath", "DATA/HTDOCS");
        prop.putHTML("wwwpath", wwwpath.isAbsolute() ? wwwpath.getAbsolutePath() : "<application_root_path>/" + env.getConfig("htDocsPath", "DATA/HTDOCS"));

        // return rewrite properties
        return prop;
    }
View Full Code Here

        final Switchboard sb = (Switchboard) env;

        final String blackListName = post.get("listname", "");

        // return variable that accumulates replacements
        final serverObjects prop = new serverObjects();
        if ((post == null) || (env == null)) return prop;
        if (!yacyNetwork.authentifyRequest(post, env)) return prop;
       
        final String col = post.get("col", "");
        final File listsPath = env.getDataPath(SwitchboardConstants.LISTS_PATH, SwitchboardConstants.LISTS_PATH_DEFAULT);
       
        String otherPeerName = null;
        if (post.containsKey("iam")) {
            final yacySeed bla = sb.peers.get(post.get("iam", ""));
            if (bla != null) otherPeerName = bla.getName();
        }
        if (otherPeerName == null) otherPeerName = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP);
       
        if ((sb.isRobinsonMode()) && (!sb.isInMyCluster(otherPeerName))) {
            // if we are a robinson cluster, answer only if this client is known by our network definition
            return null;
        }
       
        if (col.equals("black")) {
            final StringBuilder out = new StringBuilder(10000);

            final String filenames=env.getConfig("BlackLists.Shared", "");
            final String[] filenamesarray = filenames.split(",");

            if (filenamesarray.length > 0){
                for (int i = 0;i < filenamesarray.length; i++) {
                    if (blackListName.equals("") || filenamesarray[i].equals(blackListName)) {
                        final String filename = filenamesarray[i];
                        final File fileObj = new File(listsPath,filename);
                        out.append(FileUtils.getListString(fileObj, false)).append(serverCore.CRLF_STRING);
                    }
                }
            }

            prop.put("list",out.toString());
        } else {
            prop.put("list","");
        }
       
        return prop;
    }
View Full Code Here

   
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
    
        // return variable that accumulates replacements
        final serverObjects prop = new serverObjects();
        prop.setLocalized(!(header.get(HeaderFramework.CONNECTION_PROP_PATH)).endsWith(".xml"));
        int page = 0;
        if (post != null) {
            page = post.getInt("page", 0);
        }
        prop.put("page", page);
    
        final int maxCount = 1000;
        boolean dark = true;
        if (page == 0) {
            final Iterator<String> i = sb.accessHosts();
            String host;
            int entCount = 0;
            try {
                while ((entCount < maxCount) && (i.hasNext())) {
                    host = i.next();
                    prop.putHTML("page_list_" + entCount + "_host", host);
                    prop.putNum("page_list_" + entCount + "_countSecond", sb.latestAccessCount(host, 1000));
                    prop.putNum("page_list_" + entCount + "_countMinute", sb.latestAccessCount(host, 1000 * 60));
                    prop.putNum("page_list_" + entCount + "_count10Minutes", sb.latestAccessCount(host, 1000 * 60 * 10));
                    prop.putNum("page_list_" + entCount + "_countHour", sb.latestAccessCount(host, 1000 * 60 * 60));
                    entCount++;
                }
            } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this
            prop.put("page_list", entCount);
            prop.put("page_num", entCount);
           
            entCount = 0;
            try {
                for (final Map.Entry<String, Integer> bfe: serverCore.bfHost.entrySet()) {
                    prop.putHTML("page_bflist_" + entCount + "_host", bfe.getKey());
                    prop.putNum("page_bflist_" + entCount + "_countSecond", bfe.getValue());
                    entCount++;
                }
            } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this
            prop.put("page_bflist", entCount);
        } else if (page == 1) {
            String host = (post == null) ? "" : post.get("host", "");
            int entCount = 0;
            Collection<Track> access;
            Track entry;
            if (host.length() > 0) {
                access = sb.accessTrack(host);
                if (access != null) {
                    try {
                        final Iterator<Track> ii = listclone(access).iterator();
                        while (ii.hasNext()) {
                            entry = ii.next();
                            prop.putHTML("page_list_" + entCount + "_host", host);
                            prop.put("page_list_" + entCount + "_date", SimpleFormatter.format(new Date(entry.getTime())));
                            prop.putHTML("page_list_" + entCount + "_path", entry.getPath());
                            entCount++;
                        }
                    } catch (final ConcurrentModificationException e) {} // we don't want to synchronize this
                }
            } else {
                try {
                    final Iterator<String> i = sb.accessHosts();
                    while ((entCount < maxCount) && (i.hasNext())) {
                        host = i.next();
                        access = sb.accessTrack(host);
                        final Iterator<Track> ii = listclone(access).iterator();
                        while (ii.hasNext()) {
                                entry = ii.next();
                                prop.putHTML("page_list_" + entCount + "_host", host);
                                prop.put("page_list_" + entCount + "_date", SimpleFormatter.format(new Date(entry.getTime())));
                                prop.putHTML("page_list_" + entCount + "_path", entry.getPath());
                                entCount++;
                        }
                    }
                } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this
            }
            prop.put("page_list", entCount);
            prop.put("page_num", entCount);
        } else if ((page == 2) || (page == 4)) {
            final Iterator<QueryParams> ai = (page == 2) ? AccessTracker.get(AccessTracker.Location.local) : AccessTracker.get(AccessTracker.Location.remote);
            QueryParams query;
            long qcountSum = 0;
            long rcountSum = 0;
            long tcountSum = 0;
            long rcount = 0;
            long utimeSum = 0;
            long stimeSum = 0;
            long rtimeSum = 0;
            long utimeSum1 = 0;
            long stimeSum1 = 0;
            long rtimeSum1 = 0;
            int m = 0;
           
            while (ai.hasNext()) {
                try {
                    query = ai.next();
                } catch (ConcurrentModificationException e) {
                    break;
                }
                // put values in template
                prop.put("page_list_" + m + "_dark", ((dark) ? 1 : 0) );
                dark =! dark;
                prop.putHTML("page_list_" + m + "_host", query.host);
                prop.put("page_list_" + m + "_date", SimpleFormatter.format(new Date(query.time.longValue())));
                prop.put("page_list_" + m + "_timestamp", query.time.longValue());
                if (page == 2) {
                    // local search
                    prop.putNum("page_list_" + m + "_offset", query.offset);
                    prop.putHTML("page_list_" + m + "_querystring", query.queryString);
                } else {
                    // remote search
                    prop.putHTML("page_list_" + m + "_peername", (query.remotepeer == null) ? "<unknown>" : query.remotepeer.getName());
                    prop.put("page_list_" + m + "_queryhashes", QueryParams.anonymizedQueryHashes(query.queryHashes));
                }
                prop.putNum("page_list_" + m + "_querycount", query.itemsPerPage);
                prop.putNum("page_list_" + m + "_transmitcount", query.transmitcount);
                prop.putNum("page_list_" + m + "_resultcount", query.resultcount);
                prop.putNum("page_list_" + m + "_urltime", query.urlretrievaltime);
                prop.putNum("page_list_" + m + "_snippettime", query.snippetcomputationtime);
                prop.putNum("page_list_" + m + "_resulttime", query.searchtime);
                prop.putHTML("page_list_" + m + "_userAgent", query.userAgent);
                qcountSum += query.itemsPerPage;
                rcountSum += query.resultcount;
                tcountSum += query.transmitcount;
                utimeSum += query.urlretrievaltime;
                stimeSum += query.snippetcomputationtime;
                rtimeSum += query.searchtime;
                if (query.resultcount > 0){
                  rcount++;
                    utimeSum1 += query.urlretrievaltime;
                    stimeSum1 += query.snippetcomputationtime;
                    rtimeSum1 += query.searchtime;
                }
                m++;
            }
            prop.put("page_list", m);
            prop.put("page_num", m);
            prop.put("page_resultcount", rcount);
           
            // Put -1 instead of NaN as result for empty search list and return the safe HTML blank char for table output
            if (m == 0) {
                m = -1;
                // return empty values to not break the table view
                prop.put("page_list", 1);
                prop.put("page_list_0_dark", 1 );
                prop.put("page_list_0_host", "");
                prop.put("page_list_0_date", "");
                prop.put("page_list_0_timestamp", "");
                if (page == 2) {
                    // local search
                    prop.putNum("page_list_0_offset", "");
                    prop.put("page_list_0_querystring", "");
                } else {
                    // remote search
                    prop.put("page_list_0_peername", "");
                    prop.put("page_list_0_queryhashes", "");
                }
                prop.putNum("page_list_0_querycount", "");
                prop.putNum("page_list_0_transmitcount", "");
                prop.putNum("page_list_0_resultcount", "");
                prop.putNum("page_list_0_urltime", "");
                prop.putNum("page_list_0_snippettime", "");
                prop.putNum("page_list_0_resulttime", "");
                prop.put("page_list_0_userAgent", "");
            }
            if (rcount == 0) rcount = -1;
            prop.putNum("page_querycount_avg", (double) qcountSum / m);
            prop.putNum("page_resultcount_avg", (double) rcountSum / m);
            prop.putNum("page_urltime_avg", (double) utimeSum / m);
            prop.putNum("page_snippettime_avg", (double) stimeSum / m);
            prop.putNum("page_resulttime_avg", (double) rtimeSum / m);
            prop.putNum("page_transmitcount_avg", (double) tcountSum / rcount);
            prop.putNum("page_resultcount_avg1", (double) rcountSum / rcount);
            prop.putNum("page_urltime_avg1", (double) utimeSum1 / rcount);
            prop.putNum("page_snippettime_avg1", (double) stimeSum1 / rcount);
            prop.putNum("page_resulttime_avg1", (double) rtimeSum1 / rcount);
            prop.putNum("page_total", (page == 2) ? AccessTracker.size(AccessTracker.Location.local) : AccessTracker.size(AccessTracker.Location.remote));
        } else if ((page == 3) || (page == 5)) {
            final Iterator<Entry<String, TreeSet<Long>>> i = (page == 3) ? sb.localSearchTracker.entrySet().iterator() : sb.remoteSearchTracker.entrySet().iterator();
            String host;
            TreeSet<Long> handles;
            int m = 0;
            int qphSum = 0;
            Map.Entry<String, TreeSet<Long>> entry;
            try {
            while ((m < maxCount) && (i.hasNext())) {
                entry = i.next();
                host = entry.getKey();
                handles = entry.getValue();
               
                int dateCount = 0;
                final Iterator<Long> ii = handles.iterator();
                while (ii.hasNext()) {
                    final Long timestamp = ii.next();
                    prop.put("page_list_" + m + "_dates_" + dateCount + "_date", SimpleFormatter.format(new Date(timestamp.longValue())));
                    prop.put("page_list_" + m + "_dates_" + dateCount + "_timestamp", timestamp.toString());
                    dateCount++;
                }
                prop.put("page_list_" + m + "_dates", dateCount);
                final int qph = handles.tailSet(Long.valueOf(System.currentTimeMillis() - 1000 * 60 * 60)).size();
                qphSum += qph;
                prop.put("page_list_" + m + "_qph", qph);
               
                prop.put("page_list_" + m + "_dark", ((dark) ? 1 : 0) ); dark =! dark;
                prop.putHTML("page_list_" + m + "_host", host);
                if (page == 5) {
                    final yacySeed remotepeer = sb.peers.lookupByIP(Domains.dnsResolve(host), true, true, true);
                    prop.putHTML("page_list_" + m + "_peername", (remotepeer == null) ? "UNKNOWN" : remotepeer.getName());
                }
                prop.putNum("page_list_" + m + "_count", handles.size());

                // next
                m++;
            }
            } catch (final ConcurrentModificationException e) {} // we dont want to synchronize this
            // return empty values to not break the table view if no results can be listed
            if (m==0) {               
                prop.put("page_list", 1);
                prop.put("page_list_0_dates_0_date", "");
                prop.put("page_list_0_dates", 1);
                prop.putNum("page_list_0_qph", "");
                prop.put("page_list_0_dark", 1 );
                prop.put("page_list_0_peername", "");
                prop.put("page_list_0_host", "");
                prop.putNum("page_list_0_count", "");
            } else {
                prop.put("page_list", m);
            }
            prop.putNum("page_num", m);
            prop.putNum("page_total", (page == 3) ? AccessTracker.size(AccessTracker.Location.local) : AccessTracker.size(AccessTracker.Location.remote));
            prop.putNum("page_qph_sum", qphSum);
        }
        // return rewrite properties
        return prop;
    }
View Full Code Here

public class addTag_p {
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {

        final Switchboard switchboard = (Switchboard) env;
        final serverObjects prop = new serverObjects();
        boolean isAdmin = false;
        isAdmin = switchboard.verifyAuthentication(header, true);
       
        prop.put("result", "0");//error
        //rename tags
        if(post != null && isAdmin) {
          if (post.containsKey("selectTag") && post.containsKey("addTag")) {
                switchboard.bookmarksDB.addTag(post.get("selectTag"), post.get("addTag"));
                prop.put("result", "1");//success        
          } else if (post.containsKey("urlhash") && post.containsKey("addTag")) {
                final Bookmark bm = switchboard.bookmarksDB.getBookmark(post.get("urlhash"));
            bm.addTag(post.get("addTag"));
                prop.put("result", "1");//success
          }
        }      
        // return rewrite properties
        return prop;
    }
View Full Code Here

public class editTag_p {
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
       
        final Switchboard switchboard = (Switchboard) env;           
        final serverObjects prop = new serverObjects();
        boolean isAdmin = false;
        isAdmin = switchboard.verifyAuthentication(header, true);
       
        prop.put("result", "0");//error
        //rename tags
        if(post != null && isAdmin && post.containsKey("old") && post.containsKey("new")){
            if(switchboard.bookmarksDB.renameTag(post.get("old"), post.get("new")))
                prop.put("result", "1");//success
        }
        // return rewrite properties
        return prop;
    }
View Full Code Here

 
  public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        // return variable that accumulates replacements
        final Switchboard switchboard = (Switchboard) env;
        final boolean isAdmin = switchboard.verifyAuthentication(header, true);
        final serverObjects prop = new serverObjects();
        Iterator<BookmarksDB.Tag> it = null;
        String tagName = "";
        int top = SHOW_ALL;
        int comp = SORT_ALPHA;
       
       
      if (post != null) {
            if (!isAdmin) {
                // force authentication if desired
                if(post.containsKey("login")){
                    prop.put("AUTHENTICATE","admin log-in");
                }
            }

            if (post.containsKey("top")) {
                top = post.getInt("top", SHOW_ALL);
            }
            if (post.containsKey("sort")) {
                if ("size".equals(post.get("sort"))) {
                    comp = SORT_SIZE;
                }
            }
        }

      if (post != null && post.containsKey("tag")) {
          tagName=post.get("tag");         
          if (!tagName.isEmpty()) {
              it = switchboard.bookmarksDB.getTagIterator(tagName, isAdmin, comp, top);           
          }
      } else {
          it = switchboard.bookmarksDB.getTagIterator(isAdmin, comp, top);
      }        

        // Iterator<bookmarksDB.Tag> it = switchboard.bookmarksDB.getTagIterator(isAdmin);
       
        int count = 0;
        if (it != null) {
            BookmarksDB.Tag tag;
            while (it.hasNext()) {
                tag = it.next();
                if(!tag.getTagName().startsWith("/")) {        // ignore folder tags
                    prop.putXML("tags_" + count + "_name", tag.getTagName());
                    prop.put("tags_" + count + "_count", tag.size());
                    count++;
                }
            }
        }
        prop.put("tags", count);

        // return rewrite properties
        return prop;
    }
View Full Code Here

TOP

Related Classes of de.anomic.server.serverObjects

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.