예제 #1
0
파일: dhbox.py 프로젝트: smythp/dhbox
def kill_dhbox():
    the_next = request.form['next']
    user = request.form['user']
    DockerBackend.kill_dhbox(user)
    delete_user(user)
    flash(message='DH Box and username deleted.', category='alert-success')
    return redirect(url_for(the_next) or url_for("index"))
예제 #2
0
def start_over():
    """Delete and make a new test DH Box"""
    cleanup()
    response = DockerBackend.kill_dhbox('test')
    response = DockerBackend.kill_dhbox('test_wp')
    DockerBackend.setup_new_dhbox('test', 'password', '*****@*****.**')
    return response
예제 #3
0
파일: dhbox.py 프로젝트: DH-Box/dhbox
def user_box(the_user):
    which_user = User.query.filter(User.name == str(the_user)).first()
    if current_user.__name__ is 'AnonymousUser':
        return redirect(url_for("index"))
    if which_user is None or current_user is None:
        return redirect(url_for("index"))
    login_user(which_user)
    email_domain = which_user.email.split("@", 1)[1]
    if email_domain == 'demo.com':
        demo = True
    else:
        demo = False
    try:
        port_4000 = urllib2.urlopen(str(request.url) + '/website')
        port_4000 = True
        print "port 4000 website found"
    except Exception:
        print "no port 4000 site"
        port_4000 = False
    time_left = which_user.dhbox_duration - DockerBackend.how_long_up(which_user.name)
    time_left = DockerBackend.display_time(time_left)
    resp = make_response(render_template('dhbox.html',
                     user=the_user,
                     apps=filter(lambda app: app.get('hide', False) != True, all_apps),
                     demo=demo,
                     time_left=time_left,
                     bootstrap_container='container-fluid',
                     fixed_scroll='fixed_scroll',
                     port_4000=port_4000
                     )
                 )
    return resp
예제 #4
0
def demonstration():
    username = '******' + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
    demo_user_object = user_datastore.create_user(email=username + '@demo.com', name=username, password='******', dhbox_duration=3600)
    db.session.commit()
    login_user(demo_user_object)
    DockerBackend.demo_dhbox(username)
    return redirect('/dhbox/' + username)
예제 #5
0
파일: manage.py 프로젝트: DH-Box/dhbox
def start_over():
    """Delete and make a new test DH Box"""
    cleanup()
    response = DockerBackend.kill_dhbox('test')
    response = DockerBackend.kill_dhbox('test_wp')
    DockerBackend.setup_new_dhbox('test', 'password', '*****@*****.**')
    return response
예제 #6
0
def user_box(the_user):
    which_user = User.query.filter(User.name == str(the_user)).first()
    if current_user.__name__ is 'AnonymousUser':
        return redirect(url_for("index"))
    if which_user is None or current_user is None:
        return redirect(url_for("index"))
    login_user(which_user)
    email_domain = which_user.email.split("@", 1)[1]
    if email_domain == 'demo.com':
        demo = True
    else:
        demo = False
    try:
        port_4000 = urllib2.urlopen(str(request.url) + '/website')
        port_4000 = True
        print "port 4000 website found"
    except Exception:
        print "no port 4000 site"
        port_4000 = False
    time_left = which_user.dhbox_duration - DockerBackend.how_long_up(
        which_user.name)
    time_left = DockerBackend.display_time(time_left)
    resp = make_response(
        render_template('dhbox.html',
                        user=the_user,
                        apps=filter(lambda app: app.get('hide', False) != True,
                                    all_apps),
                        demo=demo,
                        time_left=time_left,
                        bootstrap_container='container-fluid',
                        fixed_scroll='fixed_scroll',
                        port_4000=port_4000))
    return resp
예제 #7
0
파일: dhbox.py 프로젝트: dsiercks/dhbox
def app_box(the_user, app_name):
    which_user = User.query.filter(User.name == str(the_user)).first()
    dhbox_username = which_user.name
    which_app = all_apps[app_name]
    port_info = DockerBackend.get_container_port(dhbox_username, which_app)
    hostname = DockerBackend.get_hostname()
    location = hostname + ":" + port_info
    return redirect('http://' + location)
예제 #8
0
def admin():
    containers = User.query.all()
    containers_list = []
    for container in containers:
        uptime = DockerBackend.how_long_up(container.name)
        time_left = DockerBackend.check_if_over_time(container)
        time_left = DockerBackend.display_time(time_left)
        containers_list.append({'name': container.name, 'uptime': uptime, 'time_left': time_left})
    return render_template('admin.html', containers=containers_list)
예제 #9
0
파일: dhbox.py 프로젝트: smythp/dhbox
def app_box(the_user, app_name):
    which_user = User.query.filter(User.name == str(the_user)).first()
    dhbox_username = which_user.name
    app_port = get_app(app_name)['port']
    port_info = DockerBackend.get_container_port(dhbox_username, app_port)
    hostname = DockerBackend.get_hostname()
    location = hostname + ":" + port_info
    if app_name == 'omeka':
        return redirect('http://' + location+'/admin')
    else:
        return redirect('http://' + location)
예제 #10
0
파일: dhbox.py 프로젝트: dsiercks/dhbox
def user_box(the_user):
    which_user = User.query.filter(User.name == str(the_user)).first()
    if which_user is None:
        return redirect(url_for("index"))
    if current_user.name is not which_user.name:
        return redirect(url_for("index"))
    dhbox_username = which_user.name
    port_info = DockerBackend.get_all_exposed_ports(dhbox_username)
    hostname = DockerBackend.get_hostname()
    resp = make_response(render_template('my_dhbox.html', user=the_user, apps=all_apps))
    return resp
예제 #11
0
def kill_dhbox():
    the_next = request.form.get('next')
    user = request.form.get('user')
    print(user)
    if current_user.has_role("admin"):
        pass
    elif user != current_user.name:
        # If they're not an admin and they're trying to delete a user that isn't them,
        # return a Forbidden error.
        return abort(403)
    DockerBackend.kill_and_remove_user(user)
    flash(message='DH Box and username deleted.', category='alert-success')
    return redirect(url_for(the_next) or url_for("index"))
예제 #12
0
파일: dhbox.py 프로젝트: DH-Box/dhbox
def kill_dhbox():
    the_next = request.form.get('next')
    user = request.form.get('user')
    print(user)
    if current_user.has_role("admin"):
        pass
    elif user != current_user.name:
        # If they're not an admin and they're trying to delete a user that isn't them,
        # return a Forbidden error.
        return abort(403)
    DockerBackend.kill_and_remove_user(user)
    flash(message='DH Box and username deleted.', category='alert-success')
    return redirect(url_for(the_next) or url_for("index"))
예제 #13
0
파일: dhbox.py 프로젝트: smythp/dhbox
def create_user_and_role():
    first_user = User.query.filter(User.name == str('steve')).first()
    if not first_user:
        user_email = '*****@*****.**'
        username = '******'
        user_pass = '******'
        the_user = user_datastore.create_user(email=user_email, name=username, password=user_pass)
        the_role = user_datastore.create_role(name='admin', description='The administrator')
        user_datastore.add_role_to_user(the_user, the_role)
        db.session.commit()
        try:
            is_container = DockerBackend.get_container_info(username)
            print 'already have a container'
        except Exception, e:
            the_new_dhbox = DockerBackend.setup_new_dhbox(username, user_pass, user_email)
예제 #14
0
def app_box(the_user, app_name):
    which_user = User.query.filter(User.name == str(the_user)).first()
    dhbox_username = which_user.name
    if app_name == 'wordpress':
        app_port = get_app(app_name)['port']
        port_info = DockerBackend.get_container_port(dhbox_username+'_wp', app_port)
    elif app_name == 'website':
        app_port = '4000'
        port_info = DockerBackend.get_container_port(dhbox_username, app_port)
    else:
        app_port = get_app(app_name)['port']
        port_info = DockerBackend.get_container_port(dhbox_username, app_port)
    hostname = DockerBackend.get_hostname()
    location = hostname + ":" + port_info
    return redirect('http://' + location)
예제 #15
0
파일: dhbox.py 프로젝트: sabo/dhbox
def create_user_and_role():
    first_user = User.query.filter(User.name == str('admin')).first()
    if not first_user:
        user_email = '*****@*****.**'
        username = '******'
        user_pass = app.config['ADMIN_PASS']
        the_user = user_datastore.create_user(email=user_email, name=username, password=user_pass, dhbox_duration=1000000000)
        the_role = user_datastore.create_role(name='admin', description='The administrator')
        user_datastore.add_role_to_user(the_user, the_role)
        db.session.commit()
        try:
            DockerBackend.get_container_info(username)
            print 'already have a container'
        except Exception:
            DockerBackend.setup_new_dhbox(username, user_pass, user_email)
예제 #16
0
파일: dhbox.py 프로젝트: smythp/dhbox
def new_dhbox():
    users_and_passes = []
    admins_and_passes = []
    form = request.form
    data = {key: request.form.getlist(key)[0] for key in request.form.keys()}
    for key in data:
        users_dict = key
    users_dict = ast.literal_eval(users_dict)
    users = users_dict['users']
    for user in users:
        if 'name' in user:
            if 'email' in user:  # Then is DH Box admin
                name_check = User.query.filter(User.name == user['name']).first()
                email_check = User.query.filter(User.name == user['email']).first()
                if name_check or email_check:
                    print "Username taken. Already has a DH Box."
                    return str('failure')
                admin_user = user['name']
                admin_email = user['email']
                admin_pass = user['pass']
                admin_user_object = user_datastore.create_user(email=admin_email, name=admin_user, password=admin_pass)
                db.session.commit()
                login_user(admin_user_object)
                the_new_dhbox = DockerBackend.setup_new_dhbox(admin_user, admin_pass, admin_email)
    return str('Successfully created a new DH Box.')
예제 #17
0
def new_dhbox():
    data = {key: request.form.getlist(key)[0] for key in request.form.keys()}
    for key in data:
        users_dict = key
    users_dict = ast.literal_eval(users_dict)
    users = users_dict['users']
    for user in users:
        if 'name' in user:
            if 'email' in user:  # Then is DH Box admin
                name_check = User.query.filter(User.name == user['name']).first()
                email_check = User.query.filter(User.name == user['email']).first()
                if name_check or email_check:
                    print "Username taken. Already has a DH Box."
                    return str('failure')
                admin_user = user['name']
                admin_email = user['email']
                admin_pass = user['pass']
                if user['duration'] == 'day':
                    duration = 86400
                elif user['duration'] == 'week':
                    duration = 604800
                else:
                    duration = 2592000
                # if user['duration'] == 'week':
                #     duration = 604800
                # elif user['duration'] == 'month':
                #     duration = 2592000
                # else:
                #     duration = 13148730 
                admin_user_object = user_datastore.create_user(email=user['email'], name=user['name'], password=user['pass'], dhbox_duration=duration)
                db.session.commit()
                login_user(admin_user_object)
                the_new_dhbox = DockerBackend.setup_new_dhbox(admin_user, admin_pass, admin_email)
    return str('Successfully created a new DH Box.')
예제 #18
0
파일: dhbox.py 프로젝트: dsiercks/dhbox
def demo():
    username = '******' + ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
    demo_user_object = user_datastore.create_user(email=username + '@demo.com', name=username, password='******')
    db.session.commit()
    login_user(demo_user_object)
    new_dhbox = DockerBackend.demo_dhbox(username)
    return username
예제 #19
0
def create_user_and_role():
    first_user = User.query.filter(User.name == 'admin').first()
    if not first_user:
        user_email = app.config['ADMIN_EMAIL']
        username = '******'
        user_pass = app.config['ADMIN_PASS']
        the_user = user_datastore.create_user(email=user_email, name=username, password=user_pass, dhbox_duration=1000000000)
        check_admin_role = Role.query.filter(Role.name == 'admin').first()
        if not check_admin_role:
            the_role = user_datastore.create_role(name='admin', description='The administrator')
            user_datastore.add_role_to_user(the_user, the_role)
        else:
            user_datastore.add_role_to_user(the_user, check_admin_role)
        db.session.commit()
        try:
            DockerBackend.get_container_info(username)
            print 'already have a container'
        except Exception:
            DockerBackend.setup_new_dhbox(username, user_pass, user_email)
예제 #20
0
파일: dhbox.py 프로젝트: smythp/dhbox
def user_box(the_user):
    which_user = User.query.filter(User.name == str(the_user)).first()
    if which_user is None:
        return redirect(url_for("index"))
    if current_user.name is not which_user.name:
        return redirect(url_for("index"))
    email_domain = which_user.email.split("@",1)[1]
    if email_domain == 'demo.com':
        demo = True
    else:
        demo = False
    dhbox_username = which_user.name
    port_info = DockerBackend.get_all_exposed_ports(dhbox_username)
    hostname = DockerBackend.get_hostname()
    resp = make_response(render_template('my_dhbox.html',
                                         user=the_user,
                                         apps=filter(lambda app: app.get('hide', False) != True, all_apps),
                                         demo=demo
                                         )
                         )
    return resp
예제 #21
0
파일: dhbox.py 프로젝트: sabo/dhbox
def user_box(the_user):
    which_user = User.query.filter(User.name == str(the_user)).first()
    if which_user is None:
        return redirect(url_for("index"))
    if current_user.name is not which_user.name:
        return redirect(url_for("index"))
    email_domain = which_user.email.split("@", 1)[1]
    if email_domain == 'demo.com':
        demo = True
    else:
        demo = False
    dhbox_username = which_user.name
    time_left = which_user.dhbox_duration - DockerBackend.how_long_up(which_user.name)
    time_left = DockerBackend.display_time(time_left)
    resp = make_response(render_template('my_dhbox.html',
                                         user=the_user,
                                         apps=filter(lambda app: app.get('hide', False) != True, all_apps),
                                         demo=demo,
                                         time_left=time_left
                                         )
                         )
    return resp
예제 #22
0
파일: dhbox.py 프로젝트: DH-Box/dhbox
def police():
    if os.path.isfile('dhbox-docker.db'):
        print "policing"
        users = User.query.all()
        for user in users:
            DockerBackend.check_and_kill(user)
        all_containers = DockerBackend.all_containers()
        for container in all_containers:
            try:
                time_up = DockerBackend.how_long_up(container)
                info = DockerBackend.get_container_info(container)
                name = info['Name'][1:]
                if name.startswith('demo') and time_up > 3600:
                    DockerBackend.kill_and_remove_user(name)
            except Exception, e:
                print "Tried to check container: ", container
                raise e
예제 #23
0
def police():
    if os.path.isfile('dhbox-docker.db'):
        print "policing"
        users = User.query.all()
        for user in users:
            DockerBackend.check_and_kill(user)
        all_containers = DockerBackend.all_containers()
        for container in all_containers:
            try:
                time_up = DockerBackend.how_long_up(container)
                info = DockerBackend.get_container_info(container)
                name = info['Name'][1:]
                if name.startswith('demo') and time_up > 3600:
                    DockerBackend.kill_and_remove_user(name)
            except Exception, e:
                print "Tried to check container: ", container
                raise e
예제 #24
0
파일: manage.py 프로젝트: DH-Box/dhbox

def delete_untagged():
    """Find the untagged images and remove them"""
    images = c.images()
    found = False
    for image in images:
        if image["RepoTags"] == ["<none>:<none>"]:
            found = True
            image_id = image["Id"]
            print "Deleting untagged image\nhash=", image_id
            try:
                c.remove_image(image["Id"])
            except docker.errors.APIError as error:
                print "Failed to delete image\nhash={}\terror={}", image_id, error
    if not found:
        print "Didn't find any untagged images to delete!"


@manager.command
def check_users():
    """list all usernames and emails"""
    users = dhbox.User.query.all()
    for user in users:
        print user.name
        print user.email

c = DockerBackend.attach_to_docker_client()

if __name__ == '__main__':
    manager.main()
예제 #25
0
파일: dhbox.py 프로젝트: smythp/dhbox
def admin():
    containers = DockerBackend.all_containers()
    return render_template('admin.html', containers=containers)
예제 #26
0
파일: dhbox.py 프로젝트: sabo/dhbox
                else:
<<<<<<< HEAD
                    duration = 13148730
=======
                    duration = 2592000
                # if user['duration'] == 'week':
                #     duration = 604800
                # elif user['duration'] == 'month':
                #     duration = 2592000
                # else:
                #     duration = 13148730 
>>>>>>> master
                admin_user_object = user_datastore.create_user(email=user['email'], name=user['name'], password=user['pass'], dhbox_duration=duration)
                db.session.commit()
                login_user(admin_user_object)
                the_new_dhbox = DockerBackend.setup_new_dhbox(admin_user, admin_pass, admin_email)
    return str('Successfully created a new DH Box.')


@app.route('/kill_dhbox', methods=['POST'])
@login_required
def kill_dhbox():
    the_next = request.form.get('next')
    user = request.form.get('user')
    print(user)
    if current_user.has_role("admin"):
        pass
    elif user != current_user.name:
        # If they're not an admin and they're trying to delete a user that isn't them,
        # return a Forbidden error.
        return abort(403)
예제 #27
0
def renew_admin():
    """Updates admin's DH Box to the new seed."""
    DockerBackend.replace_admin_dhbox_image()
예제 #28
0
def killctr(ctr_name):
    """Delete a container"""
    print "killing container " + ctr_name
    response = DockerBackend.kill_dhbox(ctr_name)
    return response
예제 #29
0
def clean_slate():
    """Delete all DH Boxes"""
    cleanup()
    response = DockerBackend.kill_dhbox('test')
    DockerBackend.setup_new_dhbox('test', 'password', '*****@*****.**')
    return response
예제 #30
0
파일: manage.py 프로젝트: smythp/dhbox
def cleanup():
    """Delete ALL stopped containers, unnamed images"""
    print "Deleting stopped containers"
    call("docker ps -a | grep Exit | awk '{print $1}' |  xargs docker rm", shell=True)
    print "Deleting images"
    DockerBackend.delete_untagged()
예제 #31
0
파일: manage.py 프로젝트: DH-Box/dhbox
def killctr(ctr_name):
    """Delete a container"""
    print "killing container " + ctr_name
    response = DockerBackend.kill_dhbox(ctr_name)
    return response
예제 #32
0
def delete_untagged():
    """Find the untagged images and remove them"""
    images = c.images()
    found = False
    for image in images:
        if image["RepoTags"] == ["<none>:<none>"]:
            found = True
            image_id = image["Id"]
            print "Deleting untagged image\nhash=", image_id
            try:
                c.remove_image(image["Id"])
            except docker.errors.APIError as error:
                print "Failed to delete image\nhash={}\terror={}", image_id, error
    if not found:
        print "Didn't find any untagged images to delete!"


@manager.command
def check_users():
    """list all usernames and emails"""
    users = dhbox.User.query.all()
    for user in users:
        print user.name
        print user.email


c = DockerBackend.attach_to_docker_client()

if __name__ == '__main__':
    manager.main()
예제 #33
0
파일: manage.py 프로젝트: DH-Box/dhbox
def start():
    """download seed for DH Box"""
    response = DockerBackend.download_dhbox()
    return response
예제 #34
0
파일: manage.py 프로젝트: DH-Box/dhbox
def new_seed():
    """Build new seed for DH Box"""
    response = DockerBackend.build_dhbox()
    return response
예제 #35
0
def new_seed():
    """Build new seed for DH Box"""
    response = DockerBackend.build_dhbox()
    return response
예제 #36
0
파일: manage.py 프로젝트: DH-Box/dhbox
def test():
    """Build new test DH Box"""
    response = DockerBackend.setup_new_dhbox('test', 'password', '*****@*****.**')
    return response
예제 #37
0
def start():
    """download seed for DH Box"""
    response = DockerBackend.download_dhbox()
    return response
예제 #38
0
파일: manage.py 프로젝트: DH-Box/dhbox
def clean_slate():
    """Delete all DH Boxes"""
    cleanup()
    response = DockerBackend.kill_dhbox('test')
    DockerBackend.setup_new_dhbox('test', 'password', '*****@*****.**')
    return response
예제 #39
0
def test():
    """Build new test DH Box"""
    response = DockerBackend.setup_new_dhbox('test', 'password',
                                             '*****@*****.**')
    return response
예제 #40
0
파일: manage.py 프로젝트: DH-Box/dhbox
def renew_admin():
    """Updates admin's DH Box to the new seed."""
    DockerBackend.replace_admin_dhbox_image()
예제 #41
0
파일: dhbox.py 프로젝트: jhconning/dhbox
def police():
    users = User.query.all()
    for user in users:
        DockerBackend.check_and_kill(user)