Esempio n. 1
0
def home():

    if check_login():

        s = get_session()

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        t = PTemplate(env)

        conn = WebModel.connection()

        content_index = admin(t=t, connection=conn)

        if t.show_basic_template == True:

            return t.load_template('admin/content.html',
                                   title='Servers',
                                   content_index=content_index,
                                   menu=menu,
                                   lang_selected=lang_selected,
                                   arr_i18n=I18n.dict_i18n)
        else:

            return content_index

    else:
        redirect(make_url(config.admin_folder))
Esempio n. 2
0
def base_admin(func_view, env, title, **args):
    
    env.directories.insert(1, config.paramecio_root+'/modules/admin/templates')
    
    content_index=''

    connection=WebModel.connection()
    #Fix, make local variable
    
    t=PTemplate(env)
    
    s=get_session()
    
    if check_login():
                
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)
    
        lang_selected=get_language(s)
        
        content_index=func_view(connection, t, s, **args)

        return t.load_template('admin/content.html', title=title, content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        
    else:
        redirect(make_url(config.admin_folder))
Esempio n. 3
0
def home():
    
    if check_login():
        
        s=get_session()
        
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)

        lang_selected=get_language(s)
        
        t=PTemplate(env)
    
        conn=WebModel.connection()
        
        content_index=admin(t=t, connection=conn)
        
        if t.show_basic_template==True:

            return t.load_template('admin/content.html', title='Servers', content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        else:
            
            return content_index
        
    else:
        redirect(make_url(config.admin_folder))
Esempio n. 4
0
def home():

    connection = WebModel.connection()
    #Fix, make local variable

    t = PTemplate(env)

    s = get_session()

    if check_login():

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        content_index = t.load_template('pastafari/dashboard.phtml')

        return t.load_template('admin/content.html',
                               title='Dashboard',
                               content_index=content_index,
                               menu=menu,
                               lang_selected=lang_selected,
                               arr_i18n=I18n.dict_i18n)

    else:
        redirect(make_url(config.admin_folder))
Esempio n. 5
0
def home():
    
    if check_login():
        
        s=get_session()
        
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)

        lang_selected=get_language(s)
        
        t=PTemplate(env)
    
        conn=WebModel.connection()
        
        url=make_url(pastafari_folder+'/os')
        
        os=servers.OsServer(conn)
        
        admin=GenerateAdminClass(os, url, t)
        
        admin.list.fields_showed=['name', 'codename']
        
        admin.list.s['order']='0'
        admin.list.s['order_field']='name'
        
        admin.list.yes_search=False
        
        content_index=admin.show()

        return t.load_template('admin/content.html', title='Os Servers', content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        
    else:
        redirect(make_url(config.admin_folder))
Esempio n. 6
0
def showprogress(task_id, server):

    # Need check the server

    t = PTemplate(env)

    conn = WebModel.connection()

    s = get_session()

    if check_login():

        content_index = ''

        conn = WebModel.connection()
        task = Task(conn)

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        arr_task = task.select_a_row(task_id)

        if arr_task:

            server_model = Server(conn)

            server_model.set_conditions('where ip=%s', [server])

            arr_server = server_model.select_a_row_where()

            if arr_server:

                #arr_task=

                content_index = t.load_template(
                    'pastafari/progress.phtml',
                    name_task=arr_task['name_task'] + ' - ' +
                    arr_server['hostname'],
                    description_task=arr_task['description_task'],
                    task_id=task_id,
                    server=server,
                    position=0)
        conn.close()
        return t.load_template('admin/content.html',
                               title='Servers log',
                               content_index=content_index,
                               menu=menu,
                               lang_selected=lang_selected,
                               arr_i18n=I18n.dict_i18n)

    else:
        conn.close()
        return ""
Esempio n. 7
0
def check_code_token():
    
    t=PTemplate(env)
    
    if yes_recovery_login==True:
    
        getpost=GetPostFiles()
        
        getpost.obtain_post()
        
        connection=WebModel.connection()
    
        user_admin=UserAdmin(connection)
        
        token=getpost.post.get('token',  '')
        
        token=user_admin.fields['token_recovery'].check(token)
    
        if token.strip()!='':
            
            user_admin.set_conditions('WHERE token_recovery=%s', [token])
            
            user_admin.yes_reset_conditions=False
            
            arr_user=user_admin.select_a_row_where(['id', 'email'])
            
            if arr_user:
                
                new_password=create_key()
                           
                user_admin.valid_fields=['password', 'token_recovery', 'num_tries']

                user_admin.reset_require()
                
                user_admin.check_user=False
                
                if user_admin.update({'password': new_password, 'token_recovery': "", 'num_tries': 0}, False):
                    
                    send_mail=SendMail()
                    
                    content_mail=t.load_template('admin/recovery_password.phtml', password=new_password)
                    
                    if not send_mail.send(email_address, [arr_user['email']], I18n.lang('admin', 'send_password_email', 'Your new password'), content_mail):
                        return {'token': 'Error: i cannot send mail', 'error': 1}
                    
                    return {'token': 'Error: cannot send the maild with the new password', 'error': 0} 
    
    s=get_session()
                
    s['csrf_token']=create_key_encrypt()
    
    s.save()
    
    return {'token': 'Error: token is not valid', 'error': 1,  'csrf_token': s['csrf_token']}
Esempio n. 8
0
def send_password():
    
    connection=WebModel.connection()
    
    user_admin=UserAdmin(connection)
    
    t=PTemplate(env)
    
    getpost=GetPostFiles()
    
    getpost.obtain_post()
    
    email=getpost.post.get('email',  '')
    
    email=user_admin.fields['email'].check(email)
    
    if user_admin.fields['email'].error:
        
        s=get_session()
                
        s['csrf_token']=create_key_encrypt()
        
        s.save()
        
        return {'email': user_admin.fields['email'].txt_error, 'error': 1, 'csrf_token': s['csrf_token']}
        
    else:
        
        user_admin.set_conditions('WHERE email=%s', [email])
        
        user_admin.yes_reset_conditions=False
        
        if user_admin.select_count()==1:
            
            user_admin.reset_require()
            
            user_admin.valid_fields=['token_recovery']
            
            user_admin.check_user=False
            
            token=create_key_encrypt_256()
            
            if user_admin.update({'token_recovery': token}):
                
                send_mail=SendMail()
                
                content_mail=t.load_template('admin/recovery_mail.phtml', token=token)
                
                if not send_mail.send(email_address, [email], I18n.lang('admin', 'send_email', 'Email for recovery your password'), content_mail):
                    return {'email': 'Error: i cannot send mail', 'error': 1}
                
            
        return {'email': '', 'error': 0}
Esempio n. 9
0
def recovery_password():
    
    t=PTemplate(env)
    
    connection=WebModel.connection()
    
    user_admin=UserAdmin(connection)
    
    post={}
    
    user_admin.create_forms(['email'])
    
    forms=show_form(post, user_admin.forms, t, yes_error=False)
    
    #connection.close()
    
    return t.load_template('admin/recovery.phtml', forms=forms)
Esempio n. 10
0
def graphs(server_id):

    if check_login():

        s = get_session()

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        t = PTemplate(env)

        conn = WebModel.connection()

        server = servers.Server(conn)

        arr_server = server.select_a_row(server_id)

        if arr_server:

            content_index = t.load_template('pastafari/admin/graphs.phtml',
                                            server=arr_server,
                                            api_key=config_task.api_key)

        else:

            content_index = ''

        if t.show_basic_template == True:

            return t.load_template('admin/content.html',
                                   title='Servers',
                                   content_index=content_index,
                                   menu=menu,
                                   lang_selected=lang_selected,
                                   arr_i18n=I18n.dict_i18n)
        else:

            return content_index

    else:
        redirect(make_url(config.admin_folder))
Esempio n. 11
0
def showprogress(task_id, server):
    
    # Need check the server
    
    t=PTemplate(env)
    
    conn=WebModel.connection()
    
    s=get_session()
    
    if check_login():
            
        content_index=''
        
        conn=WebModel.connection()
        task=Task(conn)
        
        menu=get_menu(config_admin.modules_admin)
        
        lang_selected=get_language(s)           
        
        arr_task=task.select_a_row(task_id)
        
        if arr_task:
            
            server_model=Server(conn)
            
            server_model.set_conditions('where ip=%s', [server])
            
            arr_server=server_model.select_a_row_where()
            
            if arr_server:
            
                #arr_task=
                
                content_index=t.load_template('pastafari/progress.phtml', name_task=arr_task['name_task']+' - '+arr_server['hostname'], description_task=arr_task['description_task'], task_id=task_id, server=server, position=0)
        conn.close()
        return t.load_template('admin/content.html', title='Servers log', content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)    
            
    else:
        conn.close()
        return ""
Esempio n. 12
0
def home():

    if check_login():

        s = get_session()

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        t = PTemplate(env)

        conn = WebModel.connection()

        url = make_url(pastafari_folder + '/os')

        os = servers.OsServer(conn)

        admin = GenerateAdminClass(os, url, t)

        admin.list.fields_showed = ['name', 'codename']

        admin.list.s['order'] = '0'
        admin.list.s['order_field'] = 'name'

        admin.list.yes_search = False

        content_index = admin.show()

        return t.load_template('admin/content.html',
                               title='Os Servers',
                               content_index=content_index,
                               menu=menu,
                               lang_selected=lang_selected,
                               arr_i18n=I18n.dict_i18n)

    else:
        redirect(make_url(config.admin_folder))
Esempio n. 13
0
def graphs(server_id):
    
    if check_login():
        
        s=get_session()
        
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)

        lang_selected=get_language(s)
        
        t=PTemplate(env)
    
        conn=WebModel.connection()
        
        server=servers.Server(conn)
        
        arr_server=server.select_a_row(server_id)
    
        if arr_server:
        
            content_index=t.load_template('pastafari/admin/graphs.phtml', server=arr_server, api_key=config_task.api_key)
            
        else:
            
            content_index=''

        
        if t.show_basic_template==True:

            return t.load_template('admin/content.html', title='Servers', content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        else:
            
            return content_index
        
    else:
        redirect(make_url(config.admin_folder))
Esempio n. 14
0
def home():
    
    connection=WebModel.connection()
    #Fix, make local variable
    
    t=PTemplate(env)
    
    s=get_session()
    
    if check_login():
                
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)
    
        lang_selected=get_language(s)
        
        content_index=t.load_template('pastafari/dashboard.phtml')

        return t.load_template('admin/content.html', title='Dashboard', content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        
    else:
        redirect(make_url(config.admin_folder))
Esempio n. 15
0
def home():
    
    connection=WebModel.connection()
    #Fix, make local variable
    
    t=PTemplate(env)
    
    getpost=GetPostFiles()            
    
    getpost.obtain_get()
    
    try:
        group_id=int(getpost.get.get('group_id', '0'))
    except:
        group_id=0

    if request_type()=='POST':
        getpost.obtain_post()
    
    s=get_session()
    
    if 'login' in s:
        
        if s['privileges']==2:
            
            task=Task(connection)
            logtask=LogTask(connection)
            server=Server(connection)
            
            #Load menu
            
            menu=get_menu(config_admin.modules_admin)
        
            lang_selected=get_language(s)
            
            content_index=''
            
            # Send request to server
            
            arr_servers=[]
            
            where_sql='WHERE num_updates>0'
            
            for server_id in getpost.post.values():
                
                try:
                    server_id=int(server_id)
                    
                    if server_id>0:
                        arr_servers.append(str(server_id))
                except:
                    pass
            
            if len(arr_servers)>0:
                where_sql='WHERE id IN (%s)' % ",".join(arr_servers)
            
            if group_id>0:
                where_sql+=' AND id IN (select server_id from servergroupitem where group_id='+str(group_id)+')'
            
            commands_to_execute=[['bin/upgrade.sh', '']]
            
            task.create_forms()
            
            if task.insert({'name_task': 'update_server','description_task': I18n.lang('pastafari', 'update_servers', 'Updating servers...'), 'url_return': '', 'commands_to_execute': commands_to_execute, 'server': '', 'where_sql_server': where_sql}):
                                                
                task_id=task.insert_id()
                                
                try:
                
                    r=requests.get(server_task+str(task_id))
                    
                    arr_data=r.json()
                    
                    arr_data['task_id']=task_id
                    
                    logtask.create_forms()
                    
                    if not logtask.insert(arr_data):
                        
                        content_index="Error:Wrong format of json data..."
                        
                        #return t_admin.load_template('pastafari/ajax_progress.phtml', title='Adding monitoritation to the server...') #"Load template with ajax..."
                    else:
                        
                        server.set_conditions(where_sql, [])
                        
                        num_servers=server.select_count()
                        
                        #content_index=t.load_template('pastafari/updates.phtml', task_id=task_id, title_task=I18n.lang('pastafari', 'servers_updating', 'Servers updating'), num_servers=num_servers)
                        content_index=t.load_template('pastafari/updates.phtml', task_id=task_id, title_task=I18n.lang('pastafari', 'servers_updating', 'Servers updating'), description_task=I18n.lang('pastafari', 'servers_updating_txt', 'All servers selected will be updated...'), num_servers=num_servers)
                
                except:
                    
                    #logtask.conditions=['WHERE id=%s', [task_id]]
                    
                    task.update({'status': 1, 'error': 1})
                    
                    content_index="Error:cannot connect to task server, check the url for it..."+traceback.format_exc()
                    
            else:
                content_index="Error: cannot insert the task: "+task.show_errors()

            return t.load_template('admin/content.html', title='Updating servers', content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
            
        else:
            redirect(make_url(config.admin_folder))
    
    else:
    
        redirect(make_url(config.admin_folder))
Esempio n. 16
0
def home():
    
    t=PTemplate(env)

    return t.load_template('welcome.html', title="Welcome to Paramecio!!!", content="The simple web framework writed in Python3!!!")
Esempio n. 17
0
def page(id):
    
    t=PTemplate(env)
    
    return t.load_template('index.html', title="A simple example of a page", id=id, value=request.query.value)
Esempio n. 18
0
def gettasks():
    
    if check_login():
        
        s=get_session()
        
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)

        lang_selected=get_language(s)
        
        t=PTemplate(env)
    
        conn=WebModel.connection()

        getpostfiles=GetPostFiles()

        getpostfiles.obtain_get()
        
        getpostfiles.get['op']=getpostfiles.get.get('op', '')
        getpostfiles.get['task_id']=getpostfiles.get.get('task_id', '0')
        getpostfiles.get['position']=getpostfiles.get.get('position', '0')
        getpostfiles.get['server']=getpostfiles.get.get('server', '')
        
        try:
        
            task_id=int(getpostfiles.get['task_id'])
        except:
            task_id=0
            
        try:
            position=int(getpostfiles.get['position'])
        except:
            position=0
        
        task=Task(conn)
        logtask=LogTask(conn)
        
        arr_task=task.select_a_row(task_id)
        
        t.show_basic_template=False
        
        arr_rows={'wait': 1}
        
        if arr_task:
            
            logtask.set_limit([position, 20])
                
            logtask.set_order({'id': 0})
            
            logtask.conditions=['WHERE task_id=%s', [task_id]]
            
            if getpostfiles.get['server']!='':
                logtask.conditions=['WHERE task_id=%s and logtask.server=%s', [task_id, getpostfiles.get['server']]]
                
            #logtask.set_limit([position, 1])
            
            #arr_row=logtask.select_a_row_where([], 1, position)
            
            logtask.yes_reset_conditions=False
            
            c=logtask.select_count()
            
            if c>0:
                
                arr_rows=[]
                
                with logtask.select([], True) as cursor:            
                    for arr_row in cursor:
                        arr_rows.append(arr_row)
                
            else:
                arr_rows=[]
                
                with logtask.set_conditions('WHERE task_id=%s and logtask.error=1', [task_id]).select([], True) as cursor:            
                    for arr_row in cursor:
                        arr_rows.append(arr_row)

                if arr_rows==0:
                    
                    arr_rows={'wait': 1}
                else:

                    with logtask.set_conditions('WHERE task_id=%s and logtask.server=%s and logtask.error=1', [task_id, getpostfiles.get['server']]).select([], True) as cursor:            
                        for arr_row in cursor:
                            arr_rows.append(arr_row)
                    
            """
                
                arr_rows=[]
                
                with logtask.select() as cursor:            
                    for arr_row in cursor:
                        arr_rows.append(arr_row)
                
                if len(arr_rows)==0:
                    logtask.set_limit([1])
                
                    logtask.set_order({'id': 0})
                    
                    logtask.conditions=['WHERE task_id=%s and status=1 and error=1  and server=""', [task_id]]
                    
                    if logtask.select_count('id', True)==0:
                        
                        if arr_task['status']=='0' or arr_task['status']==0:
                            conn.close()
                            return filter_ajax({'wait': 1})
                        else:
                            conn.close()
                            return filter_ajax({})
                    else:
                        
                        logtask.set_limit([1])
                    
                        logtask.set_order({'id': 0})
                        
                        logtask.conditions=['WHERE task_id=%s and status=1 and error=1  and server=""', [task_id]]
                        
                        arr_rows=logtask.select_to_array([], True)
                
                #response.set_header('Content-type', 'text/plain')
                conn.close()
                return filter_ajax(arr_rows)
                
            else:
                conn.close()
                return filter_ajax({'wait': 1})
            """
                    
        else:
            
            arr_task={'task_id': task_id, 'progress': 100, 'message': 'Error: no exists task', 'error': 1, 'status': 1}
            
        conn.close()
        
        return filter_ajax(arr_rows)

        
        
    else:

        redirect(make_url(config.admin_folder))
Esempio n. 19
0
def home(server_id, task_id):
    
    connection=WebModel.connection()
    #Fix, make local variable
    
    t=PTemplate(env)
    
    s=get_session()
    
    if check_login():
                
        task=Task(connection)
        logtask=LogTask(connection)
        server=Server(connection)
        
        getpost=GetPostFiles() 
        
        getpost.obtain_get()
        
        #Load menu
            
        menu=get_menu(config_admin.modules_admin)
    
        lang_selected=get_language(s)           
        
        # server_id=getpost.get.get('id', 0)
        
        server_hostname=''
        
        arr_server=server.select_a_row(server_id)
        
        if arr_server:
            
            server_hostname=' - '+arr_server['hostname']
        
            ip=arr_server['ip']
            
            logtask.set_conditions('WHERE server=%s', [ip])
            
            logtask_list=SimpleList(logtask, make_url(pastafari_folder+'/serverslogs', {'id':str(server_id) }), t)
            
            logtask_list.limit_pages=100
            
            logtask_list.yes_search=False
            
            logtask_list.order_field='id'
            logtask_list.order=1
            
            logtask_list.fields_showed=['id', 'server', 'message', 'error', 'status']
            
            logtask_list.arr_extra_fields=[]
            logtask_list.arr_extra_options=[]
            
            return_url=make_url('pastafari/servers')
            
            content_index=t.load_template('pastafari/admin/logs_list.phtml', logtask_list=logtask_list, server=arr_server, return_url=return_url)
            #logtask_list.show()
            
            # Send request to server
                           
        else:
        
            content_index='Log no exists'
            
        connection.close()
        return t.load_template('admin/content.html', title='Servers log'+ server_hostname, content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        
    else:
        connection.close()
        redirect(make_url(config.admin_folder))
Esempio n. 20
0
def gettasks():

    if check_login():

        s = get_session()

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        t = PTemplate(env)

        conn = WebModel.connection()

        getpostfiles = GetPostFiles()

        getpostfiles.obtain_get()

        getpostfiles.get['op'] = getpostfiles.get.get('op', '')
        getpostfiles.get['task_id'] = getpostfiles.get.get('task_id', '0')
        getpostfiles.get['position'] = getpostfiles.get.get('position', '0')
        getpostfiles.get['server'] = getpostfiles.get.get('server', '')

        try:

            task_id = int(getpostfiles.get['task_id'])
        except:
            task_id = 0

        try:
            position = int(getpostfiles.get['position'])
        except:
            position = 0

        task = Task(conn)
        logtask = LogTask(conn)

        arr_task = task.select_a_row(task_id)

        t.show_basic_template = False

        arr_rows = {'wait': 1}

        if arr_task:

            logtask.set_limit([position, 20])

            logtask.set_order({'id': 0})

            logtask.conditions = ['WHERE task_id=%s', [task_id]]

            if getpostfiles.get['server'] != '':
                logtask.conditions = [
                    'WHERE task_id=%s and logtask.server=%s',
                    [task_id, getpostfiles.get['server']]
                ]

            #logtask.set_limit([position, 1])

            #arr_row=logtask.select_a_row_where([], 1, position)

            logtask.yes_reset_conditions = False

            c = logtask.select_count()

            if c > 0:

                arr_rows = []

                with logtask.select([], True) as cursor:
                    for arr_row in cursor:
                        arr_rows.append(arr_row)

            else:
                arr_rows = []

                with logtask.set_conditions(
                        'WHERE task_id=%s and logtask.error=1',
                    [task_id]).select([], True) as cursor:
                    for arr_row in cursor:
                        arr_rows.append(arr_row)

                if arr_rows == 0:

                    arr_rows = {'wait': 1}
                else:

                    with logtask.set_conditions(
                            'WHERE task_id=%s and logtask.server=%s and logtask.error=1',
                        [task_id, getpostfiles.get['server']]).select(
                            [], True) as cursor:
                        for arr_row in cursor:
                            arr_rows.append(arr_row)
            """
                
                arr_rows=[]
                
                with logtask.select() as cursor:            
                    for arr_row in cursor:
                        arr_rows.append(arr_row)
                
                if len(arr_rows)==0:
                    logtask.set_limit([1])
                
                    logtask.set_order({'id': 0})
                    
                    logtask.conditions=['WHERE task_id=%s and status=1 and error=1  and server=""', [task_id]]
                    
                    if logtask.select_count('id', True)==0:
                        
                        if arr_task['status']=='0' or arr_task['status']==0:
                            conn.close()
                            return filter_ajax({'wait': 1})
                        else:
                            conn.close()
                            return filter_ajax({})
                    else:
                        
                        logtask.set_limit([1])
                    
                        logtask.set_order({'id': 0})
                        
                        logtask.conditions=['WHERE task_id=%s and status=1 and error=1  and server=""', [task_id]]
                        
                        arr_rows=logtask.select_to_array([], True)
                
                #response.set_header('Content-type', 'text/plain')
                conn.close()
                return filter_ajax(arr_rows)
                
            else:
                conn.close()
                return filter_ajax({'wait': 1})
            """

        else:

            arr_task = {
                'task_id': task_id,
                'progress': 100,
                'message': 'Error: no exists task',
                'error': 1,
                'status': 1
            }

        conn.close()

        return filter_ajax(arr_rows)

    else:

        redirect(make_url(config.admin_folder))
Esempio n. 21
0
def home(server_id, task_id):

    connection = WebModel.connection()
    #Fix, make local variable

    t = PTemplate(env)

    s = get_session()

    if check_login():

        task = Task(connection)
        logtask = LogTask(connection)
        server = Server(connection)

        getpost = GetPostFiles()

        getpost.obtain_get()

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        # server_id=getpost.get.get('id', 0)

        server_hostname = ''

        arr_server = server.select_a_row(server_id)

        if arr_server:

            server_hostname = ' - ' + arr_server['hostname']

            ip = arr_server['ip']

            logtask.set_conditions('WHERE server=%s', [ip])

            logtask_list = SimpleList(
                logtask,
                make_url(pastafari_folder + '/serverslogs',
                         {'id': str(server_id)}), t)

            logtask_list.limit_pages = 100

            logtask_list.yes_search = False

            logtask_list.order_field = 'id'
            logtask_list.order = 1

            logtask_list.fields_showed = [
                'id', 'server', 'message', 'error', 'status'
            ]

            logtask_list.arr_extra_fields = []
            logtask_list.arr_extra_options = []

            return_url = make_url('pastafari/servers')

            content_index = t.load_template('pastafari/admin/logs_list.phtml',
                                            logtask_list=logtask_list,
                                            server=arr_server,
                                            return_url=return_url)
            #logtask_list.show()

            # Send request to server

        else:

            content_index = 'Log no exists'

        connection.close()
        return t.load_template('admin/content.html',
                               title='Servers log' + server_hostname,
                               content_index=content_index,
                               menu=menu,
                               lang_selected=lang_selected,
                               arr_i18n=I18n.dict_i18n)

    else:
        connection.close()
        redirect(make_url(config.admin_folder))
Esempio n. 22
0
if hasattr(config, 'pastafari_folder'):
    pastafari_folder = config.pastafari_folder

num_updated_servers = 2

if hasattr(config, 'num_updated_servers'):
    num_updated_servers = config.num_updated_servers

load_lang(['paramecio', 'admin'], ['paramecio', 'common'])

env = env_theme(__file__)

env.directories.insert(1, config.paramecio_root + '/modules/admin/templates')

t = PTemplate(env)

# Server tasks list


@app.get('/' + pastafari_folder + '/tasklist/<server_id:int>')
def tasklist(server_id):

    content_index = ''

    if check_login():

        conn = WebModel.connection()

        server = Server(conn)
Esempio n. 23
0
def home(module='', submodule=''):
    
    # A simple boolean used for show or not the code of admin module in standard template
    connection=WebModel.connection()
    #Fix, make local variable
    
    t=PTemplate(env)
    
    t.add_filter(make_admin_url)
    
    t.show_basic_template=True
    
    if submodule!='':
        module+='/'+submodule
    
    #t.clean_header_cache()
    
    #check if login
    
    user_admin=UserAdmin(connection)
    
    s=get_session()
    
    if check_login():
        
        s['id']=s.get('id', 0)
        
        lang_selected=get_language(s)
        
        user_admin.set_conditions('WHERE id=%s', [s['id']])
        
        # Check if user id exists in session
        
        c=user_admin.select_count()
        
        if c>0:
        
            if s['privileges']==2:
                            #pass
                        
                if module in menu:
                    
                    #Load module
                    
                    
                    try:
                        #new_module=import_module(menu[module][1])
                        
                        #t.inject_folder=path.dirname(new_module.__file__).replace('/admin', '')
                        
                        #t.env=t.env_theme(path.dirname(__file__))
                        
                        t.env.directories.insert(1, path.dirname(module_imported[module].__file__).replace('/admin', '')+'/templates')
                        #print(t.env.directories)
                        #if config.reloader:
                            #reload(new_module)
                    
                    except ImportError:
                        
                        print("Exception in user code:")
                        print("-"*60)
                        traceback.print_exc(file=sys.stdout)
                        print("-"*60)
                        
                        return "No exists admin module"
                    
                    #args={'t': t, 'connection': connection}

                    content_index=module_imported[module].admin(t=t, connection=connection)

                    if t.show_basic_template==True:   
                    
                        return t.load_template('admin/content.html', title=menu[module][0], content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
                    else:
                        
                        return content_index
                        
                else:
                    return t.load_template('admin/index.html', title=I18n.lang('admin', 'welcome_to_paramecio', 'Welcome to Paramecio Admin!!!'), menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
                
        else:
            
            logout()
            
    else:
        
        user_admin.conditions=['WHERE privileges=%s', [2]]
        
        c=user_admin.select_count()
        
        if c>0:
            
            if request.get_cookie("remember_login", secret=key_encrypt):
            
                 #check login
            
                 token_login=request.get_cookie("remember_login", secret=key_encrypt)
            
                 user_admin.conditions=['WHERE token_login=%s', [token_login]]
    
                 arr_user=user_admin.select_a_row_where(['id', 'privileges'])
                 
                 if arr_user==False:
                     # delete cookioe
                     response.delete_cookie("remember_login")
                 else:
                     s=get_session()
            
                     s['id']=arr_user['id']
                     s['login']=1
                     s['privileges']=arr_user['privileges']
                     
                     s.save()
                     
                     redirect(make_url(config.admin_folder))
            
            else:
                
                post={}
                
                user_admin.yes_repeat_password=False

                user_admin.fields['password'].required=True
                
                user_admin.create_forms(['username', 'password'])
                
                forms=show_form(post, user_admin.forms, t, yes_error=False)
                
                #connection.close()
                
                return t.load_template('admin/login.phtml', forms=forms, yes_recovery_login=yes_recovery_login)
                
        else:
        
            post={}
            
            set_extra_forms_user(user_admin)
            
            forms=show_form(post, user_admin.forms, t, yes_error=False)

            return t.load_template('admin/register.phtml', forms=forms)
Esempio n. 24
0
def check_token():
    t=PTemplate(env)
    
    return t.load_template('admin/check_token.phtml')