Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cranspasswords
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Graillot
Cranspasswords
Commits
3c834023
Commit
3c834023
authored
12 years ago
by
Daniel STAN
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of vo:./cranspasswords
parents
52a1a113
ffbca15d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cranspasswords-server.py
+46
-6
46 additions, 6 deletions
cranspasswords-server.py
with
46 additions
and
6 deletions
cranspasswords-server.py
+
46
−
6
View file @
3c834023
...
@@ -10,11 +10,17 @@ import os
...
@@ -10,11 +10,17 @@ import os
import
pwd
import
pwd
import
sys
import
sys
import
json
import
json
import
smtplib
from
email.mime.text
import
MIMEText
from
email.mime.multipart
import
MIMEMultipart
MYUID
=
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
MYUID
=
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
if
MYUID
==
'
root
'
:
if
MYUID
==
'
root
'
:
MYUID
=
os
.
environ
[
'
SUDO_USER
'
]
MYUID
=
os
.
environ
[
'
SUDO_USER
'
]
CRANSP_MAIL
=
"
root@crans.org
"
DEST_MAIL
=
"
dstan@crans.org
"
KEYS
=
{
KEYS
=
{
"
aza-vallina
"
:
(
"
Damien.Aza-Vallina@crans.org
"
,
None
),
"
aza-vallina
"
:
(
"
Damien.Aza-Vallina@crans.org
"
,
None
),
"
dandrimont
"
:
(
"
nicolas.dandrimont@crans.org
"
,
"
66475AAF
"
),
"
dandrimont
"
:
(
"
nicolas.dandrimont@crans.org
"
,
"
66475AAF
"
),
...
@@ -31,6 +37,7 @@ KEYS = {
...
@@ -31,6 +37,7 @@ KEYS = {
"
becue
"
:
(
"
becue@crans.org
"
,
"
194974E2
"
),
"
becue
"
:
(
"
becue@crans.org
"
,
"
194974E2
"
),
"
dstan
"
:
(
"
daniel.stan@crans.org
"
,
"
6E1C820B
"
),
"
dstan
"
:
(
"
daniel.stan@crans.org
"
,
"
6E1C820B
"
),
"
samir
"
:
(
"
samir@crans.org
"
,
"
41C2B76B
"
),
"
samir
"
:
(
"
samir@crans.org
"
,
"
41C2B76B
"
),
"
boilard
"
:
(
"
boilard@crans.org
"
,
"
C39EB6F4
"
),
"
cauderlier
"
:
(
"
cauderlier@crans.org
"
,
None
),
#Méchant pas beau
"
cauderlier
"
:
(
"
cauderlier@crans.org
"
,
None
),
#Méchant pas beau
"
maioli
"
:
(
"
maioli@crans.org
"
,
None
)
#Bis (maybe 9E5026E8)
"
maioli
"
:
(
"
maioli@crans.org
"
,
None
)
#Bis (maybe 9E5026E8)
}
}
...
@@ -52,13 +59,15 @@ NOUNOUS=RTC+[
...
@@ -52,13 +59,15 @@ NOUNOUS=RTC+[
"
parret-freaud
"
,
"
parret-freaud
"
,
"
cauderlier
"
,
"
cauderlier
"
,
"
maioli
"
,
"
maioli
"
,
"
samir
"
"
samir
"
,
"
boilard
"
]
]
CA
=
[
"
becue
"
,
"
dstan
"
,
"
boilard
"
]
ROLES
=
{
ROLES
=
{
"
bureau
"
:
[],
"
ca
"
:
CA
,
"
ca
"
:
[],
"
ca-w
"
:
CA
,
"
rtc
"
:
RTC
,
"
nounous
"
:
NOUNOUS
,
"
nounous
"
:
NOUNOUS
,
"
nounous-w
"
:
NOUNOUS
#Or maybe RTC ?
"
nounous-w
"
:
NOUNOUS
#Or maybe RTC ?
}
}
...
@@ -132,29 +141,60 @@ def putfile(filename):
...
@@ -132,29 +141,60 @@ def putfile(filename):
return
False
return
False
try
:
try
:
oldroles
=
getfile
(
filename
)[
'
roles
'
]
old
=
getfile
(
filename
)
oldroles
=
old
[
'
roles
'
]
except
TypeError
:
except
TypeError
:
old
=
"
//Nouveau fichier
"
pass
pass
else
:
else
:
if
not
validate
(
oldroles
,
'
w
'
):
if
not
validate
(
oldroles
,
'
w
'
):
return
False
return
False
notification
(
"
Modification de %s
"
%
filename
,
\
"
Le fichier %s a été modifié par %s.
"
%
\
(
filename
,
MYUID
),
filename
,
str
(
old
))
writefile
(
filepath
,
json
.
dumps
({
'
roles
'
:
roles
,
'
contents
'
:
contents
}))
writefile
(
filepath
,
json
.
dumps
({
'
roles
'
:
roles
,
'
contents
'
:
contents
}))
return
True
return
True
def
rmfile
(
filename
):
def
rmfile
(
filename
):
"""
Supprime le fichier filename après avoir vérifié les droits sur le fichier
"""
"""
Supprime le fichier filename après avoir vérifié les droits sur le fichier
"""
try
:
try
:
roles
=
getfile
(
filename
)[
'
roles
'
]
old
=
getfile
(
filename
)
roles
=
old
[
'
roles
'
]
except
TypeError
:
except
TypeError
:
return
True
return
True
else
:
else
:
if
validate
(
roles
,
'
w
'
):
if
validate
(
roles
,
'
w
'
):
notification
(
"
Suppression de %s
"
%
filename
,
\
"
Le fichier %s a été supprimé par %s.
"
%
\
(
filename
,
MYUID
),
filename
,
str
(
old
))
os
.
remove
(
getpath
(
filename
))
os
.
remove
(
getpath
(
filename
))
else
:
else
:
return
False
return
False
return
True
return
True
def
notification
(
subject
,
corps
,
fname
,
old
):
conn
=
smtplib
.
SMTP
(
'
localhost
'
)
frommail
=
CRANSP_MAIL
tomail
=
DEST_MAIL
msg
=
MIMEMultipart
(
_charset
=
"
utf-8
"
)
msg
[
'
Subject
'
]
=
subject
# me == the sender's email address
# family = the list of all recipients' email addresses
msg
[
'
From
'
]
=
"
cranspasswords <%s>
"
%
CRANSP_MAIL
msg
[
'
To
'
]
=
DEST_MAIL
msg
.
preamble
=
"
cranspasswords report
"
info
=
MIMEText
(
corps
+
#"\nCi-joint l'ancien fichier." +
"
\n\n
--
\n
Cranspasswords.py
"
,
_charset
=
"
utf-8
"
)
msg
.
attach
(
info
)
#old = MIMEText(old)
#old.add_header('Content-Disposition', 'attachment', filename=fname)
#msg.attach(old)
conn
.
sendmail
(
frommail
,
tomail
,
msg
.
as_string
())
conn
.
quit
()
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
argv
=
sys
.
argv
[
1
:]
argv
=
sys
.
argv
[
1
:]
if
len
(
argv
)
not
in
[
1
,
2
]:
if
len
(
argv
)
not
in
[
1
,
2
]:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment