示例#1
0
def explorer():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from flask import request
	
	try:
		path = request.args['path']
	except Exception:
		path = ''
	
	try:
		tool = request.args['id']
	except Exception:
		return 'invalid parameter(s)'
	
	from kernel.config import TOOLS_DIR
	from os import listdir
	from os.path import isfile, exists
	
	full_path = TOOLS_DIR + tool + '/' + path
	
	if(not exists(full_path)):
		return 'invalid path'
	
	dirs = []
	files = []

	for item in listdir(full_path):
		if isfile(full_path + '/' + item):
			files.append(item)
		else:
			dirs.append(item)
		
	if path == '/' or path == '':
		back = None
	else:
		back = path[:path.rfind('/')]
	
	from flask import render_template
	
	return render_template(
		'explorer.html',
		path = path,
		tool = tool,
		dirs = dirs,
		files = files,
		back = back
	)
示例#2
0
def explorer():
    from kernel import logged

    if not logged():
        from flask import redirect

        return redirect('/')

    from flask import request

    try:
        path = request.args['path']
    except Exception:
        path = ''

    try:
        tool = request.args['id']
    except Exception:
        return 'invalid parameter(s)'

    from kernel.config import TOOLS_DIR
    from os import listdir
    from os.path import isfile, exists

    full_path = TOOLS_DIR + tool + '/' + path

    if (not exists(full_path)):
        return 'invalid path'

    dirs = []
    files = []

    for item in listdir(full_path):
        if isfile(full_path + '/' + item):
            files.append(item)
        else:
            dirs.append(item)

    if path == '/' or path == '':
        back = None
    else:
        back = path[:path.rfind('/')]

    from flask import render_template

    return render_template('explorer.html',
                           path=path,
                           tool=tool,
                           dirs=dirs,
                           files=files,
                           back=back)
示例#3
0
文件: editor.py 项目: Mimalef/paasta
def edit():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from flask import request
	
	try:
		path = request.args['path']
		tool = request.args['id']	
	except Exception:
		return 'invalid parameter(s)'
	
	try:
		code = request.args['code']
		save = request.args['save']		
	except Exception:
		code = None
		save = None
	
	from kernel.config import TOOLS_DIR
	from os.path import exists
	
	full_path = TOOLS_DIR + tool + '/' + path
	
	if(not exists(full_path)):
		return 'invalid path'
	
	if save and code:
		f = open(full_path, 'w')
		f.write(code)
		
		from flask import redirect
		
		return redirect('/editor?id=' + tool + '&path=' + path)
	
	f = open(full_path, 'r')
	content = f.read()
	
	from flask import render_template
	
	return render_template(
		'editor.html',
		tool = tool,
		path = path,
		content = content
	)
示例#4
0
文件: create.py 项目: Mimalef/paasta
def create():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from flask import request
	
	try:
		name = request.args['name']
		create = request.args['create']
	except Exception:
		name = None
		create = None
	
	if name and create:
		from flask import session
		
		creator = session['id']
		
		tool_id = register(name, creator)
		
		if not tool_id:
			return 'error'
		
		from kernel.config import TOOLS_DIR
		
		template_folder = TOOLS_DIR + 'template/'
		new_tool_folder = TOOLS_DIR + str(tool_id) + '/'
		
		from os import mkdir
		
		mkdir(new_tool_folder)
		clone(template_folder, new_tool_folder)
		
		from flask import redirect
		
		return redirect('/explorer?id=' + str(tool_id))

	from flask import render_template
	
	return render_template(
		'create.html',
		tool = '',
		path = ''
	)
示例#5
0
def select():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from flask import request
	
	agree = None
	
	try:
		tool = request.args['id']
		
		try:
			agree = request.args['agree']
		
		except Exception:
			pass
		
	except Exception:
		return 'invalid parameter(s)'
	
	if agree:
		if registered(tool):
			from flask import redirect
			
			return redirect('/tools/' + tool)
		
		else:
			return 'Error'
	
	from kernel.models.core import tool_session, Tool
	
	license = tool_session.query(Tool.license).filter_by(id = tool).first()
	
	if not license:
		return 'Not found'
	
	from flask import render_template
	
	return render_template(
		'select.html',
		tool = tool,
		license = license
	)
示例#6
0
def tool(tool_id = None):
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	if not registered(tool_id):
		from flask import redirect
		
		return redirect('/select?id=' + str(tool_id))
	
	from kernel.config import TOOLS_DIR
	
	tool_folder = TOOLS_DIR + str(tool_id) + '/'
	template_folder = 'templates/'
	
	preload_file = open(TOOLS_DIR + 'preload.py', 'r')
	main_file = open(tool_folder + 'main.py', 'r')
	
	code = preload_file.read() + main_file.read()
	
	from subprocess import Popen, PIPE
	
	p = Popen(
		[
			'python',
			'-c ' + code,
			tool_id
		],
		stdout = PIPE,
		stderr = PIPE
	)
	output, err = p.communicate()
	
	if err:
		return '<pre>' + err + '</pre>'
	
	return output

	from flask import render_template

	return render_template(
		'tool.html',
		view = output
	)
示例#7
0
def create():
    from kernel import logged

    if not logged():
        from flask import redirect

        return redirect('/')

    from flask import request

    try:
        name = request.args['name']
        create = request.args['create']
    except Exception:
        name = None
        create = None

    if name and create:
        from flask import session

        creator = session['id']

        tool_id = register(name, creator)

        if not tool_id:
            return 'error'

        from kernel.config import TOOLS_DIR

        template_folder = TOOLS_DIR + 'template/'
        new_tool_folder = TOOLS_DIR + str(tool_id) + '/'

        from os import mkdir

        mkdir(new_tool_folder)
        clone(template_folder, new_tool_folder)

        from flask import redirect

        return redirect('/explorer?id=' + str(tool_id))

    from flask import render_template

    return render_template('create.html', tool='', path='')
示例#8
0
def explorer_create_folder():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from flask import request
	
	try:
		tool = request.args['id']
		path = request.args['path']
	except Exception:
		return 'invalid parameter(s)'
	
	try:
		name = request.args['name']
		create = request.args['name']
	except Exception:
		name = None
		create = None
	
	if name and create:
		from kernel.config import TOOLS_DIR
		from os import mkdir
		from os.path import exists
		
		new_directory = TOOLS_DIR + tool + '/' + path + '/' + name
		
		if not exists(new_directory):
			mkdir(new_directory)
		
		from flask import redirect
		
		return redirect('/explorer?id=' + tool)
	
	from flask import render_template
	
	return render_template(
		'create.html',
		tool = tool,
		path = path
	)
示例#9
0
def explorer_create_file():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from flask import request
	
	try:
		tool = request.args['id']
		path = request.args['path']
	except Exception:
		return 'invalid parameter(s)'
	
	try:
		name = request.args['name']
		create = request.args['name']
	except Exception:
		name = None
		create = None
	
	if name and create:
		from kernel.config import TOOLS_DIR
		
		new_file = TOOLS_DIR + tool + '/' + path + '/' + name
		
		open(new_file, 'w').close()
		
		from flask import redirect
		
		return redirect('/explorer?id=' + tool)
	
	from flask import render_template
	
	return render_template(
		'create.html',
		tool = tool,
		path = path
	)
示例#10
0
def home():
	from kernel import logged
	
	if not logged():
		from flask import redirect
		
		return redirect('/')
	
	from kernel.models.users import select_session, Select
	from kernel.models.users import create_session, Create
	from kernel.models.core import tool_session, Tool
	
	tool_list = []
	selects = select_session.query(Select.tool_id)
	creates = create_session.query(Create.tool_id)
	
	for i in selects:
		tool_list.append(i[0])
	
	selects = tool_session.query(Tool.id, Tool.name).filter(
		Tool.id.in_(
			tool_list
		)
	)
	
	for i in creates:
		tool_list.append(i[0])
	
	creates = tool_session.query(Tool.id, Tool.name).filter(
		Tool.id.in_(
			tool_list
		)
	)
	
	from flask import render_template
	
	return render_template(
		'home.html',
		selects = selects,
		creates = creates
	)
示例#11
0
def explorer_create_folder():
    from kernel import logged

    if not logged():
        from flask import redirect

        return redirect('/')

    from flask import request

    try:
        tool = request.args['id']
        path = request.args['path']
    except Exception:
        return 'invalid parameter(s)'

    try:
        name = request.args['name']
        create = request.args['name']
    except Exception:
        name = None
        create = None

    if name and create:
        from kernel.config import TOOLS_DIR
        from os import mkdir
        from os.path import exists

        new_directory = TOOLS_DIR + tool + '/' + path + '/' + name

        if not exists(new_directory):
            mkdir(new_directory)

        from flask import redirect

        return redirect('/explorer?id=' + tool)

    from flask import render_template

    return render_template('create.html', tool=tool, path=path)
示例#12
0
文件: gate.py 项目: Mimalef/paasta
def gate():
	from kernel import logged
	
	if logged():
		from flask import redirect
		
		return redirect('/home')
	
	from flask import request
	
	if request.method == 'POST':
		if request.form['username'] and request.form['password']:
			username = request.form['username']
			password = request.form['password']
			button = request.form['submit']
			
		else:
			return 'error'
		
		if(button == 'Register'):
			if not register(username, password):
				return 'Error'
			
			if login(username, password):
				from flask import redirect
				
				return redirect('/home')
		
		if(button == 'Login'):
			if login(username, password):
				from flask import redirect
				
				return redirect('/home')
			
			return 'Wrong Username or Password'

	from flask import render_template
	
	return render_template('gate.html')
示例#13
0
def explorer_create_file():
    from kernel import logged

    if not logged():
        from flask import redirect

        return redirect('/')

    from flask import request

    try:
        tool = request.args['id']
        path = request.args['path']
    except Exception:
        return 'invalid parameter(s)'

    try:
        name = request.args['name']
        create = request.args['name']
    except Exception:
        name = None
        create = None

    if name and create:
        from kernel.config import TOOLS_DIR

        new_file = TOOLS_DIR + tool + '/' + path + '/' + name

        open(new_file, 'w').close()

        from flask import redirect

        return redirect('/explorer?id=' + tool)

    from flask import render_template

    return render_template('create.html', tool=tool, path=path)