Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c96bf194
authored
Feb 05, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: fix ssh key validation
parent
92bda738
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
12 deletions
+12
-12
one/migrations/0004_auto__chg_field_userclouddetails_ssh_private_key.py
+0
-0
one/models.py
+12
-12
No files found.
one/migrations/0004_auto__chg_field_userclouddetails_ssh_private_key.py
0 → 100644
View file @
c96bf194
This diff is collapsed.
Click to expand it.
one/models.py
View file @
c96bf194
...
...
@@ -12,7 +12,7 @@ from firewall.tasks import reload_firewall_lock
from
one.util
import
keygen
from
school.models
import
Person
import
subprocess
,
tempfile
,
os
,
stat
,
re
import
subprocess
,
tempfile
,
os
,
stat
,
re
,
base64
,
struct
pwgen
=
User
.
objects
.
make_random_password
...
...
@@ -26,6 +26,7 @@ def create_user_profile(sender, instance, created, **kwargs):
d
.
save
()
post_save
.
connect
(
create_user_profile
,
sender
=
User
)
"""
Cloud related details of a user
"""
...
...
@@ -36,7 +37,7 @@ class UserCloudDetails(models.Model):
help_text
=
_
(
'Generated password for accessing store from Windows.'
))
ssh_key
=
models
.
ForeignKey
(
'SshKey'
,
null
=
True
,
verbose_name
=
_
(
'SSH key (public)'
),
help_text
=
_
(
'Generated SSH public key for accessing store from Linux.'
))
ssh_private_key
=
models
.
TextField
(
verbose_name
=
_
(
'SSH key (private)'
),
ssh_private_key
=
models
.
TextField
(
verbose_name
=
_
(
'SSH key (private)'
),
null
=
True
,
help_text
=
_
(
'Generated SSH private key for accessing store from Linux.'
))
"""
...
...
@@ -51,6 +52,8 @@ class UserCloudDetails(models.Model):
except
:
self
.
ssh_key
=
SshKey
(
user
=
self
.
user
,
key
=
pub
)
self
.
ssh_key
.
save
()
self
.
ssh_key_id
=
self
.
ssh_key
.
id
self
.
save
()
"""
Generate new Samba password.
...
...
@@ -58,15 +61,12 @@ class UserCloudDetails(models.Model):
def
reset_smb
(
self
):
self
.
smb_password
=
pwgen
()
"""
Generate key pair and Samba password if needed.
"""
def
clean
(
self
):
super
(
UserCloudDetails
,
self
)
.
clean
()
if
not
self
.
ssh_key
:
self
.
reset_keys
()
if
not
self
.
smb_password
or
len
(
self
.
smb_password
)
==
0
:
self
.
reset_smb
()
def
reset_keys
(
sender
,
instance
,
created
,
**
kwargs
):
if
created
:
instance
.
reset_smb
()
instance
.
reset_keys
()
post_save
.
connect
(
reset_keys
,
sender
=
UserCloudDetails
)
"""
Validate OpenSSH keys (length and type).
...
...
@@ -100,7 +100,7 @@ SSH public key (in OpenSSH format).
class
SshKey
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
null
=
False
,
blank
=
False
)
key
=
models
.
CharField
(
max_length
=
2000
,
verbose_name
=
_
(
'SSH key'
),
help_text
=
_
(
'<a href="/info/ssh/">SSH public key in OpenSSH format</a> used for shell login '
help_text
=
_
(
'<a href="/info/ssh/">SSH public key in OpenSSH format</a> used for shell
and store
login '
'(2048+ bit RSA preferred). Example: <code>ssh-rsa AAAAB...QtQ== '
'john</code>.'
),
validators
=
[
OpenSshKeyValidator
()])
...
...
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