Commit 7ea935f5 by Danyi Bence

Merge branch 'master' of ssh://giccero.cloud.ik.bme.hu/cloud

parents ed4ae8c1 630dc9d1
...@@ -71,5 +71,7 @@ site_port = 9000 ...@@ -71,5 +71,7 @@ site_port = 9000
site_url = http://${LOCAL_IP}:%(site_port)s site_url = http://${LOCAL_IP}:%(site_port)s
#User manager script (add, del, set, update) #User manager script (add, del, set, update)
user_manager = FAKEUserManager.sh user_manager = FAKEUserManager.sh
#Temporary directory
temp_dir = /tmp/dl
EOF EOF
sudo /opt/webadmin/cloud/miscellaneous/store-server/CloudStore.py >/dev/null 2>&1 & sudo /opt/webadmin/cloud/miscellaneous/store-server/CloudStore.py >/dev/null 2>&1 &
...@@ -25,6 +25,9 @@ USER_MANAGER = config.get('store', 'user_manager') ...@@ -25,6 +25,9 @@ USER_MANAGER = config.get('store', 'user_manager')
#Standalone server #Standalone server
SITE_HOST = config.get('store', 'site_host') SITE_HOST = config.get('store', 'site_host')
SITE_PORT = config.get('store', 'site_port') SITE_PORT = config.get('store', 'site_port')
#Temporary dir for tar.gz
TEMP_DIR = config.get('store', 'temp_dir')
@route('/') @route('/')
def index(): def index():
...@@ -59,21 +62,32 @@ def neptun_POST(neptun): ...@@ -59,21 +62,32 @@ def neptun_POST(neptun):
if os.path.exists(list_path) != True: if os.path.exists(list_path) != True:
abort(404, "Path not found!") abort(404, "Path not found!")
else: else:
return list_directory(home_path,list_path) return list_directory(home_path, list_path)
#DOWNLOAD LINK GENERATOR #DOWNLOAD LINK GENERATOR
elif request.json['CMD'] == 'DOWNLOAD': elif request.json['CMD'] == 'DOWNLOAD':
dl_path = home_path+'/'+request.json['PATH'] dl_path = home_path+'/'+request.json['PATH']
dl_path = os.path.realpath(dl_path) dl_path = os.path.realpath(dl_path)
if not dl_path.startswith(home_path): if not dl_path.startswith(home_path):
abort(400, 'Invalid download path.') abort(400, 'Invalid download path.')
if( os.path.isfile(dl_path) ):
dl_hash = str(uuid.uuid4()) dl_hash = str(uuid.uuid4())
if( os.path.isfile(dl_path) ):
os.symlink(dl_path, ROOT_WWW_FOLDER+'/'+dl_hash) os.symlink(dl_path, ROOT_WWW_FOLDER+'/'+dl_hash)
#Debug #Debug
#redirect('http://store.cloud.ik.bme.hu:8080/dl/'+dl_hash) #redirect('http://store.cloud.ik.bme.hu:8080/dl/'+dl_hash)
return json.dumps({'LINK' : SITE_URL+'/dl/'+dl_hash}) return json.dumps({'LINK' : SITE_URL+'/dl/'+dl_hash})
else: else:
abort(400, 'Can\'t download folder') #Tar directore in /home/user
chdir = os.path.dirname(dl_path)
folder_name = os.path.basename(dl_path)
try:
os.makedirs(TEMP_DIR+'/'+neptun, 0700)
except:
pass
temp_path = TEMP_DIR+'/'+neptun+'/'+folder_name+'.tar.gz'
with open(os.devnull, "w") as fnull:
result = subprocess.call(['/bin/tar', 'zcvf', temp_path, '-C', chdir, folder_name], stdout = fnull, stderr = fnull)
os.symlink(temp_path, ROOT_WWW_FOLDER+'/'+dl_hash)
return json.dumps({'LINK' : SITE_URL+'/dl/'+dl_hash})
#UPLOAD #UPLOAD
elif request.json['CMD'] == 'UPLOAD': elif request.json['CMD'] == 'UPLOAD':
up_path = home_path+'/'+request.json['PATH'] up_path = home_path+'/'+request.json['PATH']
...@@ -97,7 +111,7 @@ def neptun_POST(neptun): ...@@ -97,7 +111,7 @@ def neptun_POST(neptun):
if not dst_path.startswith(home_path): if not dst_path.startswith(home_path):
abort(400, 'Invalid destination path.') abort(400, 'Invalid destination path.')
if os.path.exists(src_path) == True and os.path.exists(dst_path) == True and os.path.isdir(dst_path) == True: if os.path.exists(src_path) == True and os.path.exists(dst_path) == True and os.path.isdir(dst_path) == True:
shutil.move(src_path,dst_path) shutil.move(src_path, dst_path)
return return
else: else:
#TODO #TODO
...@@ -190,7 +204,7 @@ def new_user(neptun): ...@@ -190,7 +204,7 @@ def new_user(neptun):
@route('/dl/<hash_num>', method='GET') @route('/dl/<hash_num>', method='GET')
def dl_hash(hash_num): def dl_hash(hash_num):
hash_path = ROOT_WWW_FOLDER hash_path = ROOT_WWW_FOLDER
if os.path.exists(hash_path) != True: if os.path.exists(hash_path+'/'+hash_num) != True:
abort(404, "File not found!") abort(404, "File not found!")
else: else:
filename = os.path.basename(os.path.realpath(hash_path+'/'+hash_num)) filename = os.path.basename(os.path.realpath(hash_path+'/'+hash_num))
......
...@@ -71,13 +71,11 @@ ...@@ -71,13 +71,11 @@
<td>{{ item.SIZE }}</td> <td>{{ item.SIZE }}</td>
<td>{{ item.MTIME }}</td> <td>{{ item.MTIME }}</td>
<td> <td>
{% if item.TYPE != 'D' %}
<form action="/store/" method="POST">{% csrf_token %} <form action="/store/" method="POST">{% csrf_token %}
<input type="submit" value="Download"> <input type="submit" value="Download">
<input type="hidden" name="path" value="{{ path }}"> <input type="hidden" name="path" value="{{ path }}">
<input type="hidden" name="dl" value="{{ path }}{{ item.NAME }}"> <input type="hidden" name="dl" value="{{ path }}{{ item.NAME }}">
</form> </form>
{% endif %}
</td> </td>
<td> <td>
<form action="/store/" method="POST">{% csrf_token %} <form action="/store/" method="POST">{% csrf_token %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment