Package de.anomic.server

Examples of de.anomic.server.serverObjects


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

        // server sessions
        // get the serverCore thread
        final WorkflowThread httpd = sb.getThread("10_httpd");
       
        // determines if name lookup should be done or not
        final boolean doNameLookup;
        if (post != null) { 
            doNameLookup = (post.containsKey("nameLookup") && post.getBoolean("nameLookup", true));
            if (post.containsKey("closeServerSession")) {
                final String sessionName = post.get("closeServerSession", null);
                sb.closeSessions("10_httpd", sessionName);
                prop.put("LOCATION","");
                return prop;               
            }
        } else {
            doNameLookup = false;
        }
       
        // waiting for all threads to finish
        int idx = 0, numActiveRunning = 0, numActivePending = 0;
        boolean dark = true;
        for (final Session s: ((serverCore) httpd).getJobList()) {
            if (!s.isAlive()) continue;
           
            // get the session runtime
            final long sessionTime = s.getTime();
           
            // get the request command line
            String commandLine = s.getCommandLine();
            final boolean blockingRequest = (commandLine == null);
            final int commandCount = s.getCommandCount();
           
            // get the source ip address and port
            final InetAddress userAddress = s.getUserAddress();
            final int userPort = s.getUserPort();
            if (userAddress == null) {
                continue;
            }
           
            String prot = "http"; // only httpd sessions listed
           
            // determining if the source is a yacy host
            yacySeed seed = null;
            if (doNameLookup) {
                seed = sb.peers.lookupByIP(userAddress,true,false,false);
                if (seed != null && (seed.hash.equals(sb.peers.mySeed().hash)) &&
                        (!seed.get(yacySeed.PORT,"").equals(Integer.toString(userPort)))) {
                    seed = null;
                }
            }
           
            prop.put("list_" + idx + "_dark", dark ? "1" : "0");
            dark = !dark;
            try {
                prop.put("list_" + idx + "_serverSessionID",URLEncoder.encode(s.getName(),"UTF8"));
            } catch (final UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                Log.logException(e);
            }
            prop.putHTML("list_" + idx + "_sessionName", s.getName());
            prop.put("list_" + idx + "_proto", prot);
            if (sessionTime > 1000*60) {
                prop.put("list_" + idx + "_ms", "0");
                prop.put("list_" + idx + "_ms_duration",yacyPeerActions.formatInterval(sessionTime));
            } else {
                prop.put("list_" + idx + "_ms", "1");
                prop.putNum("list_" + idx + "_ms_duration", sessionTime);
            }
            prop.putHTML("list_" + idx + "_source",(seed!=null)?seed.getName()+".yacy":userAddress.getHostAddress()+":"+userPort);
            prop.putHTML("list_" + idx + "_dest", "-");
            if (blockingRequest) {
                prop.put("list_" + idx + "_running", "0");
                prop.putNum("list_" + idx + "_running_reqNr", commandCount+1);
                numActivePending++;
            } else {
                prop.put("list_" + idx + "_running", "1");
                prop.put("list_" + idx + "_running_command", commandLine==null ? "" :commandLine);
                numActiveRunning++;
            }
            prop.putNum("list_" + idx + "_used", commandCount);
            idx++;
        }    
        prop.put("list", idx);
       
        prop.putNum("numMax", ((serverCore)httpd).getMaxSessionCount());
        prop.putNum("numActiveRunning", numActiveRunning);
        prop.putNum("numActivePending", numActivePending);
       
        // client sessions
        final Set<ConnectionInfo> allConnections = ConnectionInfo.getAllConnections();
        // TODO sorting
//        Arrays.sort(a, httpc.connectionTimeComparatorInstance);
        int c = 0;
        synchronized (allConnections) {
        for (final ConnectionInfo conInfo: allConnections) {
            prop.put("clientList_" + c + "_clientProtocol", conInfo.getProtocol());
            prop.putNum("clientList_" + c + "_clientLifetime", conInfo.getLifetime());
            prop.putNum("clientList_" + c + "_clientUpbytes", conInfo.getUpbytes());
            prop.put("clientList_" + c + "_clientTargetHost", conInfo.getTargetHost());
            prop.putHTML("clientList_" + c + "_clientCommand", conInfo.getCommand());
            prop.put("clientList_" + c + "_clientID", conInfo.getID());
            c++;
        }
        }
        prop.put("clientList", c);
        prop.put("clientActive", ConnectionInfo.getCount());
       
        // return rewrite values for templates
        return prop;
    }
View Full Code Here


    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch ss) {
        if (post == null || ss == null) { return null; }

        // return variable that accumulates replacements
        final Switchboard sb = (Switchboard) ss;
        final serverObjects prop = new serverObjects();

        prop.put("magic", yacyCore.magic);
       
        if ((post == null) || (ss == null) || !yacyNetwork.authentifyRequest(post, ss)) {
            prop.put("response", "-1"); // request rejected
            return prop;
        }
       
        if ((sb.isRobinsonMode()) &&
            (!sb.isPublicRobinson()) &&
            (!sb.isInMyCluster(header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP)))) {
          // if we are a robinson cluster, answer only if we are public robinson peers,
          // or we are a private cluster and the requester is in our cluster.
            // if we don't answer, the remote peer will recognize us as junior peer,
            // what would mean that our peer ping does not work
          prop.put("response", "-1"); // request rejected
            return prop;
        }
                 
//      System.out.println("YACYQUERY: RECEIVED POST = " + ((post == null) ? "NULL" : post.toString()));

//      final String iam    = post.get("iam", "");    // complete seed of the requesting peer
        final String youare = post.get("youare", ""); // seed hash of the target peer, used for testing network stability
//      final String key    = post.get("key", "");    // transmission key for response
        final String obj    = post.get("object", ""); // keyword for query subject
        final String env    = post.get("env", "");    // argument to query

        prop.put("mytime", GenericFormatter.SHORT_SECOND_FORMATTER.format());

        // 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;
        }

        // requests about environment
        if (obj.equals("rwiurlcount")) try {
            // the total number of different urls in the rwi is returned
            // <env> shall contain a word hash, the number of assigned lurls to this hash is returned
            prop.put("response", sb.indexSegments.termIndex(Segments.Process.PUBLIC).get(env.getBytes(), null).size());
            return prop;
        } catch (IOException e) {
            Log.logException(e);
        }

        if (obj.equals("rwicount")) {
            // return the total number of available word indexes
            prop.put("response", sb.indexSegments.termIndex(Segments.Process.PUBLIC).sizesMax());
            return prop;
        }

        if (obj.equals("lurlcount")) {
            // return the number of all available l-url's
            prop.put("response", sb.indexSegments.urlMetadata(Segments.Process.PUBLIC).size());
            return prop;
        }

        // requests about requirements

        if (obj.equals("wantedlurls")) {
            prop.put("response", "0"); // dummy response
            return prop;
        }

        if (obj.equals("wantedpurls")) {
            prop.put("response", "0"); // dummy response
            return prop;
        }

        if (obj.equals("wantedword")) {
            // response returns a list of wanted word hashes
            prop.put("response", "0"); // dummy response
            return prop;
        }

        if (obj.equals("wantedrwi")) {
            // <env> shall contain a word hash, the number of wanted lurls for this hash is returned
            prop.put("response", "0"); // dummy response
            return prop;
        }

        if (obj.equals("wantedseeds")) {
            // return a number of wanted seed
            prop.put("response", "0"); // dummy response
            return prop;
        }

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

    // example:
    // http://localhost:8090/yacy/idx.json?object=host
   
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final serverObjects prop = new serverObjects();

        prop.put("list", 0);
        prop.put("rowdef","");
        prop.put("name","");
        if (post == null || env == null) return prop;

        // return variable that accumulates replacements
        final Switchboard sb = (Switchboard) env;
       
        if (sb.adminAuthenticated(header) < 2 && !yacyNetwork.authentifyRequest(post, env)) {
            return prop;
        }
       
        if (post.get("object", "").equals("host")) {
            prop.put("name","host");
            ReferenceContainerCache<HostReference> idx = sb.webStructure.incomingReferences();
            prop.put("rowdef", WebStructureGraph.hostReferenceFactory.getRow().toString());
            int count = 0;
            for (ReferenceContainer<HostReference> references: idx) {
                prop.put("list_" + count + "_term", ASCII.String(references.getTermHash()));
                Iterator<HostReference> referenceIterator = references.entries();
                StringBuilder s = new StringBuilder();
                HostReference reference;
                while (referenceIterator.hasNext()) {
                    reference = referenceIterator.next();
                    s.append(reference.toPropertyForm());
                    if (referenceIterator.hasNext()) s.append(",");
                }
                prop.put("list_" + count + "_references", s.toString());
                prop.put("list_" + count + "_comma", 1);
                count++;
            }
            prop.put("list_" + (count-1) + "_comma", 0);
            prop.put("list", count);
        }
        // return rewrite properties
        return prop;
    }
View Full Code Here

public class ConfigAppearance_p {

    private final static String SKIN_FILENAME_FILTER = "^.*\\.css$";

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final serverObjects prop = new serverObjects();
        final Switchboard sb = (Switchboard) env;
        final String skinPath = new File(env.getDataPath(), env.getConfig("skinPath", "DATA/SKINS")).toString();

        // Fallback
        prop.put("currentskin", "");
        prop.put("status", "0"); // nothing

        List<String> skinFiles = FileUtils.getDirListing(skinPath, SKIN_FILENAME_FILTER);
        if (skinFiles == null) {
            return prop;
        }

        if (post != null) {
            String selectedSkin = post.get("skin");

            if (post.containsKey("use_button") && selectedSkin != null) {
                /* Only change skin if filename is contained in list of filesnames
                 * read from the skin directory. This is very important to prevent
                 * directory traversal attacks!
                 */
                if (skinFiles.contains(selectedSkin)) {
                    changeSkin(sb, skinPath, selectedSkin);
                }
               
            }

            if (post.containsKey("delete_button")) {

                /* Only delete file if filename is contained in list of filesname
                 * read from the skin directory. This is very important to prevent
                 * directory traversal attacks!
                 */
                if (skinFiles.contains(selectedSkin)) {
                    final File skinfile = new File(skinPath, selectedSkin);
                    FileUtils.deletedelete(skinfile);
                }
            }
           
            if (post.containsKey("install_button")) {
                // load skin from URL
                final String url = post.get("url");

                final Iterator<String> it;
                try {
                    final DigestURI u = new DigestURI(url);
                    it = FileUtils.strings(u.get(ClientIdentification.getUserAgent(), 10000));
                } catch (final IOException e) {
                    prop.put("status", "1");// unable to get URL
                    prop.put("status_url", url);
                    return prop;
                }
                try {
                    final File skinFile = new File(skinPath, url.substring(url.lastIndexOf('/'), url.length()));
                    final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(skinFile)));

                    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") && "on".equals(post.get("use_skin", ""))) {
                    changeSkin(sb, skinPath, url.substring(url.lastIndexOf('/'), url.length()));
                }
            }

            if (post.containsKey("set_colors")) {
                if (skinFiles.contains(selectedSkin)) {
                    changeSkin(sb, skinPath, selectedSkin);
                }
                for (final Map.Entry<String, String> entry: post.entrySet()) {
                    if (entry.getKey().startsWith("color_")) {
                        env.setConfig(entry.getKey(), "#" + entry.getValue());
                    }
                }
            }
        }

        // reread skins
        skinFiles = FileUtils.getDirListing(skinPath, SKIN_FILENAME_FILTER);
        Collections.sort(skinFiles);
        int count = 0;
        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));
                count++;
            }
        }
        prop.put("skinlist", count);
        prop.putHTML("currentskin", env.getConfig("currentSkin", "default"));
       
        // write colors from generic skin
        Iterator<String> i = env.configKeys();
        while (i.hasNext()) {
            final String key = i.next();
            if (key.startsWith("color_")) prop.put(key, env.getConfig(key, "#000000").substring(1));
        }
        return prop;
    }
