Beispiel #1
0
def disk_status(server_id):
    
    if check_login():
        
        s=get_session()
    
        conn=WebModel.connection()
    
        server=servers.Server(conn)
        
        arr_server=server.select_a_row(server_id)
        
        if arr_server:
        
            if 'ip' in arr_server:
            
                ip=arr_server['ip']
                
                status_disk=servers.StatusDisk(conn)
                
                status_disk.set_conditions('where ip=%s', [ip])
                
                arr_disk=status_disk.select_to_array(['disk', 'used', 'free', 'date'])
                
                return filter_ajax(arr_disk)
    return filter_ajax({})
Beispiel #2
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 #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():

    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 #5
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 #6
0
def disk_status(server_id):

    if check_login():

        s = get_session()

        conn = WebModel.connection()

        server = servers.Server(conn)

        arr_server = server.select_a_row(server_id)

        if arr_server:

            if 'ip' in arr_server:

                ip = arr_server['ip']

                status_disk = servers.StatusDisk(conn)

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

                arr_disk = status_disk.select_to_array(
                    ['disk', 'used', 'free', 'date'])

                return filter_ajax(arr_disk)
    return filter_ajax({})
Beispiel #7
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 #8
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 #9
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 #10
0
def getservers(task_id, position):
    
    conn=WebModel.connection()
    
    s=get_session()

    if check_login():

        task=Task(conn)
        logtask=LogTask(conn)
        server=Server(conn)
        
        arr_task=task.select_a_row(task_id)
        
        server.set_conditions('WHERE ip IN (select DISTINCT server from logtask where task_id=%s)', [task_id])
        
        server.set_limit([position, num_tasks])
        
        arr_server=server.select_to_array(['hostname', 'ip'])
        
        response.set_header('Content-type', 'text/plain')
        
        if arr_server:
            conn.close()
            return filter_ajax({'servers': arr_server, 'error': 0})
            
        else:
            
            logtask.set_conditions('where task_id=%s and server=""', [task_id])
            
            logtask.set_order({'id': 1})
            
            arr_tasklog=logtask.select_a_row_where([], True)
            
            if arr_tasklog:
                
                if arr_tasklog['error']==1:
                    conn.close()        
                    return arr_tasklog
                else:
                    conn.close()
                    return filter_ajax({'error': 0, 'servers': []})
                    
            else:
                conn.close()
                return filter_ajax({'error': 0, 'servers': []})
                
            
            pass
        

    else:
        conn.close()
        return filter_ajax({})
Beispiel #11
0
def getservers(task_id, position):

    conn = WebModel.connection()

    s = get_session()

    if check_login():

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

        arr_task = task.select_a_row(task_id)

        server.set_conditions(
            'WHERE ip IN (select DISTINCT server from logtask where task_id=%s)',
            [task_id])

        server.set_limit([position, num_tasks])

        arr_server = server.select_to_array(['hostname', 'ip'])

        response.set_header('Content-type', 'text/plain')

        if arr_server:
            conn.close()
            return filter_ajax({'servers': arr_server, 'error': 0})

        else:

            logtask.set_conditions('where task_id=%s and server=""', [task_id])

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

            arr_tasklog = logtask.select_a_row_where([], True)

            if arr_tasklog:

                if arr_tasklog['error'] == 1:
                    conn.close()
                    return arr_tasklog
                else:
                    conn.close()
                    return filter_ajax({'error': 0, 'servers': []})

            else:
                conn.close()
                return filter_ajax({'error': 0, 'servers': []})

            pass

    else:
        conn.close()
        return filter_ajax({})
Beispiel #12
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 #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))
Beispiel #14
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 #15
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 #16
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 #17
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 #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))
Beispiel #19
0
def getprogress(task_id):
    
    conn=WebModel.connection()
    
    s=get_session()

    if check_login():
        
        getpost=GetPostFiles() 
        
        getpost.obtain_post([], True)

        task=Task(conn)
        logtask=LogTask(conn)
        server=Server(conn)
        
        arr_task=task.select_a_row(task_id)
        
        try:
            
            servers=json.loads(getpost.post['servers'])
            
        except:
            
            servers={}
        
        #for ip in servers:
        
        if len(servers)>0:
        
            logtask.set_order({'id': 1})
            
            logtask.set_conditions('WHERE task_id=%s and status=1 and error=1 and server=""', [task_id])
            
            c_error=logtask.select_count()
            
            if c_error==0:
            
                logtask.set_order({'id': 1})
                
                checked_servers=logtask.check_in_list_str('server', servers)

                logtask.set_conditions('WHERE task_id=%s and status=1 and server IN '+checked_servers+' and server!=""', [task_id])
                
                arr_log=logtask.select_to_array(['status', 'error', 'server'])
                
                logtask.set_order({'id': 1})
                
                logtask.set_conditions('WHERE task_id=%s and status=0 and server NOT IN '+checked_servers+' and server!=""', [task_id])
                
                arr_log2=logtask.select_to_array(['status', 'error', 'server'])
                
                arr_log=arr_log2+arr_log
                
                #response.set_header('Content-type', 'text/plain')
                
                #return json.dumps(arr_log)
                
            else:
                
                arr_log=[]
                
                for server in servers:
                    
                    arr_log.append({'status':1, 'error':1, 'server': server})
                    
            response.set_header('Content-type', 'text/plain')
            
            conn.close()
            
            return filter_ajax(arr_log)
            
        response.set_header('Content-type', 'text/plain')    
        
        arr_log=[]
        
        conn.close()        
        
        return filter_ajax(arr_log)
                
                

    else:
        conn.close()
        return filter_ajax({})
