Commit cb371fc0 by Danyi Bence

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

parents 6ab6548b ba97bf0e
......@@ -39,3 +39,8 @@ nosetests.xml
*~
local_settings.py
client.crt
client.key
miscellaneous/store-server/store.config
......@@ -6,16 +6,34 @@ from bottle import route, run, request, static_file, abort, redirect, app
import json, os, shutil
import uuid
import subprocess
import ConfigParser
from pwd import getpwnam
ROOT_WWW_FOLDER='/var/www'
ROOT_BIN_FOLDER='/opt/store-server'
SITE_URL='http://store.cloud.ik.bme.hu:8080'
USER_MANAGER='UserManager.sh'
#Get configuration file
config = ConfigParser.ConfigParser()
config.read('store.config')
#ROOT_WWW_FOLDER='/var/www'
ROOT_WWW_FOLDER = config.get('store', 'root_www_folder')
#ROOT_BIN_FOLDER='/opt/store-server'
ROOT_BIN_FOLDER = config.get('store', 'root_bin_folder')
#SITE_URL='http://store.cloud.ik.bme.hu:8080'
SITE_URL = config.get('store', 'site_url')
#USER_MANAGER='UserManager.sh'
USER_MANAGER = config.get('store', 'user_manager')
#Standalone server
SITE_HOST = config.get('store', 'site_host')
SITE_PORT = config.get('store', 'site_port')
@route('/')
def index():
return "It works!"
response = "NONE"
try:
response = request.environi.get('SSL_CLIENT_VERIFY', 'NONE')
except:
pass
return "It works! SSL: "+response
#@route('/<neptun:re:[a-zA-Z0-9]{6}>', method='GET')
@route('/<neptun>', method='GET')
......@@ -270,7 +288,7 @@ def list_directory(home,path):
is_dir = 'D'
else:
is_dir = 'F'
element = { 'NAME' : item, 'TYPE' : is_dir, 'SIZE' : os.path.getsize(static_route)/1024, 'MTIME' : os.path.getmtime(static_route) }
element = { 'NAME' : item, 'TYPE' : is_dir, 'SIZE' : os.path.getsize(static_route)/1024, 'MTIME' : os.path.getmtime(static_route) }
tuplelist.append(element)
return json.dumps(tuplelist)
......@@ -279,6 +297,6 @@ def getQuotaStatus(neptun):
return output.split()
if __name__ == "__main__":
run(host='0.0.0.0', port=8080)
run(host=SITE_HOST, port=SITE_PORT)
else:
application=app()
#!/bin/bash
#
# Return values:
# 0: succesfully created
# 1: invalid syntax
# 2: user already exist
#
GRP_NAME="cloudusers"
COMMAND="$1"
USER_NAME="$2"
SMB_PASSWD="$3"
umask 022
case $COMMAND in
'add')
if [ "x${USER_NAME}" == "x" ]; then
exit 1
fi
if [ "x${SMB_PASSWD}" == "x" ]; then
exit 1
fi
#Check if user already exist
id ${USER_NAME} > /dev/null 2>&1
if [ $? == '0' ]; then
exit 2
fi
HOME_DIR="/home/${USER_NAME}/home"
mkdir -p ${HOME_DIR}
useradd --no-user-group --home ${HOME_DIR} --gid ${GRP_NAME} ${USER_NAME} >/dev/null 2>&1
adduser ${USER_NAME} ${GRP_NAME} >/dev/null 2>&1
chown ${USER_NAME}:cloudusers ${HOME_DIR} >/dev/null 2>&1
chmod 0755 ${HOME_DIR} >/dev/null 2>&1
chmod 0755 "/home/${USER_NAME}" 2>&1
#Set password to SMB_PASSWD
echo -e "${SMB_PASSWD}\n${SMB_PASSWD}\n" | passwd ${USER_NAME} >/dev/null 2>&1
#Set SMBPASSWD
# echo -e "${SMB_PASSWD}\n${SMB_PASSWD}" | (smbpasswd -a -s ${USER_NAME}) > /dev/null
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
;;
'set')
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
# echo -e "${SMB_PASSWD}\n${SMB_PASSWD}" | (smbpasswd -a -s ${USER_NAME}) > /dev/null
else
exit 2
fi
;;
'del')
id ${USER_NAME} > /dev/null 2>&1
if [ $? != '0' ]; then
exit 2
fi
# smbpasswd -x ${USER_NAME} >/dev/null 2>&1
deluser --remove-home ${USER_NAME} >/dev/null 2>&1
rmdir /home/${USER_NAME} >/dev/null 2>&1
echo "User ${USER_NAME} DELETED at `date`" >> /root/users.log
;;
'stat')
# stat=( $(quota -w ${USER_NAME} 2>/dev/null | tail -1 | awk '{ print $2" "$3" "$4 }') )
# USED_DISK=${stat[0]}
# SOFT_LIMIT=${stat[1]}
# HARD_LIMIT=${stat[3]}
case $3 in
'used')
echo $USED_DISK
;;
'soft')
echo $SOFT_LIMIT
;;
'hard')
echo $HARD_LIMIT
;;
esac
;;
'status')
# echo $(quota -w ${USER_NAME} 2>/dev/null | tail -1 | awk '{ print $2" "$3" "$4 }')
echo "1000 1000 1000"
;;
*)
echo "Usage: UserManager.sh COMMAND USER PASSWORD"
exit 1
;;
esac
from django.contrib import admin
from store.models import *
class SettingAdmin(admin.ModelAdmin):
list_display = ('key', 'value')
admin.site.register(Setting, SettingAdmin)
from django.db import models
from django.http import Http404
import json, requests, time
from modeldict import ModelDict
from store.models import settings
# Create your models here.
#TODO Handle exceptions locally
class StoreApi:
# store_url = 'https://store.cloud.ik.bme.hu'
# store_url = 'http://store.cloud.ik.bme.hu:8080'
# store_client_cert = '/opt/webadmin/cloud/client.crt'
# store_client_key = ''/opt/webadmin/cloud/client.key
# store_user = 'admin'
# store_password = 'IQu8Eice'
# ssl_auth = True
# verify_ssl = False
@staticmethod
def post_request(url, payload):
headers = {'content-type': 'application/json'}
if settings['ssl_auth'] == 'True' and settings['basic_auth'] == 'True':
r = requests.post(url, data=payload, headers=headers, \
verify = settings['verify_ssl'], \
cert=(settings['store_client_cert'], settings['store_client_key']), \
auth=(settings['store_client_user'], settings['store_client_pass'])
)
elif settings['ssl_auth'] == 'True':
r = requests.post(url, data=payload, headers=headers, \
verify = settings['verify_ssl'], \
cert=(settings['store_client_cert'], settings['store_client_key']) \
)
elif settings['basic_auth'] == 'True':
r = requests.post(url, data=payload, headers=headers, \
verify = settings['verify_ssl'], \
auth=(settings['store_client_user'], settings['store_client_pass']) \
)
else:
r = requests.post(url, data=payload, headers=headers, \
verify = settings['verify_ssl'] \
)
return r
@staticmethod
def get_request(url):
headers = {'content-type': 'application/json'}
if settings['ssl_auth'] == 'True' and settings['basic_auth'] == 'True':
r = requests.get(url, headers=headers, \
verify = settings['verify_ssl'], \
cert=(settings['store_client_cert'], settings['store_client_key']), \
auth=(settings['store_client_user'], settings['store_client_pass'])
)
elif settings['ssl_auth'] == 'True':
r = requests.get(url, headers=headers, \
verify = settings['verify_ssl'], \
cert=(settings['store_client_cert'], settings['store_client_key']) \
)
elif settings['basic_auth'] == 'True':
r = requests.get(url, headers=headers, \
verify = settings['verify_ssl'], \
auth=(settings['store_client_user'], settings['store_client_pass']) \
)
else:
r = requests.get(url, headers=headers, \
verify = settings['verify_ssl'] \
)
return r
@staticmethod
def listfolder(neptun, path):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'LIST', 'PATH' : path })
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content)
for item in tupplelist:
item['MTIME'] = time.ctime(item['MTIME'])
return tupplelist
else:
raise Http404
@staticmethod
def requestdownload(neptun, path):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'DOWNLOAD', 'PATH' : path })
r = StoreApi.post_request(url, payload)
response = json.loads(r.content)
return response['LINK']
@staticmethod
def requestupload(neptun, path):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'UPLOAD', 'PATH' : path })
headers = {'content-type': 'application/json'}
r = StoreApi.post_request(url, payload)
response = json.loads(r.content)
if r.status_code == requests.codes.ok:
return response['LINK']
else:
raise Http404
@staticmethod
def requestremove(neptun, path):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'REMOVE', 'PATH' : path })
headers = {'content-type': 'application/json'}
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def requestnewfolder(neptun, path):
url = settings['store_url']+'/'+neptun
payload = json.dumps({ 'CMD' : 'NEW_FOLDER', 'PATH' : path })
headers = {'content-type': 'application/json'}
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def userexist(neptun):
url = settings['store_url']+'/'+neptun
r = StoreApi.get_request(url)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def createuser(neptun, password, key_list):
url = settings['store_url']+'/new/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def updateauthorizationinfo(neptun, password, key_list):
url = settings['store_url']+'/set/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
r = StoreApi.post_request(url, payload)
if r.status_code == requests.codes.ok:
return True
else:
return False
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding model 'Setting'
db.create_table('store_setting', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('key', self.gf('django.db.models.fields.CharField')(max_length=32)),
('value', self.gf('django.db.models.fields.CharField')(max_length=200)),
))
db.send_create_signal('store', ['Setting'])
def backwards(self, orm):
# Deleting model 'Setting'
db.delete_table('store_setting')
models = {
'store.setting': {
'Meta': {'object_name': 'Setting'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'value': ('django.db.models.fields.CharField', [], {'max_length': '200'})
}
}
complete_apps = ['store']
\ No newline at end of file
from django.db import models
from django.http import Http404
import json, requests, time
# Create your models here.
#TODO Handle exceptions locally
class StoreApi(models.Model):
# store_url = 'https://store.cloud.ik.bme.hu'
store_url = 'http://store.cloud.ik.bme.hu:8080'
store_user = 'admin'
store_password = 'IQu8Eice'
basic_auth = True
verify_ssl = False
@staticmethod
def listfolder(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'LIST', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
tupplelist = json.loads(r.content)
for item in tupplelist:
item['MTIME'] = time.ctime(item['MTIME'])
return tupplelist
else:
raise Http404
@staticmethod
def requestdownload(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'DOWNLOAD', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
response = json.loads(r.content)
return response['LINK']
@staticmethod
def requestupload(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'UPLOAD', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
response = json.loads(r.content)
if r.status_code == requests.codes.ok:
return response['LINK']
else:
raise Http404
@staticmethod
def requestremove(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'REMOVE', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def requestnewfolder(neptun, path):
url = StoreApi.store_url+'/'+neptun
payload = json.dumps({ 'CMD' : 'NEW_FOLDER', 'PATH' : path })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def userexist(neptun):
url = StoreApi.store_url+'/'+neptun
if StoreApi.basic_auth:
r = requests.get(url, auth=(StoreApi.store_user,StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.get(url)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def createuser(neptun, password, key_list):
url = StoreApi.store_url+'/new/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
return True
else:
return False
@staticmethod
def updateauthorizationinfo(neptun, password, key_list):
url = StoreApi.store_url+'/set/'+neptun
payload = json.dumps({ 'SMBPASSWD' : password, 'KEYS' : key_list })
headers = {'content-type': 'application/json'}
if StoreApi.basic_auth:
r = requests.post(url, data=payload, headers=headers, auth=(StoreApi.store_user, StoreApi.store_password), verify=StoreApi.verify_ssl)
else:
r = requests.post(url, data=payload, headers=headers)
if r.status_code == requests.codes.ok:
return True
else:
return False
from modeldict import ModelDict
class Setting(models.Model):
key = models.CharField(max_length=32)
value = models.CharField(max_length=200)
settings = ModelDict(Setting, key='key', value='value', instances=False)
......@@ -2,7 +2,7 @@
from django.http import HttpResponse
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from store.models import StoreApi
from store.api import StoreApi
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
import os
......
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