View Full Code Here

    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();
        if ((post == null) || (env == null)) return prop;
        if (!yacyNetwork.authentifyRequest(post, env)) return prop;

        final String process = post.get("process", "permission");
        final String key =  post.get("key", "");
        final String clientip = header.get(HeaderFramework.CONNECTION_PROP_CLIENTIP, "<unknown>"); // read an artificial header addendum
        final InetAddress ias = Domains.dnsResolve(clientip);
       
        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.get(HeaderFramework.CONNECTION_PROP_CLIENTIP)))))) {
            // 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;
        }
       
        prop.put("messagesize", Integer.toString(messagesize));
        prop.put("attachmentsize", Integer.toString(attachmentsize));

        if (process.equals("permission")) {
            // permission: respond with acceptable message and attachment size
//          String iam = (String) post.get("iam", "");    // seed hash of requester
            prop.put("response", "Welcome to my peer!");
            // that's it!
        }

        if (process.equals("post")) {
            // post: post message to message board
            final String otherSeedString = post.get("myseed", "");
            if (otherSeedString.length() == 0) {
                prop.put("response", "-1"); // request rejected
                return prop;
            }
            //Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time
            yacySeed otherSeed;
            try {
                otherSeed = yacySeed.genRemoteSeed(otherSeedString, key, false, ias.getHostAddress());
            } catch (IOException e) {
                prop.put("response", "-1"); // don't accept messages for bad seeds
                return prop;
            }

            String subject = crypt.simpleDecode(post.get("subject", ""), key); // message's subject
            String message = crypt.simpleDecode(post.get("message", ""), key); // message body
            if (subject == null || message == null) {
                prop.put("response", "-1"); // don't accept empty messages
                return prop;
            }
            message = message.trim();
            subject = subject.trim();
            if (subject.length() == 0 || message.length() == 0) {
                prop.put("response", "-1"); // don't accept empty messages
                return prop;
            }
           
            prop.put("response", "Thank you!");

            // save message
            MessageBoard.entry msgEntry = null;
            byte[] mb;
            mb = UTF8.getBytes(message);
View Full Code Here

        // case if no values are requested
        if (post == null || env == null) {

            // we create empty entries for template strings
            final serverObjects prop = new serverObjects();
            return prop;
        }
       
        final servletProperties prop = new servletProperties();
        if (post.containsKey("act") && "clear_cookie".equals(post.get("act"))) {
            final ResponseHeader outgoingHeader = new ResponseHeader();
            final Iterator<Map.Entry<String, String>> it = header.entrySet().iterator();
            Map.Entry<String, String> e;
            while (it.hasNext()) {
                e = it.next();
                if ("Cookie".equals(e.getKey())) {
                    final String cookies[] = e.getValue().split(";");
                    for(final String cookie : cookies)
                    {
                        final String nameValue[] = cookie.split("=");
                        outgoingHeader.setCookie(nameValue[0].trim(),nameValue.length>1 ? (nameValue[1].trim()) : "","Thu, 01-Jan-99 00:00:01 GMT");
                    }
                }
            }
         
            prop.setOutgoingHeader(outgoingHeader);
            prop.put("coockiesout", "0");
            //header.
        
        } else if (post.containsKey("act") && "set_cookie".equals(post.get("act"))) {
            final String cookieName = post.get("cookie_name").trim();
            final String cookieValue = post.get("cookie_value").trim();
            final ResponseHeader outgoingHeader = new ResponseHeader();

            outgoingHeader.setCookie(cookieName,cookieValue);
            prop.setOutgoingHeader(outgoingHeader);
            prop.put("cookiesin", "1");
            prop.putHTML("cookiesin_0_name", cookieName);
            prop.putHTML("cookiesin_0_value", cookieValue);
            //header.
       }

        prop.put("cookiesout", "1");
        prop.putHTML("cookiesout_0_string", header.getHeaderCookies().replaceAll(";",";<br />"));
        return prop;
    }
