Package cu.ftpd.user.userbases.local

Examples of cu.ftpd.user.userbases.local.LocalUser


        // read the userfile, and for each value, add the corresponding value to a cuftpd user
        if (!userfile.getName().matches("[\\w-]+")) {
            System.err.println("Illegal username: " + userfile.getName());
            return;
        }
        LocalUser user = userbase.addUser(userfile.getName(), "WILL_BE_CHANGED", false);
        user.passwd(passwords.get(user.getUsername()), false);
        BufferedReader in = null;
        try {
            in = new BufferedReader(new InputStreamReader(new FileInputStream(userfile)));
            String line;
            boolean hasPrimaryGroupSet = false;
            while ((line = in.readLine()) != null) {
                if (line.startsWith("RATIO")) {
                    String[] parts = line.substring(5).trim().split(" ");
                    if ("0".equals(parts[0].trim())) {
                        userbase.setLeechForUser(true, user.getUsername(), null, false);
                    }
                } else if (line.startsWith("CREDITS")) {
                    String[] parts = line.substring(7).trim().split(" ");
                    user.setCredits(Long.parseLong(parts[0].trim()), false);
                } else if (line.startsWith("TAGLINE")) {
                    user.setTagline(line.substring(7).trim(), false);
                } else if (line.startsWith("TIME")) {
                    String[] parts = line.substring(4).trim().split(" ");
                    user.setLastlog(Long.parseLong(parts[1].trim()), false);
                } else if (line.startsWith("ADDED")) {
                    /* _todo: we can't set created from the inside. we'll let them be created when the script is run then instead
                    String[] parts = line.substring(5).trim().split(" ");
                    user.setCreated(line.substring(5).trim());
                    */
                } else if (line.startsWith("IP")) {
                    user.addIp(line.substring(2).trim(), false);
                } else if (line.startsWith("DNS")) {
                    user.addIp(line.substring(3).trim(), false);
                } else if (line.startsWith("LOGINS")) {
                    String[] parts = line.substring(6).trim().split(" ");
                    user.setLastlog(Long.parseLong(parts[0].trim()), false);
                } else if (line.startsWith("GENERAL")) {
                    String[] parts = line.substring(7).trim().split(" ");
                    userbase.setAllotmentForUser(Long.parseLong(parts[0].substring(parts[0].indexOf(',') + 1)), user.getUsername(), null, false);
                } else if (line.startsWith("FLAGS")) {
                    String flags = line.substring(5);
                    if (flags.contains("D")) {
                        user.addPermission(UserPermission.KICK, false);
                    }
                    if (flags.contains("F") || flags.contains("G")) {
                        user.addPermission(UserPermission.CREDITS, false);
                    }
                    if (flags.contains("H")) {
                        user.addPermission(UserPermission.VIEWUSER, false);
                    }

                    // flag D = UserPermission.KICK
                    // flag F | G = UserPermission.CREDITS
                    // flag H = UserPermission.VIEWUSER
                } else if (line.startsWith("ALLUP")) {
                    // _todo: find out the real format for stats
                    // one "set" of values for each section
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.ALLUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.ALLUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.ALLUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("ALLDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.ALLDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.ALLDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.ALLUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("MNUP")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.MNUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.MNUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.MNUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("MNDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.MNDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.MNDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.MNUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("WKUP")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.WKUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.WKUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.WKUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("WKDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.WKDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.WKDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.WKUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("DAYUP")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.DAYUP_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.DAYUP_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.DAYUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("DAYDN")) {
                    StatisticsEntry se = statistics.getUserStatistics(user.getUsername(), "default");
                    String[] parts = line.substring(5).trim().split(" ");
                    se.set(UserStatistics.DAYDN_FILES, Long.parseLong(parts[0]));
                    se.set(UserStatistics.DAYDN_BYTES, Long.parseLong(parts[1]) / 1024);
                    se.set(UserStatistics.DAYUP_TIME, Long.parseLong(parts[2]) / 1000);
                    statistics.store(se);
                } else if (line.startsWith("GROUP")) {
                    String[] groupdata = line.substring(5).trim().split(" ", 2);
                    final String group = groupdata[0].trim();
                    user.addGroup(group);
                    if ("1".equals(groupdata[1].trim())) {
                        user.addGadminForGroup(group, false);
                    }
                    if (!hasPrimaryGroupSet) {
                        hasPrimaryGroupSet = true;
                        user.setPrimaryGroup(group, false);
                    }
                }
            }
        } finally {
            if (in != null) {
View Full Code Here


    public void apply(Change change) {
        if (change instanceof UserChange) {
            UserChange userChange = (UserChange) change;
            try {
                LocalUser user = userbase.getUser(userChange.getUsername());
                userChangeActions.get(userChange.getProperty()).apply(userChange, user);
            } catch (NoSuchUserException e) {
                Logging.getErrorLog().reportError("User '" + userChange.getUsername() + "' doesn't exists. Asynchronous change disregarded. Was: " + change);
            }
        } else if (change instanceof UserbaseChange) {
View Full Code Here

TOP

Related Classes of cu.ftpd.user.userbases.local.LocalUser

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.