コード例 #1
0
def admin_login():
    """
    Login for an admin account
    """
    if g.admin is not None:
        return redirect(url_for('admin_home', admin_id=g.admin['project_id']))

    form = LoginForm(request.form)
    if form.validate_on_submit():
        # On submit, grab name & password
        project_name = form.project_name.data
        password = form.password.data

        # Try login
        db = DB()
        resp = db.auth(project_name, password)
        if resp['status'] and resp['admin']:
            session['admin_project_id'] = resp['project_id']

            admin_detail = db.get_project_detail(session['admin_project_id'])
            admin_id = admin_detail['project_id']

            return redirect(url_for('admin_home', admin_id=admin_id))
        elif not resp['admin']:
            flash('Invalid admin account!')
        else:
            flash(resp['message'])
    return render_template('admin_login.html', form=form)
コード例 #2
0
def login():
    """
    Handles project account authentication
    """
    if g.project is not None:
        return redirect(url_for('home',
                                project_name=g.project['project_name']))

    form = LoginForm(request.form)
    if form.validate_on_submit():
        # On submit, grab name & password
        project_name = form.project_name.data
        password = form.password.data

        # Try login
        db = DB()
        resp = db.auth(project_name, password)
        if resp['status']:
            session['project_id'] = resp['project_id']

            project_detail = db.get_project_detail(session['project_id'])
            project_name = project_detail['project_name']

            return redirect(url_for('home', project_name=project_name))
        else:
            flash(resp['message'])
    return render_template('login.html', form=form)
コード例 #3
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def alien_actions_steal():
    form = AlienActionStealForm()
    if form.validate_on_submit():
        DB.alien_take_human_to_ship(current_user.id, form)
        flash('Stolen.')
    return render_template("alien_actions/steal.html", form=form,
                           user=current_user)
コード例 #4
0
def create():
    """
    Page to create a new project account
    """
    form = CreateForm(request.form)
    if form.validate_on_submit():
        # On submit, grab form information
        project_name = form.project_name.data
        email = form.email.data
        password = form.password.data
        hashed_password = generate_password_hash(password)
        description = form.description.data

        # Create the account
        db = DB()
        resp = db.create(project_name,
                         password,
                         hashed_password,
                         description=description,
                         email=email)
        if resp['status']:
            flash('Project successfully created!')
            return redirect(
                url_for('admin_home', admin_id=g.admin['project_id']))
        else:
            flash(resp['message'])

    return render_template('create.html', form=form)
コード例 #5
0
ファイル: collect.py プロジェクト: danyfdz92/stack
    def run_search(self):
        """
        One-time Graph API search for historical collections
        """
        self.running = True
        while self.running:

            # First, check to see if the thread has been set to shut down. If so, break
            thread_status = self.e.isSet()
            if thread_status:
                self.c.log('Collection thread set to shut down. Shutting down.', thread=self.thread)
                self.running = False
                break

            # Loop thru each term and queries the API
            for id in self.id_list:
                since = self.params['since']
                until = self.params['until']

                # Check to see if there's a last value less than until. If so, replace b/c got cut off
                # mid collection last time
                last = self.params['last']
                if last:
                    if until is None or last < until:
                        until = last

                # Loop thru until the paging has finished
                paging_url = 'none'
                while paging_url is not None:
                    try:
                        if paging_url is not 'none':
                            resp = requests.get(paging_url)
                            resp = json.loads(resp.content)
                        else:
                            resp = self.fb.get_object_feed(id, since=since, until=until)

                        # If there is not data and no more pages, the historical search has completed, so shut down
                        if 'paging' not in resp.keys() or not resp['data']:
                            self.c.log('Historical query collection completed for term: %s.' % str(id), thread=self.thread)
                            paging_url = None
                            pass
                        # If there's data, process it
                        elif resp['data']:
                            self.on_data(resp['data'])
                            # Set the paging url for the next loop thru
                            paging_url = resp['paging']['next']

                    # On error, logs and records in DB
                    except FacebookError as e:
                        self.c.log('Query for term ID %s failed.' % str(id), thread=self.thread, level='error')

                        now = time.strftime('%Y-%m-%d %H:%M:%S')
                        self.project_db.update({'_id': ObjectId(self.collector_id)},
                            {'$push': {'error_codes': {'code': e[0]['code'], 'message': e[0]['message'], 'date': now}}})

            self.c.log('Historical query collection completed for all terms. Shutting down.', thread=self.thread)
            db = DB()
            db.set_collector_status(self.c.project_id, self.collector_id, collector_status=0)
            self.running = False
コード例 #6
0
 def decorated_function(*args, **kwargs):
     g.admin = None
     if 'admin_project_id' in session:
         db = DB()
         resp = db.get_project_detail(session['admin_project_id'])
         if resp['status']:
             g.admin = resp
     return f(*args, **kwargs)
コード例 #7
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def human_actions_escape():
    form = HumanActionEscapeForm()
    if form.validate_on_submit():
        DB.escape_from_ship(current_user.id)
        flash('You escaped.')
        return redirect(url_for(current_user.role))
    return render_template("human_actions/escape.html", form=form,
                           user=current_user)
コード例 #8
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def alien_actions_experiment():
    form = AlienActionExperimentForm()
    if form.validate_on_submit():
        # DB.alien_take_human_to_ship(current_user.id, form)
        DB.make_experiment(current_user.id, form)
        flash('Experiment done')
    return render_template("alien_actions/experiment.html", form=form,
                           user=current_user)
コード例 #9
0
def _aload_project(project_name):
    """
    Utility method to load an admin project detail if an admin is viewing their control page
    """
    db = DB()
    resp = db.stack_config.find_one({'project_name': project_name})
    g.project = db.get_project_detail(str(resp['_id']))

    session['project_id'] = str(resp['_id'])
コード例 #10
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def admin_actions_destroy_ship():
    form = AdminActionDestroyShipForm()
    ships_dict = DB.get_ships_for_crashing()
    if form.validate_on_submit():
        if form.ship.data in ships_dict:
            DB.destroy_ship(form.ship.data)
            flash('Ship was destroyed.')
        flash('Wrong ship name.')
    return render_template("admin_actions/destroy_ship.html", form=form,
                           user=current_user, ships=ships_dict)
コード例 #11
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def add_user():
    form = AdminActionAddUserForm()

    if form.validate_on_submit():
        DB.add_user(username=form.username.data,
                    password_hash=generate_password_hash(form.password.data),
                    role=form.role.data)
        flash('New user was added.')
    return render_template("admin_actions/add_user.html", form=form,
                           user=current_user)
コード例 #12
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def admin_log_excursions():
    form = AdminLogExcursionsForm()
    res = ''
    human_dict = DB.get_all_humans()
    alien_dict = DB.get_all_aliens()
    if form.validate_on_submit():
        res = DB.common_exc_and_exp_for_human_and_alien(
            human_dict[form.human.data],
            alien_dict[form.alien.data],
            form.date1.data,
            form.date2.data)
    return render_template("adm_logs/excursions.html", form=form,
                           user=current_user, res=res, 
                           humans=list(human_dict.keys()),
                           aliens=list(alien_dict.keys()))
コード例 #13
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def admin_log_alien_steals():
    form = NAndTwoDatesForm()
    res = ''
    if form.validate_on_submit():
        res = DB.aliens_that_theft_more_then_n(form.date1.data, form.date2.data, form.n.data)
    return render_template("adm_logs/alien_steals.html", form=form,
                           user=current_user, res=res)
コード例 #14
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def human_logs_experiment():
    form = NAndTwoDatesForm()
    res = ""
    if form.validate_on_submit():
        res = DB.experimented_by_n(current_user.id, form.date1.data, form.date2.data, form.n.data)
    return render_template("human_logs/experiment.html", form=form,
                           user=current_user, res=res)
コード例 #15
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def admin_log_total_steals():
    form = ShowButtonForm()
    res = []
    if form.validate_on_submit():
        res = DB.thefts_by_month()
    return render_template("adm_logs/total_steals.html", form=form,
                           user=current_user, res=res)
コード例 #16
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def human_logs_kill():
    form = TwoDatesForm()
    res=""
    if form.validate_on_submit():
        res = DB.killed_by_me(current_user.id, form.date1.data, form.date2.data)
    return render_template("human_logs/kill.html", form=form,
                           user=current_user, res=res)
コード例 #17
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def admin_log_human_steals():
    form = NAndTwoDatesForm()
    res = ''
    if form.validate_on_submit():
        res = DB.were_thefted_more_then_n_times(form.date1.data, form.date2.data, form.n.data)
    return render_template("adm_logs/human_steals.html", form=form,
                           user=current_user, res=res)
コード例 #18
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def admin_log_ships():
    form = ShowButtonForm()
    res = []
    if form.validate_on_submit():
        res = DB.get_ships_for_crashing()

    return render_template("adm_logs/ships.html", form=form, user=current_user, res=res)
コード例 #19
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def alien_logs_experiment():
    form = NAndTwoDatesForm()
    res = ''
    if form.validate_on_submit():
        res = DB.excursions_by_alien_with_more_then_n(current_user.id, form.date1.data, form.date2.data, form.n.data)
    return render_template("alien_logs/excursion.html", form=form,
                           user=current_user, res=res)
コード例 #20
0
def admin_home(admin_id):
    """
    Homepage for an admin account
    """
    project_list = []

    db = DB()
    resp = db.get_project_list()

    if resp['status']:
        for project in resp['project_list']:
            if 'admin' in list(project.keys()) and not project['admin']:
                project_list.append(project)

    return render_template('admin_home.html',
                           admin_detail=g.admin,
                           project_list=project_list)
コード例 #21
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def human_logs_steal_and_kill():
    form = ShowButtonForm()
    res = ""
    if form.validate_on_submit():
        res = DB.theft_and_killed_by_me(current_user.id)
        print(res)
    return render_template("human_logs/steal_and_kill.html", form=form,
                           user=current_user, res=res)
コード例 #22
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def human_logs_steal():
    form = NAndTwoDatesForm()
    res = ""
    if form.validate_on_submit():
        res = DB.get_all_who_theft_me_more_then_n(current_user.id, form.date1.data, form.date2.data, form.n.data)
        print(res)
    return render_template("human_logs/steal.html", form=form,
                           user=current_user, res=res)
コード例 #23
0
    def __init__(self, db_dir, n_splits=None, initialize_db=False, **kwargs):
        """
        Divides all samples in k groups of samples.
        If n_splits is None, it will generate
        Total Number of Ratings folds (Leave-One-Out) Style
        """
        self.db_dir = db_dir
        self.db = DB(db_dir=self.db_dir)
        self.total_ratings = len(self.db.ratings)
        if n_splits is None:
            self._n_splits = len(self.db.ratings)
        else:
            self._n_splits = n_splits

        self._index = 0
        self._jump_size = math.ceil(len(self.db.ratings) / self._n_splits)
        self._initialize_db = initialize_db
コード例 #24
0
 def setUp(self):
     db = DB(Config.DATABASE_URI)
     # db.create_tables()
     self.db = db
     self.ticket_json = '''{
         "message": "test_message",
         "subject": "test_subject",
         "email": "*****@*****.**"
     }'''
     self.comment_json = '''{
コード例 #25
0
ファイル: routes.py プロジェクト: LvivD/bd_human_alien
def human_actions_kill():
    form = HumanActionKillForm()
    aliens_on_ship = DB.get_info_by_user(current_user.id)[2]

    if form.validate_on_submit():
        if form.alien.data in list(aliens_on_ship.keys()):
            res = DB.human_kill_alien(current_user.id,
                                      aliens_on_ship[form.alien.data])
            if res:
                flash('Alien was killed')
                return redirect(url_for("index"))
            flash("Something wrong. Alien wasn't killed")

        else:
            flash("Wrong alien name. Alien wasn't killed")

    return render_template("human_actions/kill.html", form=form,
                           user=current_user,
                           aliens_on_ship=list(aliens_on_ship.keys()))
コード例 #26
0
def setup():
    """
    Called on a new install to setup an admin account
    """
    form = SetupForm(request.form)
    if form.validate_on_submit():
        # On submit, grab form information
        project_name = form.project_name.data
        password = form.password.data
        hashed_password = generate_password_hash(password)

        # Create the account
        db = DB()
        resp = db.create(project_name, password, hashed_password, admin=True)
        if resp['status']:
            flash('Project successfully created!')
            return redirect(url_for('index'))
        else:
            flash(resp['message'])

    return render_template('setup.html', form=form)
コード例 #27
0
def collector(project_name, network, collector_id, task_id=None):
    """
    Loads the detail / control page for a collector
    """
    # Redirects an admin back to the homepage b/c nothing is loaded into the session yet
    if g.project is None:
        flash(
            'Please navigate to the New Collector page from your homepage panel.'
        )
        return redirect(url_for('index'))

    form = ProcessControlForm(request.form)

    # Loads collector info for the page
    db = DB()
    resp = db.get_collector_detail(g.project['project_id'], collector_id)
    collector = resp['collector']

    # Loads active status
    resp = db.check_process_status(g.project['project_id'],
                                   'collect',
                                   collector_id=collector_id)
    active_status = resp['message']

    # If a start/stop/restart is in progress, display the status
    task_status = None
    if task_id:
        resp = celery.AsyncResult(task_id)
        if resp.state == 'PENDING':
            task_status = 'Collector start/shutdown still in progress...'
        else:
            task_status = 'Collector start/shutdown completed.'

    return render_template('collector.html',
                           collector=collector,
                           active_status=active_status,
                           form=form,
                           task_status=task_status)
コード例 #28
0
def collector_control(collector_id):
    """
    POST control route for collector forms
    """
    collector_form = ProcessControlForm(request.form)
    task = None

    # On form submit controls the processor
    if request.method == 'POST' and collector_form.validate():
        command = request.form['control'].lower()

        task_args = {
            'process': 'collect',
            'project': g.project,
            'collector_id': collector_id
        }

        db = DB()
        collector = db.get_collector_detail(g.project['project_id'],
                                            collector_id)
        network = collector['collector']['network']

        if command == 'start':
            task = start_daemon.apply_async(kwargs=task_args,
                                            queue='stack-start')
        elif command == 'stop':
            task = stop_daemon.apply_async(kwargs=task_args,
                                           queue='stack-stop')
        elif command == 'restart':
            task = restart_daemon.apply_async(kwargs=task_args,
                                              queue='stack-start')

        return redirect(
            url_for('collector',
                    project_name=g.project['project_name'],
                    network=network,
                    collector_id=collector_id,
                    task_id=task.task_id))
コード例 #29
0
ファイル: config.py プロジェクト: bceskavich/homepage
def insert_work():
    title = raw_input('Work item title: ')
    description = raw_input('Work item description: ')
    image_name = raw_input('Main image name: ')
    main_link = raw_input('Main link URL: ')
    priority = raw_input('Priority: ')

    tags = []
    flag = 1
    while flag:
        tag_name = raw_input('Input tag name: ')
        tag_url = raw_input('Input tag link URL: ')

        tags.append({'tag_name': tag_name, 'tag_url': tag_url})

        yn = raw_input('Add more tags? [y/n]: ')
        if yn == 'n':
            flag = 0

    doc = {
        'priority'      : priority,
        'title'         : title,
        'description'   : description,
        'image_name'    : 'http://www.ceskavich.com/static/img/' + image_name,
        'main_link'     : main_link,
        'tags'          : tags
    }

    db = DB('main', 'work')

    resp = db.insert(doc)
    if resp['status']:
        print '\n'
        print 'SUCCESS!'
    else:
        print '\n'
        print 'Oops. Something went wrong. Please try again.'
コード例 #30
0
ファイル: config.py プロジェクト: bceskavich/homepage
def insert_work():
    title = raw_input('Work item title: ')
    description = raw_input('Work item description: ')
    image_name = raw_input('Main image name: ')
    main_link = raw_input('Main link URL: ')
    priority = raw_input('Priority: ')

    tags = []
    flag = 1
    while flag:
        tag_name = raw_input('Input tag name: ')
        tag_url = raw_input('Input tag link URL: ')

        tags.append({'tag_name': tag_name, 'tag_url': tag_url})

        yn = raw_input('Add more tags? [y/n]: ')
        if yn == 'n':
            flag = 0

    doc = {
        'priority': priority,
        'title': title,
        'description': description,
        'image_name': 'http://www.ceskavich.com/static/img/' + image_name,
        'main_link': main_link,
        'tags': tags
    }

    db = DB('main', 'work')

    resp = db.insert(doc)
    if resp['status']:
        print '\n'
        print 'SUCCESS!'
    else:
        print '\n'
        print 'Oops. Something went wrong. Please try again.'
コード例 #31
0
def index():
    """
    Loads the STACK homepage w/ list of project accounts
    """
    start_workers()

    db = DB()
    resp = db.get_project_list()

    project_list = None
    admins = None

    if resp and resp['project_list']:
        project_list = resp['project_list']
        admins = [
            project for project in project_list
            if 'admin' in list(project.keys()) and project['admin'] == 1
        ]

    # Renders index of at least one admin account exists, if not calls the new install setup
    if admins:
        return render_template('index.html', project_list=project_list)
    else:
        return redirect(url_for('setup'))
コード例 #32
0
ファイル: __main__.py プロジェクト: bdosono/stack
        wrapper = sys.argv[1]
    except:
        print USAGE
        sys.exit()
    try:
        method = sys.argv[2]
    except:
        print USAGE
        sys.exit()

    if wrapper not in ['db', 'controller']:
        print USAGE
        sys.exit()

    if wrapper == 'db' and method in db_methods:
        db = DB()

        if method == 'create_project':
            """
            python __main__.py db create_project
            """

            print
            print 'Welcome to STACKS! Please fill out the following information \
                   to get started:'
            print
            print 'Project Name - one word, NO hyphens (-), underscores (_), or \
                   spaces'
            print
            print 'Email - one or more email(s) used for status reports and \
                   issue notices.'