Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
f978bdee
authored
Feb 09, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store-server: fixed quota
parent
aedd2a46
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
10 deletions
+53
-10
miscellaneous/store-server/CloudStore.py
+10
-5
miscellaneous/store-server/FAKEUserManager.sh
+4
-0
one/models.py
+18
-1
one/static/cloud.js
+8
-1
store/api.py
+11
-2
store/views.py
+2
-1
No files found.
miscellaneous/store-server/CloudStore.py
View file @
f978bdee
...
@@ -229,7 +229,7 @@ def set_quota(neptun):
...
@@ -229,7 +229,7 @@ def set_quota(neptun):
quota
=
request
.
json
[
'QUOTA'
]
quota
=
request
.
json
[
'QUOTA'
]
except
:
except
:
abort
(
400
,
'Wrong syntax!'
)
abort
(
400
,
'Wrong syntax!'
)
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'setquota'
,
neptun
,
quota
,
hard_quota
(
quota
)])
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'setquota'
,
neptun
,
str
(
quota
)
,
hard_quota
(
quota
)])
if
result
==
0
:
if
result
==
0
:
return
return
elif
result
==
2
:
elif
result
==
2
:
...
@@ -240,25 +240,30 @@ def set_quota(neptun):
...
@@ -240,25 +240,30 @@ def set_quota(neptun):
@force_ssl
@force_ssl
def
new_user
(
neptun
):
def
new_user
(
neptun
):
key_list
=
[]
key_list
=
[]
smbpasswd
=
''
smbpasswd
=
''
quota
=
''
try
:
try
:
smbpasswd
=
request
.
json
[
'SMBPASSWD'
]
smbpasswd
=
request
.
json
[
'SMBPASSWD'
]
quota
=
request
.
j
os
n
[
'QUOTA'
]
quota
=
request
.
j
so
n
[
'QUOTA'
]
except
:
except
:
print
"Invalid syntax"
abort
(
400
,
'Invalid syntax'
)
abort
(
400
,
'Invalid syntax'
)
# Call user creator script
# Call user creator script
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'add'
,
neptun
,
smbpasswd
,
quota
,
hard_quota
(
quota
)])
print
smbpasswd
+
" "
+
str
(
quota
)
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'add'
,
neptun
,
smbpasswd
,
str
(
quota
),
hard_quota
(
quota
)])
if
result
==
0
:
if
result
==
0
:
try
:
try
:
for
key
in
request
.
json
[
'KEYS'
]:
for
key
in
request
.
json
[
'KEYS'
]:
key_list
.
append
(
key
)
key_list
.
append
(
key
)
updateSSHAuthorizedKeys
(
neptun
,
key_list
)
updateSSHAuthorizedKeys
(
neptun
,
key_list
)
except
:
except
:
print
"SSH error"
abort
(
400
,
'SSH'
)
abort
(
400
,
'SSH'
)
return
return
elif
result
==
2
:
elif
result
==
2
:
abort
(
403
,
'User already exist!'
)
abort
(
403
,
'User already exist!'
)
else
:
else
:
print
"Error"
abort
(
400
,
'An error occured!'
)
abort
(
400
,
'An error occured!'
)
...
@@ -326,7 +331,7 @@ def upload(hash_num):
...
@@ -326,7 +331,7 @@ def upload(hash_num):
# Return hard quota from quota
# Return hard quota from quota
def
hard_quota
(
quota
):
def
hard_quota
(
quota
):
return
str
(
int
(
quota
)
*
1.25
)
return
str
(
int
(
quota
*
1.25
)
)
# Define filebuffer for big uploads
# Define filebuffer for big uploads
def
fbuffer
(
f
,
chunk_size
=
4096
):
def
fbuffer
(
f
,
chunk_size
=
4096
):
...
...
miscellaneous/store-server/FAKEUserManager.sh
View file @
f978bdee
...
@@ -82,6 +82,10 @@ case $COMMAND in
...
@@ -82,6 +82,10 @@ case $COMMAND in
# echo $(quota -w ${USER_NAME} 2>/dev/null | tail -1 | awk '{ print $2" "$3" "$4 }')
# echo $(quota -w ${USER_NAME} 2>/dev/null | tail -1 | awk '{ print $2" "$3" "$4 }')
echo
"1916 2097152 2621440"
echo
"1916 2097152 2621440"
;;
;;
'setquota'
)
echo
"
$1
$2
$3
$4
"
>
/tmp/asd
exit
0
;;
*
)
*
)
echo
"Usage: UserManager.sh COMMAND USER PASSWORD"
echo
"Usage: UserManager.sh COMMAND USER PASSWORD"
exit
1
exit
1
...
...
one/models.py
View file @
f978bdee
...
@@ -13,7 +13,7 @@ from one.util import keygen
...
@@ -13,7 +13,7 @@ from one.util import keygen
from
school.models
import
Person
,
Group
from
school.models
import
Person
,
Group
from
datetime
import
timedelta
as
td
from
datetime
import
timedelta
as
td
from
django.db.models.signals
import
post_delete
,
pre_delete
from
django.db.models.signals
import
post_delete
,
pre_delete
from
store.api
import
StoreApi
import
subprocess
,
tempfile
,
os
,
stat
,
re
,
base64
,
struct
import
subprocess
,
tempfile
,
os
,
stat
,
re
,
base64
,
struct
...
@@ -68,6 +68,23 @@ class UserCloudDetails(models.Model):
...
@@ -68,6 +68,23 @@ class UserCloudDetails(models.Model):
def
reset_smb
(
self
):
def
reset_smb
(
self
):
self
.
smb_password
=
pwgen
()
self
.
smb_password
=
pwgen
()
def
set_quota
(
sender
,
instance
,
created
,
**
kwargs
):
if
not
StoreApi
.
userexist
(
instance
.
user
.
username
):
try
:
password
=
instance
.
smb_password
quota
=
instance
.
disk_quota
*
1024
key_list
=
[]
for
key
in
instance
.
user
.
sshkey_set
.
all
():
key_list
.
append
(
key
.
key
)
except
:
pass
#Create user
if
not
StoreApi
.
createuser
(
instance
.
user
.
username
,
password
,
key_list
,
quota
):
pass
else
:
StoreApi
.
set_quota
(
instance
.
user
.
username
,
instance
.
disk_quota
)
post_save
.
connect
(
set_quota
,
sender
=
UserCloudDetails
)
def
reset_keys
(
sender
,
instance
,
created
,
**
kwargs
):
def
reset_keys
(
sender
,
instance
,
created
,
**
kwargs
):
if
created
:
if
created
:
instance
.
reset_smb
()
instance
.
reset_smb
()
...
...
one/static/cloud.js
View file @
f978bdee
...
@@ -162,7 +162,14 @@ $(function() {
...
@@ -162,7 +162,14 @@ $(function() {
$
.
ajax
({
$
.
ajax
({
type
:
'POST'
,
type
:
'POST'
,
url
:
'/vm/'
+
state
+
'/'
+
id
+
'/'
,
url
:
'/vm/'
+
state
+
'/'
+
id
+
'/'
,
success
:
function
(
data
)
{}
success
:
function
(
data
,
b
,
c
)
{
if
(
state
==
"resume"
){
window
.
location
.
href
=
'/vm/show/'
+
id
+
"/"
;
}
else
{
window
.
location
.
reload
();
}
}
})
})
}
}
$
(
'#new-member'
).
click
(
function
()
{
$
(
'#new-member'
).
click
(
function
()
{
...
...
store/api.py
View file @
f978bdee
...
@@ -146,6 +146,15 @@ class StoreApi:
...
@@ -146,6 +146,15 @@ class StoreApi:
else
:
else
:
return
False
return
False
@staticmethod
@staticmethod
def
set_quota
(
neptun
,
quota
):
url
=
settings
[
'store_url'
]
+
'/quota/'
+
neptun
payload
=
json
.
dumps
({
'QUOTA'
:
quota
})
r
=
StoreApi
.
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
else
:
return
False
@staticmethod
def
userexist
(
neptun
):
def
userexist
(
neptun
):
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
url
=
settings
[
'store_url'
]
+
'/'
+
neptun
r
=
StoreApi
.
get_request
(
url
)
r
=
StoreApi
.
get_request
(
url
)
...
@@ -154,9 +163,9 @@ class StoreApi:
...
@@ -154,9 +163,9 @@ class StoreApi:
else
:
else
:
return
False
return
False
@staticmethod
@staticmethod
def
createuser
(
neptun
,
password
,
key_list
):
def
createuser
(
neptun
,
password
,
key_list
,
quota
):
url
=
settings
[
'store_url'
]
+
'/new/'
+
neptun
url
=
settings
[
'store_url'
]
+
'/new/'
+
neptun
payload
=
json
.
dumps
({
'SMBPASSWD'
:
password
,
'KEYS'
:
key_list
})
payload
=
json
.
dumps
({
'SMBPASSWD'
:
password
,
'KEYS'
:
key_list
,
'QUOTA'
:
quota
})
r
=
StoreApi
.
post_request
(
url
,
payload
)
r
=
StoreApi
.
post_request
(
url
,
payload
)
if
r
.
status_code
==
requests
.
codes
.
ok
:
if
r
.
status_code
==
requests
.
codes
.
ok
:
return
True
return
True
...
...
store/views.py
View file @
f978bdee
...
@@ -15,13 +15,14 @@ def estabilish_store_user(user):
...
@@ -15,13 +15,14 @@ def estabilish_store_user(user):
try
:
try
:
details
=
request
.
user
.
userclouddetails_set
.
all
()[
0
]
details
=
request
.
user
.
userclouddetails_set
.
all
()[
0
]
password
=
details
.
smb_password
password
=
details
.
smb_password
quota
=
details
.
disk_quota
key_list
=
[]
key_list
=
[]
for
key
in
request
.
user
.
sshkey_set
.
all
():
for
key
in
request
.
user
.
sshkey_set
.
all
():
key_list
.
append
(
key
.
key
)
key_list
.
append
(
key
.
key
)
except
:
except
:
return
HttpResponse
(
'Can not acces to django database!'
,
status_code
=
404
)
return
HttpResponse
(
'Can not acces to django database!'
,
status_code
=
404
)
#Create user
#Create user
if
not
StoreApi
.
createuser
(
user
,
password
,
key_list
):
if
not
StoreApi
.
createuser
(
user
,
password
,
key_list
,
str
(
quota
)
):
return
HttpResponse
(
'User does not exist on store! And could not create!'
)
return
HttpResponse
(
'User does not exist on store! And could not create!'
)
@login_required
@login_required
...
...
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