Search in sources :

Example 16 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class WebCampaign method deleteUser.

/**
	 * Delete a user from the cache/aeropsike.
	 * 
	 * @param cmd
	 *            Map. The command parameters.
	 * @return String. The JSON encoded return of the command.
	 * @throws Exception
	 *             on Cache/aerospike and JSON errors.
	 */
public String deleteUser(Map cmd) throws Exception {
    Map response = new HashMap();
    try {
        String name = (String) cmd.get("username");
        if (name.equals("demo")) {
            response.put("error", true);
            response.put("message", "Demo user can't delete themselves");
            return getString(response);
        }
        String target = (String) cmd.get("target");
        User u = db.getUser(target);
        boolean state = RTBServer.stopped;
        RTBServer.stopped = true;
        db.deleteUser(target);
        Controller.getInstance().deleteUser(target, "*");
        RTBServer.stopped = state;
        response.put("users", makeUsersResponseList());
        response.put("campaigns", db.getAllCampaigns());
    } catch (Exception error) {
        response.put("message", "failed: " + error.toString());
        response.put("error", true);
    }
    return getString(response);
}
Also used : User(com.xrtb.db.User) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class WebCampaign method getAdmin.

/**
	 * Get admin data based on the login.
	 * 
	 * @param cmd
	 *            Map. The command parameters.
	 * @return String. The JSON encoded return from the command.
	 * @throws Exception
	 *             on cache/aerorpike or JSON errors.
	 */
public String getAdmin(Map cmd) throws Exception {
    String who = (String) cmd.get("username");
    String pass = (String) cmd.get("password");
    String subcommand = (String) cmd.get("subcommand");
    Map response = new HashMap();
    if (who.equals("root")) {
        if (Configuration.getInstance().password != null && Configuration.getInstance().password.equals(pass) == false) {
            response.put("error", true);
            response.put("message", "No such login");
            Controller.getInstance().sendLog(3, "WebAccess-Login", "Bad ADMIN root login attempted!");
            return getString(response);
        }
    } else {
        if (who.equalsIgnoreCase("demo") == false) {
            response.put("error", true);
            response.put("message", "No regular user logins allowed here.");
            Controller.getInstance().sendLog(3, "WebAccess-Login", "Bad ADMIN demo login attempted!");
            return getString(response);
        }
    }
    long time = System.currentTimeMillis();
    User u = null;
    if (who.equals("demo")) {
        u = db.getUser("demo");
        if (u == null) {
            response.put("error", true);
            response.put("message", "Demo login not allowed here");
            return getString(response);
        }
        if (u.password.length() > 0) {
            if (u.password.equals(pass) == false) {
                response.put("error", true);
                response.put("message", "Bad login");
                return getString(response);
            }
        }
    }
    Map m = new HashMap();
    try {
        List<String> userList = db.getUserList();
        List<User> users = new ArrayList();
        for (String s : userList) {
            u = db.getUser(s);
            if (u.name.equals(who) || who.equals("root"))
                users.add(u);
        }
        m.put("fileName", Configuration.getInstance().fileName);
        m.put("initials", Configuration.getInstance().initialLoadlist);
        m.put("seats", Configuration.getInstance().seatsList);
        m.put("lists", Configuration.getInstance().filesList);
        m.put("users", userList);
        m.put("status", getStatus());
        m.put("summaries", getSummary());
        Map x = new HashMap();
        x.put("winchannel", Configuration.getInstance().WINS_CHANNEL);
        x.put("bidchannel", Configuration.getInstance().BIDS_CHANNEL);
        x.put("responses", Configuration.getInstance().RESPONSES);
        x.put("nobid", Configuration.getInstance().NOBIDS_CHANNEL);
        x.put("request", Configuration.getInstance().REQUEST_CHANNEL);
        x.put("clicks", Configuration.getInstance().CLICKS_CHANNEL);
        x.put("log", Configuration.getInstance().LOG_CHANNEL);
        x.put("forensiq", Configuration.getInstance().FORENSIQ_CHANNEL);
        x.put("subscriber_hosts", Configuration.getInstance().commandAddresses);
        x.put("commands", Configuration.getInstance().commandsPort);
        x.put("requeststrategy", Configuration.getInstance().requstLogStrategyAsString());
        x.put("status", Configuration.getInstance().PERF_CHANNEL);
        m.put("zeromq", x);
        if (Configuration.getInstance().ssl != null) {
            x = new HashMap();
            x.put("setKeyStorePath", Configuration.getInstance().ssl.setKeyStorePath);
            x.put("setKeyStorePassword", Configuration.getInstance().ssl.setKeyStorePassword);
            x.put("setKeyManagerPassword", Configuration.getInstance().ssl.setKeyManagerPassword);
            m.put("ssl", x);
        }
        x = new HashMap();
        x.put("host", Configuration.getInstance().cacheHost);
        x.put("port", Configuration.getInstance().cachePort);
        x.put("maxconns", Configuration.getInstance().maxconns);
        m.put("aerospike", x);
        x = new HashMap();
        x.put("threads", RTBServer.threads);
        x.put("deadmanswitch", Configuration.getInstance().deadmanSwitch);
        x.put("multibid", Configuration.multibid);
        x.put("winurl", Configuration.getInstance().winUrl);
        x.put("pixel-tracking-url", Configuration.getInstance().pixelTrackingUrl);
        x.put("redirect-url", Configuration.getInstance().redirectUrl);
        x.put("adminPort", Configuration.getInstance().adminPort);
        x.put("adminSSL", Configuration.getInstance().adminSSL);
        x.put("ttl", Configuration.getInstance().ttl);
        x.put("stopped", Configuration.getInstance().pauseOnStart);
        x.put("password", Configuration.getInstance().password);
        m.put("app", x);
        m.put("verbosity", Configuration.getInstance().verbosity);
        m.put("geotags", Configuration.getInstance().geotags);
        m.put("forensiq", Configuration.forensiq);
        m.put("template", Configuration.getInstance().template);
        m.put("blacklist", DataBaseObject.getInstance().getBlackList());
    } catch (Exception error) {
        m.put("error", true);
        m.put("message", error.toString());
        error.printStackTrace();
    }
    m.put("sparklines", RTBServer.getSummary());
    m.put("running", Configuration.getInstance().getLoadedCampaignNames());
    return getString(m);
}
Also used : User(com.xrtb.db.User) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class DbTools method read.