Beispiel #20
0
def net_cpu_status(server_id):

    if check_login():

        s = get_session()

        conn = WebModel.connection()

        server = servers.Server(conn)

        arr_server = server.select_a_row(server_id)

        if arr_server:

            if 'ip' in arr_server:

                ip = arr_server['ip']

                now = datetime.obtain_timestamp(datetime.now(True))

                hours12 = now - 21600

                date_now = datetime.timestamp_to_datetime(now)

                date_hours12 = datetime.timestamp_to_datetime(hours12)

                status_cpu = servers.StatusCpu(conn)

                status_cpu.set_conditions(
                    'where ip=%s and date>=%s and date<=%s',
                    [ip, date_hours12, date_now])

                #arr_cpu=status_cpu.select_to_array(['idle', 'date'])
                cur = status_cpu.select(['idle', 'date'])

                x = 0

                arr_cpu = []

                cur.fetchone()

                for cpu_info in cur:

                    arr_cpu.append(cpu_info['idle'])

                cur.close()

                status_mem = servers.StatusMemory(conn)

                status_mem.set_conditions(
                    'where ip=%s and date>=%s and date<=%s',
                    [ip, date_hours12, date_now])

                #status_mem.set_order(['id', 'ASC'])

                #arr_mem=status_mem.select_to_array(['used', 'free', 'date'])
                arr_mem = []
                with status_mem.select(['used', 'free', 'cached',
                                        'date']) as cur:
                    #cur.fetchone()

                    for mem_info in cur:
                        mem_info['used'] = (
                            (mem_info['used'] / 1024) / 1024) / 1024
                        mem_info['free'] = (
                            (mem_info['free'] / 1024) / 1024) / 1024
                        mem_info['cached'] = (
                            (mem_info['cached'] / 1024) / 1024) / 1024
                        arr_mem.append(mem_info)

                if len(arr_mem) > 2:
                    arr_mem.pop(0)

                #arr_cpu=status_cpu.select_to_array(['idle', 'date'])
                cur = status_cpu.select(['idle', 'date'])

                arr_net = {}

                status_net = servers.StatusNet(conn)

                status_net.set_conditions(
                    'where ip=%s and date>=%s and date<=%s',
                    [ip, date_hours12, date_now])

                arr_net = []

                cur = status_net.select(['bytes_sent', 'bytes_recv', 'date'])

                substract_time = 0  #datetime.obtain_timestamp(datetime.now())

                c_hours12 = now

                c_elements = 0

                c_count = cur.rowcount

                if c_count > 0:

                    data_net = cur.fetchone()

                    first_recv = data_net['bytes_recv']
                    first_sent = data_net['bytes_sent']

                    if len(arr_cpu) < (c_count - 1):
                        arr_cpu.append(arr_cpu[1:])

                    for data_net in cur:

                        timestamp = datetime.obtain_timestamp(
                            data_net['date'], True)

                        diff_time = timestamp - substract_time

                        if substract_time != 0 and diff_time > 300:

                            count_time = timestamp

                            while substract_time <= count_time:

                                form_time = datetime.timestamp_to_datetime(
                                    substract_time)

                                arr_net.append(
                                    {'date': datetime.format_time(form_time)})

                                substract_time += 60

                        bytes_sent = round(
                            (data_net['bytes_sent'] - first_sent) / 1024)
                        bytes_recv = round(
                            (data_net['bytes_recv'] - first_recv) / 1024)
                        cpu = arr_cpu[x]

                        memory_used = arr_mem[x]['used']
                        memory_free = arr_mem[x]['free']
                        memory_cached = arr_mem[x]['cached']

                        arr_net.append({
                            'bytes_sent':
                            bytes_sent,
                            'bytes_recv':
                            bytes_recv,
                            'date':
                            datetime.format_time(data_net['date']),
                            'cpu':
                            cpu,
                            'memory_used':
                            memory_used,
                            'memory_free':
                            memory_free,
                            'memory_cached':
                            memory_cached
                        })

                        first_sent = data_net['bytes_sent']
                        first_recv = data_net['bytes_recv']

                        c_hours12 = timestamp

                        substract_time = int(timestamp)

                        c_elements += 1

                        x += 1

                    # If the last time is more little that now make a loop

                    while c_hours12 <= now:

                        form_time = datetime.timestamp_to_datetime(c_hours12)

                        seconds = form_time[-2:]

                        #print(form_time)

                        if seconds == '00':

                            arr_net.append(
                                {'date': datetime.format_time(form_time)})

                            # if secons is 00 and z=1 put value
                            #arr_net.append({'date': datetime.format_time(form_time)})

                            pass

                        c_hours12 += 1

                    cur.close()

                    if c_elements > 2:

                        return filter_ajax(arr_net)
                    else:

                        return filter_ajax({})

                    return filter_ajax({})

    return filter_ajax({})
Beispiel #21
0
def getprogress(task_id):

    conn = WebModel.connection()

    s = get_session()

    if check_login():

        getpost = GetPostFiles()

        getpost.obtain_post([], True)

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

        arr_task = task.select_a_row(task_id)

        try:

            servers = json.loads(getpost.post['servers'])

        except:

            servers = {}

        #for ip in servers:

        if len(servers) > 0:

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

            logtask.set_conditions(
                'WHERE task_id=%s and status=1 and error=1 and server=""',
                [task_id])

            c_error = logtask.select_count()

            if c_error == 0:

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

                checked_servers = logtask.check_in_list_str('server', servers)

                logtask.set_conditions(
                    'WHERE task_id=%s and status=1 and server IN ' +
                    checked_servers + ' and server!=""', [task_id])

                arr_log = logtask.select_to_array(
                    ['status', 'error', 'server'])

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

                logtask.set_conditions(
                    'WHERE task_id=%s and status=0 and server NOT IN ' +
                    checked_servers + ' and server!=""', [task_id])

                arr_log2 = logtask.select_to_array(
                    ['status', 'error', 'server'])

                arr_log = arr_log2 + arr_log

                #response.set_header('Content-type', 'text/plain')

                #return json.dumps(arr_log)

            else:

                arr_log = []

                for server in servers:

                    arr_log.append({'status': 1, 'error': 1, 'server': server})

            response.set_header('Content-type', 'text/plain')

            conn.close()

            return filter_ajax(arr_log)

        response.set_header('Content-type', 'text/plain')

        arr_log = []

        conn.close()

        return filter_ajax(arr_log)

    else:
        conn.close()
        return filter_ajax({})
Beispiel #22
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 #23
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 #24
0
def getinfo():

    if check_login():

        connection = WebModel.connection()

        server = servers.Server(connection)

        status_disk = servers.StatusDisk(connection)

        status_net = servers.StatusNet(connection)

        status_cpu = servers.StatusCpu(connection)

        c = server.select_count()

        now = datetime.now(True)

        timestamp_now = datetime.obtain_timestamp(now)

        five_minutes = int(timestamp_now) - 300

        five_minutes_date = datetime.timestamp_to_datetime(five_minutes)

        server.set_conditions('WHERE date<%s', [five_minutes_date])

        c_down = server.select_count()

        server.set_conditions('WHERE num_updates>%s', [0])

        c_updates = server.select_count()

        with status_disk.query(
                'select sum(used) as total_used, sum(free) as total_free from statusdisk'
        ) as cur:
            arr_disk = cur.fetchone()

        status_disk.set_conditions('WHERE percent>%s', [85])

        c_bloated_disk = status_disk.select_count()

        # Network use

        twelve_hours = int(timestamp_now) - 43200

        twelve_hours_date = datetime.timestamp_to_datetime(twelve_hours)

        #status_net.set_conditions('WHERE date>%s', [twelve_hours_date])

        #SELECT(t2.sub1 - t1.sub1) AS sub1, (t2.sub2 - t1.sub2) AS sub2
        #FROM table t1 CROSS JOIN
        # table t2
        #WHERE t1.date = '2014-11-08' AND t2.id = '2014-11-07';

        # select (t1.bytes_sent+t2,bytes_sent) as bytes_sent from statusnet t1 CROSS JOIN statusnet t2

        arr_net = {'total_bytes_recv': 0, 'total_bytes_sent': 0}

        #status_net.set_conditions('WHERE date>%s', [twelve_hours_date])

        #status_net.set_order('date', 'ASC')

        #select bytes_sent, bytes_recv, ip from statusnet WHERE date>'20160606093229' and last_updated=1 group by ip

        status_net.set_conditions(
            'WHERE date>%s and last_updated=1 group by ip',
            [twelve_hours_date])

        with status_net.select(['bytes_recv', 'bytes_sent']) as cur:

            # I think that this loop can be optimized

            for net in cur:
                arr_net['total_bytes_recv'] += net['bytes_recv']
                arr_net['total_bytes_sent'] += net['bytes_sent']

        arr_cpu = {'0-30': 0, '30-70': 0, '70-100': 0}

        status_cpu.set_conditions(
            'WHERE date>%s and last_updated=1 group by ip',
            [twelve_hours_date])

        with status_cpu.select(['idle']) as cur:

            for cpu in cur:
                if cpu['idle'] > 70:
                    arr_cpu['70-100'] += 1
                elif cpu['idle'] > 30:
                    arr_cpu['30-70'] += 1
                else:
                    arr_cpu['0-30'] += 1
        #print(c_net)

        arr_json = {
            'num_servers': c,
            'num_servers_down': c_down,
            'num_servers_updates': c_updates,
            'disk_info': arr_disk,
            'num_servers_bloated': c_bloated_disk,
            'net_info': arr_net,
            'cpu_info': arr_cpu
        }

        return arr_json
    else:
        redirect(make_url(config.admin_folder))
Beispiel #25
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 #26
0
def net_cpu_status(server_id):
    
    if check_login():
        
        s=get_session()
    
        conn=WebModel.connection()
    
        server=servers.Server(conn)
        
        arr_server=server.select_a_row(server_id)
        
        if arr_server:
        
            if 'ip' in arr_server:
            
                ip=arr_server['ip']
                
                now=datetime.obtain_timestamp(datetime.now(True))
                
                hours12=now-21600
                
                date_now=datetime.timestamp_to_datetime(now)
                
                date_hours12=datetime.timestamp_to_datetime(hours12)
                
                status_cpu=servers.StatusCpu(conn)
                
                status_cpu.set_conditions('where ip=%s and date>=%s and date<=%s', [ip, date_hours12, date_now])
                
                #arr_cpu=status_cpu.select_to_array(['idle', 'date'])
                cur=status_cpu.select(['idle', 'date'])
                
                x=0
                
                arr_cpu=[]
                
                cur.fetchone()
                
                for cpu_info in cur:
                    
                    arr_cpu.append(cpu_info['idle'])
                    
                cur.close()
                
                status_mem=servers.StatusMemory(conn)
                
                status_mem.set_conditions('where ip=%s and date>=%s and date<=%s', [ip, date_hours12, date_now]) 
                
                #status_mem.set_order(['id', 'ASC'])
                
                #arr_mem=status_mem.select_to_array(['used', 'free', 'date'])
                arr_mem=[]
                with status_mem.select(['used', 'free', 'cached', 'date'])  as cur:
                    #cur.fetchone()
                    
                    for mem_info in cur:
                        mem_info['used']=((mem_info['used']/1024)/1024)/1024
                        mem_info['free']=((mem_info['free']/1024)/1024)/1024
                        mem_info['cached']=((mem_info['cached']/1024)/1024)/1024
                        arr_mem.append(mem_info)
                
                if len(arr_mem)>2:
                    arr_mem.pop(0)
                
                #arr_cpu=status_cpu.select_to_array(['idle', 'date'])
                cur=status_cpu.select(['idle', 'date'])
                
                arr_net={}
                
                status_net=servers.StatusNet(conn)
                
                status_net.set_conditions('where ip=%s and date>=%s and date<=%s', [ip, date_hours12, date_now])
                
                arr_net=[]
                
                cur=status_net.select(['bytes_sent', 'bytes_recv', 'date'])
                
                substract_time=0 #datetime.obtain_timestamp(datetime.now())
                
                c_hours12=now
                
                c_elements=0
                
                c_count=cur.rowcount
                
                if c_count>0:
                
                    data_net=cur.fetchone()
                    
                    first_recv=data_net['bytes_recv']
                    first_sent=data_net['bytes_sent']
                    
                    if len(arr_cpu)<(c_count-1):
                        arr_cpu.append(arr_cpu[1:])
                    
                    for data_net in cur:
                        
                        timestamp=datetime.obtain_timestamp(data_net['date'], True)
                        
                        diff_time=timestamp-substract_time
                        
                        if substract_time!=0 and diff_time>300:
                            
                            count_time=timestamp
                            
                            while substract_time<=count_time:
                    
                                form_time=datetime.timestamp_to_datetime(substract_time)
                                
                                arr_net.append({'date': datetime.format_time(form_time)})
                                        
                                substract_time+=60
                        
                        bytes_sent=round((data_net['bytes_sent']-first_sent)/1024)
                        bytes_recv=round((data_net['bytes_recv']-first_recv)/1024)
                        cpu=arr_cpu[x]
                        
                        memory_used=arr_mem[x]['used']
                        memory_free=arr_mem[x]['free']
                        memory_cached=arr_mem[x]['cached']

                        arr_net.append({'bytes_sent': bytes_sent, 'bytes_recv': bytes_recv, 'date': datetime.format_time(data_net['date']), 'cpu': cpu, 'memory_used': memory_used, 'memory_free': memory_free, 'memory_cached': memory_cached})
                        
                        first_sent=data_net['bytes_sent']
                        first_recv=data_net['bytes_recv']
                        
                        c_hours12=timestamp
                        
                        substract_time=int(timestamp)
                        
                        c_elements+=1
                        
                        x+=1
                        
                    # If the last time is more little that now make a loop 
                    
                    while c_hours12<=now:
                    
                        form_time=datetime.timestamp_to_datetime(c_hours12)
                        
                        seconds=form_time[-2:]
                            
                        #print(form_time)
                        
                        if seconds=='00':
                            
                            arr_net.append({'date': datetime.format_time(form_time)})
                                
                            # if secons is 00 and z=1 put value
                            #arr_net.append({'date': datetime.format_time(form_time)})
                                
                            pass
                        
                        c_hours12+=1
                    
                    cur.close()
                    
                    if c_elements>2:
                        
                        return filter_ajax(arr_net)
                    else:
                        
                        return filter_ajax({})
                        
                    return filter_ajax({})
        
    return filter_ajax({})
Beispiel #27
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 #28
0
def getinfo():
    
    if check_login():
    
        connection=WebModel.connection()

        server=servers.Server(connection)
        
        status_disk=servers.StatusDisk(connection)
        
        status_net=servers.StatusNet(connection)
        
        status_cpu=servers.StatusCpu(connection)
        
        c=server.select_count()
        
        now=datetime.now(True)
            
        timestamp_now=datetime.obtain_timestamp(now)

        five_minutes=int(timestamp_now)-300
        
        five_minutes_date=datetime.timestamp_to_datetime(five_minutes)
        
        server.set_conditions('WHERE date<%s', [five_minutes_date])
        
        c_down=server.select_count()
        
        server.set_conditions('WHERE num_updates>%s', [0])
        
        c_updates=server.select_count()
        
        with status_disk.query('select sum(used) as total_used, sum(free) as total_free from statusdisk') as cur:
            arr_disk=cur.fetchone()
            
        status_disk.set_conditions('WHERE percent>%s', [85])
        
        c_bloated_disk=status_disk.select_count()
        
        # Network use
        
        twelve_hours=int(timestamp_now)-43200
        
        twelve_hours_date=datetime.timestamp_to_datetime(twelve_hours)
        
        #status_net.set_conditions('WHERE date>%s', [twelve_hours_date])
        
        #SELECT(t2.sub1 - t1.sub1) AS sub1, (t2.sub2 - t1.sub2) AS sub2
        #FROM table t1 CROSS JOIN
        # table t2
        #WHERE t1.date = '2014-11-08' AND t2.id = '2014-11-07';
        
        # select (t1.bytes_sent+t2,bytes_sent) as bytes_sent from statusnet t1 CROSS JOIN statusnet t2
        
        arr_net={'total_bytes_recv': 0, 'total_bytes_sent': 0}
        
        #status_net.set_conditions('WHERE date>%s', [twelve_hours_date])
        
        #status_net.set_order('date', 'ASC')
        
        #select bytes_sent, bytes_recv, ip from statusnet WHERE date>'20160606093229' and last_updated=1 group by ip
        
        status_net.set_conditions('WHERE date>%s and last_updated=1 group by ip', [twelve_hours_date])
        
        with status_net.select(['bytes_recv', 'bytes_sent']) as cur:
            
            # I think that this loop can be optimized
            
            for net in cur:
                arr_net['total_bytes_recv']+=net['bytes_recv']
                arr_net['total_bytes_sent']+=net['bytes_sent']
            
        arr_cpu={'0-30': 0, '30-70': 0, '70-100': 0}
        
        status_cpu.set_conditions('WHERE date>%s and last_updated=1 group by ip', [twelve_hours_date])
        
        with status_cpu.select(['idle']) as cur:
            
            for cpu in cur:
                if cpu['idle']>70:
                    arr_cpu['70-100']+=1
                elif cpu['idle']>30:
                    arr_cpu['30-70']+=1
                else:
                    arr_cpu['0-30']+=1
        #print(c_net)
        
        arr_json={'num_servers': c, 'num_servers_down': c_down, 'num_servers_updates': c_updates, 'disk_info': arr_disk, 'num_servers_bloated': c_bloated_disk, 'net_info': arr_net, 'cpu_info': arr_cpu}
        
        return arr_json
    else:
        redirect(make_url(config.admin_folder))
Beispiel #29
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 #30
0
def base_simple_admin(func_view, env, title, **args):
    
    if check_login():
        
        return func_view(connection, t, s, **args)
Beispiel #31
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)