Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
Commit
aedd2a46
authored
Feb 09, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store-server: Added quota management
parent
fe58151d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
7 deletions
+50
-7
miscellaneous/store-server/CloudStore.py
+26
-4
miscellaneous/store-server/UserManager.sh
+24
-3
No files found.
miscellaneous/store-server/CloudStore.py
View file @
aedd2a46
...
...
@@ -65,7 +65,7 @@ def neptun_GET(neptun):
if
os
.
path
.
exists
(
home_path
)
!=
True
:
abort
(
401
,
'The requested user does not exist!'
)
else
:
statistics
=
get
QuotaStatus
(
neptun
)
statistics
=
get
_quota
(
neptun
)
return
{
'Used'
:
statistics
[
0
],
'Soft'
:
statistics
[
1
],
'Hard'
:
statistics
[
2
]}
COMMANDS
=
{}
...
...
@@ -222,6 +222,18 @@ def set_keys(neptun):
return
elif
result
==
2
:
abort
(
403
,
'User does not exist!'
)
@route
(
'/quota/<neptun>'
,
method
=
'POST'
)
@force_ssl
def
set_quota
(
neptun
):
try
:
quota
=
request
.
json
[
'QUOTA'
]
except
:
abort
(
400
,
'Wrong syntax!'
)
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'setquota'
,
neptun
,
quota
,
hard_quota
(
quota
)])
if
result
==
0
:
return
elif
result
==
2
:
abort
(
403
,
'User does not exist!'
)
@route
(
'/new/<neptun>'
,
method
=
'POST'
)
...
...
@@ -231,10 +243,11 @@ def new_user(neptun):
smbpasswd
=
''
try
:
smbpasswd
=
request
.
json
[
'SMBPASSWD'
]
quota
=
request
.
josn
[
'QUOTA'
]
except
:
abort
(
400
,
'Invalid syntax'
)
# Call user creator script
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'add'
,
neptun
,
smbpasswd
])
result
=
subprocess
.
call
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'add'
,
neptun
,
smbpasswd
,
quota
,
hard_quota
(
quota
)
])
if
result
==
0
:
try
:
for
key
in
request
.
json
[
'KEYS'
]:
...
...
@@ -311,7 +324,9 @@ def upload(hash_num):
redirect
(
redirect_address
)
#return 'Upload finished: '+file_name+' - '+str(datalength)+' Byte'
# Return hard quota from quota
def
hard_quota
(
quota
):
return
str
(
int
(
quota
)
*
1.25
)
# Define filebuffer for big uploads
def
fbuffer
(
f
,
chunk_size
=
4096
):
...
...
@@ -369,10 +384,17 @@ def file_dict(path, home):
'MTIME'
:
os
.
path
.
getmtime
(
path
),
'DIR'
:
os
.
path
.
relpath
(
os
.
path
.
dirname
(
path
),
home
)}
def
get
QuotaStatus
(
neptun
):
def
get
_quota
(
neptun
):
output
=
subprocess
.
check_output
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'status'
,
neptun
],
stderr
=
subprocess
.
STDOUT
)
return
output
.
split
()
def
set_quota
(
neptun
,
quota
):
try
:
output
=
subprocess
.
check_output
([
ROOT_BIN_FOLDER
+
'/'
+
USER_MANAGER
,
'setquota'
,
neptun
,
quota
,
hard_quota
(
quota
)],
stderr
=
subprocess
.
STDOUT
)
except
:
return
False
return
True
if
__name__
==
"__main__"
:
run
(
host
=
SITE_HOST
,
port
=
SITE_PORT
)
else
:
...
...
miscellaneous/store-server/UserManager.sh
View file @
aedd2a46
...
...
@@ -13,14 +13,20 @@ USER_NAME="$2"
SMB_PASSWD
=
"
$3
"
umask
022
case
$COMMAND
in
'add'
)
if
[
"x
${
USER_NAME
}
"
==
"x"
]
;
then
exit
1
fi
case
$COMMAND
in
'add'
)
if
[
"x
${
SMB_PASSWD
}
"
==
"x"
]
;
then
exit
1
fi
if
[
"x
${
SOFT_QUOTA
}
"
==
"x"
]
;
then
exit
1
fi
if
[
"x
${
HARD_QUOTA
}
"
==
"x"
]
;
then
exit
1
fi
#Check if user already exist
id
${
USER_NAME
}
>
/dev/null 2>&1
if
[
$?
==
'0'
]
;
then
...
...
@@ -40,9 +46,13 @@ case $COMMAND in
echo
"User
${
USER_NAME
}
CREATED at
`
date
`
"
>>
/root/users.log
#Set quotas
# Username Soft Hard Inode Dev
setquota
${
USER_NAME
}
2097152 2621440 0 0 /home
# setquota ${USER_NAME} 2097152 2621440 0 0 /home
setquota
${
USER_NAME
}
${
SOFT_QUOTA
}
${
HARD_QUOTA
}
0 0 /home
;;
'set'
)
if
[
"x
${
SMB_PASSWD
}
"
==
"x"
]
;
then
exit
1
fi
id
${
USER_NAME
}
>
/dev/null 2>&1
if
[
$?
==
'0'
]
;
then
echo
-e
"
${
SMB_PASSWD
}
\n
${
SMB_PASSWD
}
\n
"
| passwd
${
USER_NAME
}
>
/dev/null 2>&1
...
...
@@ -81,6 +91,17 @@ case $COMMAND in
'status'
)
echo
$(
quota
-w
${
USER_NAME
}
2>/dev/null | tail
-1
| awk
'{ print $2" "$3" "$4 }'
)
;;
'setquota'
)
SOFT_QUOTA
=
"
$3
"
HARD_QUOTA
=
"
$4
"
if
[
"x
${
SOFT_QUOTA
}
"
==
"x"
]
;
then
exit
1
fi
if
[
"x
${
HARD_QUOTA
}
"
==
"x"
]
;
then
exit
1
fi
setquota
${
USER_NAME
}
${
SOFT_QUOTA
}
${
HARD_QUOTA
}
0 0 /home
;;
*
)
echo
"Usage: UserManager.sh COMMAND USER PASSWORD"
exit
1
...
...
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