/**
	 * Read the database.json file into this object.
	 * 
	 * @param db
	 *            String. The JSON string database to load into Redis.
	 * @return List. A list of users in the database file.
	 * @throws Exception
	 *             on file errors.
	 */
public List<User> read(String db) throws Exception {
    String content = new String(Files.readAllBytes(Paths.get(db)), StandardCharsets.UTF_8);
    System.out.println(content);
    List<User> users = mapper.readValue(content, mapper.getTypeFactory().constructCollectionType(List.class, User.class));
    Set set = map.keySet();
    Iterator<String> it = set.iterator();
    while (it.hasNext()) {
        User u = map.get(it.next());
        for (Campaign c : u.campaigns) {
            c.owner = u.name;
        }
        dbo.put(u);
    }
    return users;
}
Also used : User(com.xrtb.db.User) Set(java.util.Set) Campaign(com.xrtb.common.Campaign) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class DbTools method write.

/**
	 * Write the database object to the database.json file.
	 * 
	 * @param dbName
	 *            String. The filename to contain the Redis database.
	 * @throws Exception
	 *             on file errors.
	 */
public void write(String dbName) throws Exception {
    List<User> list = new ArrayList();
    List<String> users = dbo.listUsers();
    for (String user : users) {
        User u = dbo.get(user);
        for (Campaign c : u.campaigns) {
            c.owner = u.name;
        }
        list.add(u);
    }
    String content = mapper.writer().withDefaultPrettyPrinter().writeValueAsString(list);
    Files.write(Paths.get(dbName), content.getBytes());
    System.out.println(content);
}
Also used : User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign) ArrayList(java.util.ArrayList)

Example 20 with User

use of com.xrtb.db.User in project XRTB by benmfaul.

the class DbTools method printDatabase.

/**
	 * Print the contents of the REDIS database to stdout.
	 */
public void printDatabase() throws Exception {
    List<String> users = dbo.listUsers();
    for (String who : users) {
        User u = dbo.get(who);
        System.out.println("====> " + who);
        String str = mapper.writer().withDefaultPrettyPrinter().writeValueAsString(u);
        System.out.println(str);
    }
}
Also used : User(com.xrtb.db.User)

Aggregations

User (com.xrtb.db.User)28 Campaign (com.xrtb.common.Campaign)13 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 Map (java.util.Map)9 List (java.util.List)7 RTBServer (com.xrtb.bidder.RTBServer)5 Configuration (com.xrtb.common.Configuration)5 DbTools (com.xrtb.tools.DbTools)5 Test (org.junit.Test)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Node (com.xrtb.common.Node)3 BidRequest (com.xrtb.pojo.BidRequest)3 File (java.io.File)2 Set (java.util.Set)2 HttpSession (javax.servlet.http.HttpSession)2 BeforeClass (org.junit.BeforeClass)2 AddCampaign (com.xrtb.commands.AddCampaign)1 DeleteCampaign (com.xrtb.commands.DeleteCampaign)1 DataBaseObject (com.xrtb.db.DataBaseObject)1