Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Crans Passwords
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
Crans Passwords
Commits
ffbca15d
Commit
ffbca15d
authored
Jun 02, 2012
by
Daniel STAN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ajout de l'envoi de mail et d'une nounou
parent
14db7244
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
6 deletions
+46
-6
cranspasswords-server.py
cranspasswords-server.py
+46
-6
No files found.
cranspasswords-server.py
View file @
ffbca15d
...
...
@@ -10,11 +10,17 @@ import os
import
pwd
import
sys
import
json
import
smtplib
from
email.mime.text
import
MIMEText
from
email.mime.multipart
import
MIMEMultipart
MYUID
=
pwd
.
getpwuid
(
os
.
getuid
())[
0
]
if
MYUID
==
'root'
:
MYUID
=
os
.
environ
[
'SUDO_USER'
]
CRANSP_MAIL
=
"root@crans.org"
DEST_MAIL
=
"dstan@crans.org"
KEYS
=
{
"aza-vallina"
:
(
"Damien.Aza-Vallina@crans.org"
,
None
),
"dandrimont"
:
(
"nicolas.dandrimont@crans.org"
,
"66475AAF"
),
...
...
@@ -31,6 +37,7 @@ KEYS = {
"becue"
:
(
"becue@crans.org"
,
"194974E2"
),
"dstan"
:
(
"daniel.stan@crans.org"
,
"6E1C820B"
),
"samir"
:
(
"samir@crans.org"
,
"41C2B76B"
),
"boilard"
:
(
"boilard@crans.org"
,
"C39EB6F4"
),
"cauderlier"
:
(
"cauderlier@crans.org"
,
None
),
#Méchant pas beau
"maioli"
:
(
"maioli@crans.org"
,
None
)
#Bis (maybe 9E5026E8)
}
...
...
@@ -52,13 +59,15 @@ NOUNOUS=RTC+[
"parret-freaud"
,
"cauderlier"
,
"maioli"
,
"samir"
"samir"
,
"boilard"
]
CA
=
[
"becue"
,
"dstan"
,
"boilard"
]
ROLES
=
{
"bureau"
:
[],
"ca"
:
[],
"rtc"
:
RTC
,
"ca"
:
CA
,
"ca-w"
:
CA
,
"nounous"
:
NOUNOUS
,
"nounous-w"
:
NOUNOUS
#Or maybe RTC ?
}
...
...
@@ -132,29 +141,60 @@ def putfile(filename):
return
False
try
:
oldroles
=
getfile
(
filename
)[
'roles'
]
old
=
getfile
(
filename
)
oldroles
=
old
[
'roles'
]
except
TypeError
:
old
=
"//Nouveau fichier"
pass
else
:
if
not
validate
(
oldroles
,
'w'
):
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
}))
return
True
def
rmfile
(
filename
):
"""Supprime le fichier filename après avoir vérifié les droits sur le fichier"""
try
:
roles
=
getfile
(
filename
)[
'roles'
]
old
=
getfile
(
filename
)
roles
=
old
[
'roles'
]
except
TypeError
:
return
True
else
:
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
))
else
:
return
False
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__"
:
argv
=
sys
.
argv
[
1
:]
if
len
(
argv
)
not
in
[
1
,
2
]:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment