Beispiel #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))
Beispiel #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))
Beispiel #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))
Beispiel #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))
Beispiel #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))
Beispiel #6
0
def tasklist(server_id):
    
    content_index=''
    
    if check_login():

        conn=WebModel.connection()

        server=Server(conn)
        
        arr_server=server.select_a_row(server_id)
        
        if arr_server:

            s=get_session()

            menu=get_menu(config_admin.modules_admin)
        
            lang_selected=get_language(s)           

            task=Task(conn)
            
            arr_task_id=[]
            
            with task.query('select DISTINCT task_id from logtask where server=%s', [arr_server['ip']]) as cursor:
                for arr_task in cursor:
                    arr_task_id.append(arr_task['task_id'])
            
            task.set_conditions('WHERE id IN '+task.check_in_list_str('id', arr_task_id), [])
            
            task_list=SimpleList(task, make_url(pastafari_folder+'/tasklist/'+str(server_id), {}), t)
        
            task_list.fields_showed=['id', 'name_task', 'description_task', 'error', 'status']
        
            task_list.yes_search=False

            task_list.order_field='id'
            task_list.order=1
            
            request.environ['server_id']=arr_server['id']

            task_list.arr_extra_options=[server_task_options]
            
            return_url=make_url('pastafari/servers')
        
            content_index=t.load_template('pastafari/admin/showtasks.phtml', task_list=task_list, server=arr_server, return_url=return_url)
            
        else:
            cont_index=I18n.lang('pastafari', 'sorry_i_cannot_find_the_server', 'Sorry, i cannot find the server')
        
        conn.close()  
        
        return t.load_template('admin/content.html', title=I18n.lang('pastafari', 'task_list_of', 'Task list of')+ ' %s' % arr_server['hostname'], content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
    
    return ""
Beispiel #7
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 ""
Beispiel #8
0
def home():
    
    connection=WebModel.connection()
    #Fix, make local variable
    
    s=get_session()
    
    if check_login():
        
        getpostfiles=GetPostFiles()
        
        getpostfiles.obtain_get()

        parent_id=getpostfiles.get.get('parent_id', '0')
        
        parent_id=int(parent_id)
        
        #Load menu
        
        menu=get_menu(config_admin.modules_admin)
    
        lang_selected=get_language(s)
        
        groups=servers.ServerGroup(connection)
        
        groups.create_forms()
        
        groups.forms['parent_id'].default_value=parent_id
        
        hierarchy=HierarchyModelLinks(groups, 'All groups', 'name', 'parent_id', make_url('pastafari/groups'))
        
        hierarchy.prepare()
        
        group_list=GenerateAdminClass(groups, make_url(pastafari_folder+'/groups', {'parent_id': str(parent_id)}), t)
        
        groups.set_conditions('WHERE parent_id=%s', [parent_id])
        
        group_list.list.fields_showed=['name']
        
        group_list.list.arr_extra_options=[task_options]
        
        group_list.list.s['order']='0'
        group_list.list.s['order_field']='name'
        
        group_list.list.yes_search=False
        
        content_index=t.load_template('pastafari/groups.phtml', group_list=group_list, hierarchy_links=hierarchy, son_id=parent_id)
        #group_list.show()
        
        return t.load_template('admin/content.html', title=I18n.lang('pastafari', 'servers_groups', 'Server\'s Group'), content_index=content_index, menu=menu, lang_selected=lang_selected, arr_i18n=I18n.dict_i18n)
        
    else:
        redirect(make_url(config.admin_folder))
Beispiel #9
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))
Beispiel #10
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 ""
Beispiel #11
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))
Beispiel #12
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))
Beispiel #13
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))
Beispiel #14
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))
Beispiel #15
0
def home():

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

    s = get_session()

    if check_login():

        getpostfiles = GetPostFiles()

        getpostfiles.obtain_get()

        parent_id = getpostfiles.get.get('parent_id', '0')

        parent_id = int(parent_id)

        #Load menu

        menu = get_menu(config_admin.modules_admin)

        lang_selected = get_language(s)

        groups = servers.ServerGroup(connection)

        groups.create_forms()

        groups.forms['parent_id'].default_value = parent_id

        hierarchy = HierarchyModelLinks(groups, 'All groups', 'name',
                                        'parent_id',
                                        make_url('pastafari/groups'))

        hierarchy.prepare()

        group_list = GenerateAdminClass(
            groups,
            make_url(pastafari_folder + '/groups',
                     {'parent_id': str(parent_id)}), t)

        groups.set_conditions('WHERE parent_id=%s', [parent_id])

        group_list.list.fields_showed = ['name']

        group_list.list.arr_extra_options = [task_options]

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

        group_list.list.yes_search = False

        content_index = t.load_template('pastafari/groups.phtml',
                                        group_list=group_list,
                                        hierarchy_links=hierarchy,
                                        son_id=parent_id)
        #group_list.show()

        return t.load_template('admin/content.html',
                               title=I18n.lang('pastafari', 'servers_groups',
                                               'Server\'s Group'),
                               content_index=content_index,
                               menu=menu,
                               lang_selected=lang_selected,
                               arr_i18n=I18n.dict_i18n)

    else:
        redirect(make_url(config.admin_folder))
Beispiel #16
0
if hasattr(config, 'email_address'):
    email_address=config.email_address

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

key_encrypt=config.key_encrypt #create_key_encrypt()

module_admin=path.dirname(__file__)

env=env_theme(__file__)

# Preload modules

#Load menu
                
menu=get_menu(config_admin.modules_admin)

module_imported={}

for k, v in menu.items():
    
    if k[:1]!='/':
        if type(v).__name__=='list':
            module_imported[k]=import_module(v[1])

#print(d)

@get('/'+config.admin_folder)
@get('/'+config.admin_folder+'/<module>')
@post('/'+config.admin_folder+'/<module>')
@get('/'+config.admin_folder+'/<module>/<submodule>')
Beispiel #17
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))
Beispiel #18
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))
Beispiel #19
0
def tasklist(server_id):

    content_index = ''

    if check_login():

        conn = WebModel.connection()

        server = Server(conn)

        arr_server = server.select_a_row(server_id)

        if arr_server:

            s = get_session()

            menu = get_menu(config_admin.modules_admin)

            lang_selected = get_language(s)

            task = Task(conn)

            arr_task_id = []

            with task.query(
                    'select DISTINCT task_id from logtask where server=%s',
                [arr_server['ip']]) as cursor:
                for arr_task in cursor:
                    arr_task_id.append(arr_task['task_id'])

            task.set_conditions(
                'WHERE id IN ' + task.check_in_list_str('id', arr_task_id), [])

            task_list = SimpleList(
                task,
                make_url(pastafari_folder + '/tasklist/' + str(server_id), {}),
                t)

            task_list.fields_showed = [
                'id', 'name_task', 'description_task', 'error', 'status'
            ]

            task_list.yes_search = False

            task_list.order_field = 'id'
            task_list.order = 1

            request.environ['server_id'] = arr_server['id']

            task_list.arr_extra_options = [server_task_options]

            return_url = make_url('pastafari/servers')

            content_index = t.load_template('pastafari/admin/showtasks.phtml',
                                            task_list=task_list,
                                            server=arr_server,
                                            return_url=return_url)

        else:
            cont_index = I18n.lang('pastafari',
                                   'sorry_i_cannot_find_the_server',
                                   'Sorry, i cannot find the server')

        conn.close()

        return t.load_template(
            'admin/content.html',
            title=I18n.lang('pastafari', 'task_list_of', 'Task list of') +
            ' %s' % arr_server['hostname'],
            content_index=content_index,
            menu=menu,
            lang_selected=lang_selected,
            arr_i18n=I18n.dict_i18n)

    return ""
Beispiel #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))
Beispiel #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))