コード例 #1
0
ファイル: accounts.py プロジェクト: MaxEllsworth/lhl
    def assign_to_groups(
        self, user, groups
    ):  # assign single user (single string) to groups designated in groups variable (list)
        file = open(config.file().group_file(), "r")
        groups_lines = [line.split(":") for line in file.readlines()]
        for int in range(0, len(groups_lines)):
            if groups_lines[int][0] in groups:
                if user not in groups_lines[int][3].rstrip("\n").split(","):
                    if groups_lines[int][3].rstrip("\n").split(",") == "":
                        groups_lines[int][3] = user
                    else:
                        newline = groups_lines[int][3].rstrip("\n").split(", ")
                        newline.append(str(user + "\n"))
                    groups_lines[int][3] = ", ".join(newline)

            elif user in groups_lines[int][3].rstrip("\n").split(",") and groups_lines[int][0] not in groups:
                fixed_line = groups_lines[int][3].rstrip("\n").split(",")
                while user in fixed_line:
                    fixed_line.remove(user)
                    # print fixed_line
                fixed_line = ", ".join(fixed_line) + "\n"
                # print fixed_line
                groups_lines[int][3] = fixed_line
        groups_lines = [":".join(line) for line in groups_lines]
        file = open(config.file().group_file(), "w+")
        for line in groups_lines:
            file.write(line)
        file.close()
        log("ens", "usr", str("is only in groups {}".format(", ".join(groups))))
コード例 #2
0
ファイル: accounts.py プロジェクト: MaxEllsworth/lhl
    def update_password_hash(self, user, hash):  # only for one user
        file = open(config.file().shadow_file(), "r")
        password_lines = [line.split(":") for line in file.readlines()]
        file.close()
        for int in range(0, len(password_lines)):
            if password_lines[int][0] == user:
                password_lines[int][1] = hash

        password_lines = [":".join(line) for line in password_lines]
        file = open(config.file().shadow_file(), "w+")
        file.writelines(password_lines)
        file.close()
        log("chn", "psw", str("for user" + user))
コード例 #3
0
ファイル: accounts.py プロジェクト: MaxEllsworth/lhl
 def disable_users(self, marked):
     """ Takes in list of users, disables them with !."""
     file = open(config.file().shadow_file())
     shadow_file = [line.split(":") for line in file.readlines()]
     file.close()
     for int in range(0, len(shadow_file)):
         if shadow_file[int][0] in marked:
             shadow_file[int][1] = "!"
     shadow_file = [":".join(line) for line in shadow_file]
     file = open(config.file().shadow_file(), "w+")
     file.writelines(shadow_file)
     log("dsb", "usr", ", ".join(marked))
     file.close()
コード例 #4
0
ファイル: netcon.py プロジェクト: MaxEllsworth/lhl
def hosts_check():
	file = open(config.file().hosts_file(), "r")
	lines = [item for item in [line for line in file.readlines() if line != "\n"] if item.split()[0] != "#"] 
	hosts = ["".join([item.rstrip("\n") for item in line if item != " "]).split("\t") for line in lines]
	file.close()
	for line in hosts:
		organized_dict = {}
		if len(line) == 2:
			organized_dict["name"], organized_dict["address"] = line[1], line[0]
			organized_dict["special"] = ""
			dbr.ok("hosts_file")
			dbr.fill("hosts_file", organized_dict)
			
			log("dbd", "hst", str(organized_dict["name"] + " : " + organized_dict["address"]))
		elif len(line) == 1:
			organized_dict["special"] = line[0]
			organized_dict["name"], organized_dict["address"] = "", ""
			dbr.ok("hosts_file")
			dbr.fill("hosts_file", organized_dict)
			
			log("dbd", "hst", organized_dict["special"])
コード例 #5
0
ファイル: accounts.py プロジェクト: MaxEllsworth/lhl
    def group_membership(self):
        file = open(config.file().group_file(), "r")
        groups_lines = [line.split(":") for line in file.readlines()]
        file.close()
        groups = [group[0] for group in groups_lines]
        members = [group[3] for group in groups_lines]

        groups_list = []
        for int in range(0, len(groups)):
            membership_dict = {}
            membership_dict[groups[int]] = members[int].rstrip("\n")
            groups_list.append(membership_dict)

        for item in groups_list:
            organized_dict = {}
            dbr.ok("group_membership")
            if item.values()[0] == "\n":
                item[item.keys()[0]] = ""
            organized_dict["group"] = item.keys()[0]
            organized_dict["members"] = item.values()[0]
            dbr.fill("group_membership", organized_dict)
        log("dbd", "grp", "membership")
コード例 #6
0
ファイル: accounts.py プロジェクト: MaxEllsworth/lhl
 def abnormal_users(self, allowed_users):
     """takes in list of allowed users, dbs users not in list and not in default list."""
     normal = [
         "daemon",
         "bin",
         "sys",
         "sync",
         "games",
         "man",
         "lp",
         "mail",
         "news",
         "uucp",
         "proxy",
         "www-data",
         "backup",
         "list",
         "irc",
         "gnats",
         "nobody",
         "libuuid",
         "statd",
         "shd",
         "root",
     ]
     file = open(config.file().shadow_file(), "r")
     current_users = [line.split(":")[0] for line in file.readlines()]
     file.close()
     nonnormal = [user for user in current_users if user not in normal]
     abnormal = [user for user in nonnormal if user not in allowed_users]
     for int in range(0, len(abnormal)):
         organized_dict = {}
         organized_dict["user"] = abnormal[int]
         dbr.ok("abnormal_users")
         dbr.fill("abnormal_users", organized_dict)
     log("dbd", "usr", ", ".join(abnormal), "abnormal")
     return abnormal