Line | |
---|
1 | import os |
---|
2 | import pwd |
---|
3 | import xmlrpclib |
---|
4 | |
---|
5 | class HomeCleaner: |
---|
6 | |
---|
7 | # MINUTES |
---|
8 | CRON_TIME=60 |
---|
9 | |
---|
10 | if os.path.exists("/etc/n4d/conf.d/golem"): |
---|
11 | |
---|
12 | predepends=["Golem"] |
---|
13 | |
---|
14 | def __init__(self): |
---|
15 | |
---|
16 | self.home="/home/" |
---|
17 | self.controlled=False |
---|
18 | if os.path.exists("/etc/n4d/controlled-startups.d/HomeCleaner"): |
---|
19 | self.controlled=True |
---|
20 | |
---|
21 | #def init |
---|
22 | |
---|
23 | def startup(self,options): |
---|
24 | |
---|
25 | if options["boot"]: |
---|
26 | if options["controlled"]: |
---|
27 | self.delete_orphan_homes() |
---|
28 | |
---|
29 | #def startup |
---|
30 | |
---|
31 | def delete_orphan_homes(self): |
---|
32 | |
---|
33 | n4d=xmlrpclib.ServerProxy("https://server:9779") |
---|
34 | |
---|
35 | try: |
---|
36 | user_list=[] |
---|
37 | ret=n4d.get_user_list("","Golem","*") |
---|
38 | |
---|
39 | for user in ret: |
---|
40 | user_list.append(user["uid"]) |
---|
41 | |
---|
42 | for user in pwd.getpwall(): |
---|
43 | u=user.pw_name |
---|
44 | if u not in user_list: |
---|
45 | user_list.append(u) |
---|
46 | |
---|
47 | |
---|
48 | rm_list=[] |
---|
49 | for item in os.listdir(self.home): |
---|
50 | if os.path.isdir(self.home+item): |
---|
51 | if item not in user_list: |
---|
52 | rm_list.append(item) |
---|
53 | |
---|
54 | for user in rm_list: |
---|
55 | |
---|
56 | os.system("rm -rf %s/%s"%(self.home,user)) |
---|
57 | |
---|
58 | return [True,""] |
---|
59 | |
---|
60 | except Exception as e: |
---|
61 | return [False,str(e)] |
---|
62 | |
---|
63 | #def delete_orphan_homes |
---|
64 | |
---|
65 | |
---|
66 | def n4d_cron(self,minutes): |
---|
67 | |
---|
68 | if minutes%HomeCleaner.CRON_TIME==0: |
---|
69 | if self.controlled: |
---|
70 | self.delete_orphan_homes() |
---|
71 | |
---|
72 | #def n4d_cron |
---|
Note: See
TracBrowser
for help on using the repository browser.