This repository has been archived by the owner on Mar 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfiles.py
executable file
·47 lines (42 loc) · 1.61 KB
/
files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding=utf-8
from fabric.api import *
import gen_mdp
@task(default=True)
@roles('files')
def main():
print("files.main")
@task
@roles('files')
def add_user(login_asso, mdp):
env.host_string = 'files.mde.utc'
sudo('smbldap-useradd -a -d /assos/%s -A1 %s' % (login_asso, login_asso))
sudo('echo -ne "%s\n%s\n" | smbpasswd -s %s' % (mdp, mdp, login_asso))
sudo('mkdir -p /assos/%s' % login_asso)
sudo('mkdir -p /sites/%s' % login_asso)
sudo('mkdir -p /sites/sessions/%s' % login_asso)
sudo('chown -R %s:"Domain Users" /assos/%s' % (login_asso, login_asso))
sudo('chown -R %s:web /sites/%s' % (login_asso, login_asso))
sudo('chown -R %s:web /sites/sessions/%s' % (login_asso, login_asso))
sudo('chmod 0700 -R /assos/%s' % login_asso)
sudo('chmod 2750 -R /sites/%s' % login_asso)
sudo('chmod 2750 -R /sites/sessions/%s' % login_asso)
sudo("echo \"<?php\nheader('Location: http://assos.utc.fr/asso/%s');\n?>\" > /sites/%s/index.php" % (login_asso, login_asso))
sudo('chown %s:web /sites/%s/index.php' % (login_asso, login_asso))
sudo('chmod 0640 /sites/%s/index.php' % login_asso)
sudo('ln -s /sites/%s /assos/%s/public_html' % (login_asso, login_asso))
@task
@roles('files')
def del_user(login_asso):
env.host_string = 'files.mde.utc'
try:
sudo('smbldap-userdel %s' % login_asso)
sudo('rm -R /assos/%s' % login_asso)
sudo('rm -R /sites/%s' % login_asso)
sudo('rm -R /sites/sessions/%s' % login_asso)
except:
pass
@task
@roles('files')
def change_passwd(login_asso, mdp):
print("Le mdp va être changé")
sudo('echo -ne "%s\n%s\n" | smbpasswd -s %s' % (mdp, mdp, login_asso))