Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Crans Passwords
Manage
Activity
Members
Labels
Plan
Issues
5
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Nounous
Crans Passwords
Commits
3bf48dcf
Commit
3bf48dcf
authored
12 years ago
by
root
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of /home/dstan/cranspasswords
parents
a8c467de
8e8f390d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cranspasswords-server.py
+17
-7
17 additions, 7 deletions
cranspasswords-server.py
with
17 additions
and
7 deletions
cranspasswords-server.py
+
17
−
7
View file @
3bf48dcf
...
@@ -11,6 +11,7 @@ import pwd
...
@@ -11,6 +11,7 @@ import pwd
import
sys
import
sys
import
json
import
json
import
smtplib
import
smtplib
import
datetime
from
email.mime.text
import
MIMEText
from
email.mime.text
import
MIMEText
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.multipart
import
MIMEMultipart
...
@@ -82,9 +83,9 @@ def validate(roles,mode='r'):
...
@@ -82,9 +83,9 @@ def validate(roles,mode='r'):
return
True
return
True
return
False
return
False
def
getpath
(
filename
):
def
getpath
(
filename
,
backup
=
False
):
"""
Récupère le chemin du fichier `filename
'"""
"""
Récupère le chemin du fichier `filename
'"""
return
os
.
path
.
join
(
STORE
,
'
%s.
json
'
%
filename
)
return
os
.
path
.
join
(
STORE
,
'
%s.
%s
'
%
(
filename
,
'
bak
'
if
backup
else
'
json
'
)
)
def
writefile
(
filename
,
contents
):
def
writefile
(
filename
,
contents
):
"""
Écrit le fichier de manière sécure
"""
"""
Écrit le fichier de manière sécure
"""
...
@@ -146,7 +147,7 @@ def putfile(filename):
...
@@ -146,7 +147,7 @@ def putfile(filename):
old
=
getfile
(
filename
)
old
=
getfile
(
filename
)
oldroles
=
old
[
'
roles
'
]
oldroles
=
old
[
'
roles
'
]
except
TypeError
:
except
TypeError
:
old
=
"
//Nouvea
u fichier
"
old
=
"
[Création d
u fichier
]
"
pass
pass
else
:
else
:
if
not
validate
(
oldroles
,
'
w
'
):
if
not
validate
(
oldroles
,
'
w
'
):
...
@@ -154,7 +155,7 @@ def putfile(filename):
...
@@ -154,7 +155,7 @@ def putfile(filename):
notification
(
"
Modification de %s
"
%
filename
,
\
notification
(
"
Modification de %s
"
%
filename
,
\
"
Le fichier %s a été modifié par %s.
"
%
\
"
Le fichier %s a été modifié par %s.
"
%
\
(
filename
,
MYUID
),
filename
,
str
(
old
)
)
(
filename
,
MYUID
),
filename
,
old
)
writefile
(
filepath
,
json
.
dumps
({
'
roles
'
:
roles
,
'
contents
'
:
contents
}))
writefile
(
filepath
,
json
.
dumps
({
'
roles
'
:
roles
,
'
contents
'
:
contents
}))
...
@@ -171,13 +172,20 @@ def rmfile(filename):
...
@@ -171,13 +172,20 @@ def rmfile(filename):
if
validate
(
roles
,
'
w
'
):
if
validate
(
roles
,
'
w
'
):
notification
(
"
Suppression de %s
"
%
filename
,
\
notification
(
"
Suppression de %s
"
%
filename
,
\
"
Le fichier %s a été supprimé par %s.
"
%
\
"
Le fichier %s a été supprimé par %s.
"
%
\
(
filename
,
MYUID
),
filename
,
str
(
old
)
)
(
filename
,
MYUID
),
filename
,
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
):
def
notification
(
subject
,
corps
,
fname
,
old
):
back
=
open
(
getpath
(
fname
,
True
),
'
a
'
)
back
.
write
(
json
.
dumps
(
old
))
back
.
write
(
'
\n
'
)
back
.
write
(
'
* %s: %s
\n
'
%
(
str
(
datetime
.
datetime
.
now
()),
corps
))
back
.
close
()
# Puis envoi du message
conn
=
smtplib
.
SMTP
(
'
localhost
'
)
conn
=
smtplib
.
SMTP
(
'
localhost
'
)
frommail
=
CRANSP_MAIL
frommail
=
CRANSP_MAIL
tomail
=
DEST_MAIL
tomail
=
DEST_MAIL
...
@@ -188,12 +196,14 @@ def notification(subject,corps,fname,old):
...
@@ -188,12 +196,14 @@ def notification(subject,corps,fname,old):
msg
[
'
From
'
]
=
"
cranspasswords <%s>
"
%
CRANSP_MAIL
msg
[
'
From
'
]
=
"
cranspasswords <%s>
"
%
CRANSP_MAIL
msg
[
'
To
'
]
=
DEST_MAIL
msg
[
'
To
'
]
=
DEST_MAIL
msg
.
preamble
=
"
cranspasswords report
"
msg
.
preamble
=
"
cranspasswords report
"
info
=
MIMEText
(
corps
+
#"\nCi-joint l'ancien fichier." +
info
=
MIMEText
(
corps
+
"
\n
La précédente version a été sauvegardée
"
+
#"\nCi-joint l'ancien fichier." +
"
\n\n
--
\n
Cranspasswords.py
"
,
_charset
=
"
utf-8
"
)
"
\n\n
--
\n
Cranspasswords.py
"
,
_charset
=
"
utf-8
"
)
msg
.
attach
(
info
)
msg
.
attach
(
info
)
#old = MIMEText(old)
#old = MIMEText(old)
#old.add_header('Content-Disposition', 'attachment', filename=fname)
#old.add_header('Content-Disposition', 'attachment', filename=fname)
#msg.attach(old)
#msg.attach(
str(
old)
)
conn
.
sendmail
(
frommail
,
tomail
,
msg
.
as_string
())
conn
.
sendmail
(
frommail
,
tomail
,
msg
.
as_string
())
conn
.
quit
()
conn
.
quit
()
...
...
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