46 lines
1.1 KiB
Python
Executable File
46 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import subprocess
|
|
|
|
def import_acls(input_file):
|
|
print(f"Importing ACLs from {input_file}...")
|
|
|
|
with open(input_file, "r") as f:
|
|
lines = f.readlines()
|
|
|
|
for line in lines:
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
|
|
path, user, role = line.split()
|
|
print(f"Adding ACL: Path={path}, User={user}, Role={role}")
|
|
|
|
result = subprocess.run(["pveum", "acl", "modify", path, "--users", user, "--roles", role])
|
|
|
|
if result.returncode != 0:
|
|
print(f"Error adding ACL: {result.stderr}")
|
|
else:
|
|
print(f"Successfully added ACL for {path}")
|
|
|
|
print("ACL import completed.")
|
|
|
|
def main():
|
|
if len(sys.argv) != 2:
|
|
print(f"Usage: {sys.argv[0]} <input_file>")
|
|
print("""
|
|
Arguments:
|
|
input_file - File containing ACLs to import
|
|
|
|
Input file format:
|
|
/acl/path user@realm role
|
|
/acl/path user@realm role
|
|
...""")
|
|
sys.exit(1)
|
|
|
|
input_file = sys.argv[1]
|
|
import_acls(input_file)
|
|
|
|
if __name__ == "__main__":
|
|
main() |