View Full Code Here

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;

        // admin password
        boolean localhostAccess = sb.getConfigBool("adminAccountForLocalhost", false);
        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)) {
                // check passed. set account:
                env.setConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, Digest.encodeMD5Hex(Base64Order.standardCoder.encodeString(user + ":" + pw1)));
                env.setConfig("adminAccount", "");
            }
           
            if (localhostAccess) {

              sb.setConfig("adminAccountForLocalhost", true);
              // if an localhost access is configured, check if a local password is given
              // if not, set a random password
              if (env.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0) {
                // make a 'random' password
                env.setConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "0000" + sb.genRandomPassword());
                env.setConfig("adminAccount", "");
              }
            } else {
                sb.setConfig("adminAccountForLocalhost", false);
                if (env.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").startsWith("0000")) {
                    // make shure that the user can still use the interface after a random password was set
                    env.setConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "");
                }
            }
        }
       
        if (env.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_B64MD5, "").length() == 0 && !env.getConfigBool("adminAccountForLocalhost", false)) {
            prop.put("passwordNotSetWarning", 1);
        }
       
        prop.put("localhost.checked", (localhostAccess) ? 1 : 0);
        prop.put("account.checked", (localhostAccess) ? 0 : 1);
        prop.put("statusPassword", localhostAccess ? "0" : "1");
        prop.put("defaultUser", "admin");
       
        //default values
        prop.put("current_user", "newuser");
        prop.put("username", "");
        prop.put("firstname", "");
        prop.put("lastname", "");
        prop.put("address", "");
        prop.put("timelimit", "");
        prop.put("timeused", "");

        final AccessRight[] rights = AccessRight.values();
        int c = 0;
        for (final AccessRight right : rights) {
            prop.put("rights_" + c + "_name", right.toString());
            prop.put("rights_" + c +"_friendlyName", right.getFriendlyName());
            prop.put("rights_" + c + "_set", "0");
            c++;
        }
        prop.put("rights", c);
       
        prop.put("users", "0");
       
        if (sb.userDB == null) {
            return prop;
        }
       
        if (post == null) {
            //do nothing

            //user != current_user
            //user=from userlist
            //current_user = edited user
        } else if (post.containsKey("user") && !"newuser".equals(post.get("user"))){
            if (post.containsKey("change_user")) {
                //defaults for newuser are set above               
                entry = sb.userDB.getEntry(post.get("user"));
                // program crashes if a submit with empty username was made on previous mask and the user clicked on the
                // link: "If you want to manage more Users, return to the user page." (parameter "user" is empty)
                if (entry != null) {
                    //TODO: set username read-only in html
                    prop.putHTML("current_user", post.get("user"));
                    prop.putHTML("username", post.get("user"));
                    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);
                }
            } else if (post.containsKey("delete_user") && !"newuser".equals(post.get("user"))){
                sb.userDB.removeEntry(post.get("user"));
            }
        } else if (post.containsKey("change")) { //New User / edit User
            prop.put("text", "0");
            prop.put("error", "0");

            final String username = post.get("username");
            final String pw1 = post.get("password");
            final String pw2 = post.get("password2");

            if (pw1 == null || !pw1.equals(pw2)) {
                prop.put("error", "2"); //PW does not match
                return prop;
            }

            final String firstName = post.get("firstname");
            final String lastName = post.get("lastname");
            final String address = post.get("address");
            final String timeLimit = post.get("timelimit");
            final String timeUsed = post.get("timeused");
            final Map<AccessRight, String> rightsSet = new EnumMap<AccessRight, String>(AccessRight.class);

            for(final AccessRight right : rights) {
                rightsSet.put(right, post.containsKey(right.toString()) && "on".equals(post.get(right.toString())) ? "true" : "false");
            }
           
            final Map<String, String> mem = new HashMap<String, String>();
            if( "newuser".equals(post.get("current_user"))){ //new user
               
                if (!"".equals(pw1)) { //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 (final AccessRight right : rights) {
                    mem.put(right.toString(), rightsSet.get(right));
                }

                try {
                    entry = sb.userDB.createEntry(username, mem);
                    sb.userDB.addEntry(entry);
                    prop.putHTML("text_username", username);
                    prop.put("text", "1");
                } catch (final IllegalArgumentException e) {
                    prop.put("error", "3");
                }
               
            } else { //edit user

                entry = sb.userDB.getEntry(username);

                if (entry != null) {
                    try{
                        if (!"".equals(pw1)) {
                            entry.setProperty(UserDB.Entry.MD5ENCODED_USERPWD_STRING, Digest.encodeMD5Hex(username+":"+pw1));
                        }

                        entry.setProperty(UserDB.Entry.USER_FIRSTNAME, firstName);
                        entry.setProperty(UserDB.Entry.USER_LASTNAME, lastName);
                        entry.setProperty(UserDB.Entry.USER_ADDRESS, address);
                        entry.setProperty(UserDB.Entry.TIME_LIMIT, timeLimit);
                        entry.setProperty(UserDB.Entry.TIME_USED, timeUsed);

                        for(final AccessRight right : rights) {
                            entry.setProperty(right.toString(), rightsSet.get(right));
                        }

                    } catch (final Exception e) {
                        Log.logException(e);
                    }

                } else {
                    prop.put("error", "1");
                }
                prop.putHTML("text_username", username);
                prop.put("text", "2");
            }//edit user
            prop.putHTML("username", username);
        }
   
        //Generate Userlist
        final Iterator<UserDB.Entry> it = sb.userDB.iterator(true);
        int numUsers=0;
        while (it.hasNext()) {
            entry = it.next();
            if (entry == null) {
                continue;
            }
            prop.putHTML("users_"+numUsers+"_user", entry.getUserName());
            numUsers++;
        }
        prop.put("users", numUsers);

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

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

        if (post != null) {
            if (post.containsKey("retrieve")) {
                final String peerhash = post.get("peer", null);
                final yacySeed seed = (peerhash == null) ? null : sb.peers.getConnected(peerhash);
View Full Code Here

public class index {

    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
       
        String forwardTarget = sb.getConfig(SwitchboardConstants.INDEX_FORWARD, "");
        if (forwardTarget.length() > 0) {
            // forward the page
            prop.put("forward", 1);
            prop.put("forward_target", forwardTarget);
            return prop;
        }
       
        // access control
        final boolean authorizedAccess = sb.verifyAuthentication(header, false);
        if ((post != null) && (post.containsKey("publicPage"))) {
            if (!authorizedAccess) {
                prop.put("AUTHENTICATE", "admin log-in"); // force log-in
                return prop;
            }
        }
       
        final boolean global = (post == null) ? true : post.get("resource", "global").equals("global");

        int searchoptions = (post == null) ? 1 : post.getInt("searchoptions", 1);
        if (!sb.getConfigBool("search.options", true)) searchoptions = 0;
        final String former = (post == null) ? "" : post.get("former", "");
        final int count = Math.min(100, (post == null) ? 10 : post.getInt("count", 10));
        final int maximumRecords = sb.getConfigInt(SwitchboardConstants.SEARCH_ITEMS, 10);
        final String urlmaskfilter = (post == null) ? ".*" : post.get("urlmaskfilter", ".*");
        final String prefermaskfilter = (post == null) ? "" : post.get("prefermaskfilter", "");
        final String constraint = (post == null) ? "" : post.get("constraint", "");
        final String cat = (post == null) ? "href" : post.get("cat", "href");
        final int type = (post == null) ? 0 : post.getInt("type", 0);
       
        final boolean indexDistributeGranted = sb.getConfigBool(SwitchboardConstants.INDEX_DIST_ALLOW, true);
        final boolean indexReceiveGranted = sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_ALLOW, true) ||
                          sb.getConfigBool(SwitchboardConstants.INDEX_RECEIVE_AUTODISABLED, true);
        //global = global && indexDistributeGranted && indexReceiveGranted;
       
        // search domain
        ContentDomain contentdom = ContentDomain.TEXT;
        final String cds = (post == null) ? "text" : post.get("contentdom", "text");
        if (cds.equals("text")) contentdom = ContentDomain.TEXT;
        if (cds.equals("audio")) contentdom = ContentDomain.AUDIO;
        if (cds.equals("video")) contentdom = ContentDomain.VIDEO;
        if (cds.equals("image")) contentdom = ContentDomain.IMAGE;
        if (cds.equals("app")) contentdom = ContentDomain.APP;
       
        // we create empty entries for template strings
        String promoteSearchPageGreeting = env.getConfig(SwitchboardConstants.GREETING, "");
        if (env.getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) promoteSearchPageGreeting = env.getConfig("network.unit.description", "");
        prop.putHTML(SwitchboardConstants.GREETING, promoteSearchPageGreeting);
        prop.put(SwitchboardConstants.GREETING_HOMEPAGE, sb.getConfig(SwitchboardConstants.GREETING_HOMEPAGE, ""));
        prop.put(SwitchboardConstants.GREETING_LARGE_IMAGE, sb.getConfig(SwitchboardConstants.GREETING_LARGE_IMAGE, ""));
        prop.putHTML("former", former);
        prop.put("num-results", "0");
        prop.put("excluded", "0");
        prop.put("combine", "0");
        prop.put("resultbottomline", "0");
        prop.put("maximumRecords", maximumRecords);
        prop.put("searchoptions", searchoptions);
        prop.put("searchoptions_count-10", (count == 10) ? "1" : "0");
        prop.put("searchoptions_count-50", (count == 50) ? "1" : "0");
        prop.put("searchoptions_count-100", (count == 100) ? "1" : "0");
        prop.put("searchoptions_resource-select", sb.peers.sizeConnected() > 0 ? 1 : 0);
        prop.put("searchoptions_resource-select_global", global ? "1" : "0");
        prop.put("searchoptions_resource-select_global-disabled", (indexReceiveGranted && indexDistributeGranted) ? "0" : "1");
        prop.put("searchoptions_resource-select_global-disabled_reason", (indexReceiveGranted) ? "0" : (indexDistributeGranted ? "1" : "2"));
        prop.put("searchoptions_resource-select_local", global ? "0" : "1");
        prop.put("searchoptions_urlmaskoptions", "0");
        prop.putHTML("searchoptions_urlmaskoptions_urlmaskfilter", urlmaskfilter);
        prop.put("searchoptions_prefermaskoptions", "0");
        prop.putHTML("searchoptions_prefermaskoptions_prefermaskfilter", prefermaskfilter);
        prop.put("searchoptions_indexofChecked", "");
        prop.put("results", "");
        prop.putHTML("cat", cat);
        prop.put("type", type);
        prop.put("depth", "0");
        prop.put("topmenu", sb.getConfigBool("publicTopmenu", true) ? 1 : 0);
        prop.put("pi", sb.getConfigBool("publicAdministratorPi", false) ? 1 : 0);
        prop.putHTML("constraint", constraint);
        prop.put("searchdomswitches", sb.getConfigBool("search.text", true) || sb.getConfigBool("search.audio", true) || sb.getConfigBool("search.video", true) || sb.getConfigBool("search.image", true) || sb.getConfigBool("search.app", true) ? 1 : 0);
        prop.put("searchdomswitches_searchtext", sb.getConfigBool("search.text", true) ? 1 : 0);
        prop.put("searchdomswitches_searchaudio", sb.getConfigBool("search.audio", true) ? 1 : 0);
        prop.put("searchdomswitches_searchvideo", sb.getConfigBool("search.video", true) ? 1 : 0);
        prop.put("searchdomswitches_searchimage", sb.getConfigBool("search.image", true) ? 1 : 0);
        prop.put("searchdomswitches_searchapp", sb.getConfigBool("search.app", true) ? 1 : 0);
        prop.put("searchdomswitches_searchtext_check", (contentdom == ContentDomain.TEXT) ? "1" : "0");
        prop.put("searchdomswitches_searchaudio_check", (contentdom == ContentDomain.AUDIO) ? "1" : "0");
        prop.put("searchdomswitches_searchvideo_check", (contentdom == ContentDomain.VIDEO) ? "1" : "0");
        prop.put("searchdomswitches_searchimage_check", (contentdom == ContentDomain.IMAGE) ? "1" : "0");
        prop.put("searchdomswitches_searchapp_check", (contentdom == ContentDomain.APP) ? "1" : "0");
        prop.put("search.navigation", sb.getConfig("search.navigation", "all") );
        prop.put("search.verify", sb.getConfig("search.verify", "iffresh") );
        // online caution timing
        sb.localSearchLastAccess = System.currentTimeMillis();
       
        return prop;
    }
View Full Code Here

     * @param env the serverSwitch object holding all runtime-data
     * @return the rewrite-properties for the template
     */
    public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
        final Switchboard sb = (Switchboard) env;
        final serverObjects prop = new serverObjects();
       
        // getting the http host header
        final String hostSocket = header.get(HeaderFramework.CONNECTION_PROP_HOST);
       
        String host = hostSocket;
        int port = 80;
        final int pos = hostSocket.indexOf(":");       
        if (pos != -1) {
            port = Integer.parseInt(hostSocket.substring(pos + 1));
            host = hostSocket.substring(0, pos);
        }   
       
        prop.put("host", host);
        prop.put("port", port);
        prop.putHTML("name", sb.peers.mySeed().getName());
       
        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.