示例#1
0
    def show( begin_page, total_elements, num_elements, link ,initial_num_pages=20, variable='begin_page', label='', func_jscript=''):
        
        pages='';

        if begin_page>total_elements:
            begin_page=0

        # Calculamos el total de todas las páginas

        total_page=ceil(total_elements/num_elements)
        
        # Calculamos en que página nos encontramos

        actual_page=ceil(begin_page/num_elements)

        # Calculamos el total de intervalos

        total_interval=ceil(total_page/initial_num_pages)

        # Calculamos el intervalo en el que estamos

        actual_interval=floor(actual_page/initial_num_pages)

        # Calculamos el elemento de inicio del intervalo

        initial_page=ceil(actual_interval*initial_num_pages*num_elements)

        last_page=ceil(actual_interval*initial_num_pages*num_elements)+ceil(initial_num_pages*num_elements)

        if last_page>total_elements:
            last_page=total_elements

        if initial_page>0:
            initial_link=add_get_parameters(link, **{variable: '0'});
            middle_link=add_get_parameters(link, **{variable: str((initial_page-num_elements)) } );
            pages += "<a class=\""+Pages.css_class+"\" href=\""+initial_link+"\" onclick=\"func_jscript\">1</a> <a class=\""+Pages.css_class+"\" href=\""+middle_link+"\">&lt;&lt;</a> "

        arr_pages={}

        #for(x=initial_page;x<last_page;x+=num_elements)
        for x in range(initial_page, last_page, num_elements):
            
            middle_link=add_get_parameters(link, **{variable: str(x)} )

            num_page=ceil(x/num_elements)+1;
            arr_pages[x]="<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">"+str(num_page)+"</a> "
            arr_pages[begin_page]='<span class="selected_page">'+str(num_page)+'</span> ';
            pages += arr_pages[x]

        
        if last_page<total_elements:

            middle_link=add_get_parameters(link, **{variable: str(x+num_elements)} );
            last_link=add_get_parameters(link, **{variable: str( ( ( total_page*num_elements ) - num_elements) ) } )

            pages += "<a class=\""+Pages.css_class+"\" href=\""+middle_link+"\" onclick=\"func_jscript\">&gt;&gt;</a> <a class=\"link_pages\" href=\""+last_link+"\" onclick=\"func_jscript\">"+I18n.lang('common', 'last', 'Last')+"</a>"

        
        return pages
示例#2
0
def server_options(url, id, arr_row):
    options = []
    options.append('<a href="' +
                   add_get_parameters(url, op='view_status', id=id) + '">' +
                   I18n.lang('pastafari', 'view_status', 'View status') +
                   '</a>')
    return options
示例#3
0
 def url(self, son_id, title):
     
     args={}
     
     args[self.field_parent]=str(son_id)
     
     return '<a href="%s">%s</a>' % (add_get_parameters(self.base_url, **args), title)
示例#4
0
 def show(self):
     
     self.model.yes_reset_conditions=False
     
     self.obtain_order()
     
     self.obtain_field_search()
     
     self.search()
     
     total_elements=self.model.select_count()
     
     num_elements=self.limit_pages
     
     link=add_get_parameters(self.url, search_text=self.search_text, search_field=self.search_field, order=self.s['order'])
     
     begin_page=self.begin_page
     
     self.model.order_by='order by '+self.order_field+' '+self.order_by
     
     self.model.limit='limit '+str(begin_page)+','+str(self.limit_pages)
     
     list_items=self.model.select(self.fields, self.raw_query)
     
     #print(self.model.fields.keys())
     
     pages=Pages.show( begin_page, total_elements, num_elements, link ,initial_num_pages=self.initial_num_pages, variable='begin_page', label='', func_jscript='')
     
     self.begin_page=str(self.begin_page)
     
     self.model.yes_reset_conditions=True
     
     listing=self.t.load_template('utils/list.phtml', simplelist=self, list=list_items, pages=pages)
     
     list_items.close()
     
     return listing
示例#5
0
def admin(t):

    GetPostFiles.obtain_get()

    GetPostFiles.get['op'] = GetPostFiles.get.get('op', '')

    server = servers.Server()

    url = make_url(config.admin_folder + '/pastafari/servers')

    if GetPostFiles.get['op'] == 'add_new_server':

        #Check if the server can be access with god module using ssh, if yes, install idea(aka virus or platon) using protozoo or similar program

        server.create_forms()

        return ""
        pass
    elif GetPostFiles.get['op'] == 'view_status':

        GetPostFiles.get['id'] = GetPostFiles.get.get('id', '0')

        server_id = int(GetPostFiles.get['id'])

        server_view = server.select_a_row(server_id)

        GetPostFiles.get['show_data'] = GetPostFiles.get.get('show_data', '0')

        if server_view != False:

            if GetPostFiles.get['show_data'] == '0':

                return ts.load_template('server_status.phtml',
                                        server_view=server_view)

            elif GetPostFiles.get['show_data'] == '1':

                get_c = 60

                ptemplate.show_basic_template = False

                network_status = servers.ServerInfoNet()

                c = network_status.select_count()

                begin_c = c - get_c

                if begin_c < 0:

                    begin_c = 0

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

                network_status.set_order(['date'], ['ASC'])

                network_status.set_limit([begin_c, get_c])

                network_cur = network_status.select()

                #arr_dates=[]

                arr_dates = {}

                for net_info in network_cur:

                    arr_dates[net_info['device']] = arr_dates.get(
                        net_info['device'], [])

                    net_info['date'] = datetime.format_fulldate(
                        net_info['date'])

                    arr_dates[net_info['device']].append(net_info)

                    #arr_dates.append(arr_date)

                arr_final_dates = {}

                for dev in arr_dates:

                    substract_up = arr_dates[dev][0]['network_up']

                    substract_down = arr_dates[dev][0]['network_down']

                    arr_final_dates[dev] = []

                    for x in range(1, len(arr_dates[dev])):

                        up = arr_dates[dev][x]['network_up'] - substract_up

                        down = arr_dates[dev][x][
                            'network_down'] - substract_down

                        arr_final_dates[dev].append({
                            'date':
                            arr_dates[dev][x]['date'],
                            'network_up':
                            up,
                            'network_down':
                            down
                        })

                        substract_up = arr_dates[dev][x]['network_up']

                        substract_down = arr_dates[dev][x]['network_down']

                        pass

                return json.dumps(arr_final_dates)

    else:

        # Obtain uptimes

        server.conditions = ['where status=%s', [0]]

        num_servers_failed = server.select_count()

        server.conditions = ['where status=%s', [1]]

        num_servers_uptime = server.select_count()

        # Obtain profiles

        server.distinct = 'DISTINCT'

        server.order_by = 'order by profile ASC'

        arr_profiles = server.select_to_array(['profile'])

        profiles = SelectForm('profile', '')

        profiles.arr_select[''] = ''

        for profile in arr_profiles.values():

            profiles.arr_select[profile['profile']] = profile['profile']

        server.distinct = ''

        GetPostFiles.get['profile'] = GetPostFiles.get.get('profile', '')

        url = add_get_parameters(url, profile=GetPostFiles.get['profile'])

        if GetPostFiles.get[
                'profile'] in profiles.arr_select and GetPostFiles.get[
                    'profile'] != '':
            server.conditions = [
                'where profile=%s', [GetPostFiles.get['profile']]
            ]

        profiles.default_value = GetPostFiles.get['profile']

        server_list = SimpleList(server, url, t)

        #server_list.fields=['id', 'type']

        server_list.fields_showed = [
            'hostname', 'ip', 'profile', 'type', 'last_updated'
        ]

        server_list.yes_search = False

        server_list.arr_extra_fields = [
            I18n.lang('common', 'options', 'Options')
        ]

        server_list.arr_extra_options = [server_options]

        return ts.load_template('servers.phtml',
                                server_list=server_list,
                                url=url,
                                profiles=profiles,
                                num_servers_failed=num_servers_failed,
                                num_servers_uptime=num_servers_uptime)
示例#6
0
def server_options(url, id, arr_row):
        options=[]
        options.append('<a href="'+add_get_parameters(url, op='view_status', id=id)+'">'+I18n.lang('pastafari', 'view_status', 'View status')+'</a>')
        return options
示例#7
0
def admin(t):
  
    GetPostFiles.obtain_get()
    
    GetPostFiles.get['op']=GetPostFiles.get.get('op', '')
    
    server=servers.Server()
    
    url=make_url(config.admin_folder+'/pastafari/servers')
    
    if GetPostFiles.get['op']=='add_new_server':
    
        #Check if the server can be access with god module using ssh, if yes, install idea(aka virus or platon) using protozoo or similar program
    
        server.create_forms()
    
        return ""
        pass
    elif GetPostFiles.get['op']=='view_status':
        
        GetPostFiles.get['id']=GetPostFiles.get.get('id', '0')
    
        server_id=int(GetPostFiles.get['id'])
    
        server_view=server.select_a_row(server_id)
        
        GetPostFiles.get['show_data']=GetPostFiles.get.get('show_data', '0')
        
        if server_view!=False:
        
            if GetPostFiles.get['show_data']=='0':
    
                return ts.load_template('server_status.phtml', server_view=server_view)
    
            elif GetPostFiles.get['show_data']=='1':
                
                get_c=60
            
                ptemplate.show_basic_template=False
            
                network_status=servers.ServerInfoNet()
                
                c=network_status.select_count()
                
                begin_c=c-get_c
                
                if begin_c<0:
                    
                    begin_c=0
                
                network_status.set_conditions('where server=%s', [server_view['ip']])
                
                network_status.set_order(['date'], ['ASC'])
                
                network_status.set_limit([begin_c, get_c])
                
                network_cur=network_status.select()
                
                #arr_dates=[]
                
                arr_dates={}
                
                for net_info in network_cur:
            
                    arr_dates[net_info['device']]=arr_dates.get(net_info['device'], [])
            
                    net_info['date']=datetime.format_fulldate(net_info['date'])
            
                    arr_dates[net_info['device']].append(net_info)
            
                    #arr_dates.append(arr_date)
            
                arr_final_dates={}
            
                for dev in arr_dates:
                    
                    substract_up=arr_dates[dev][0]['network_up']
                    
                    substract_down=arr_dates[dev][0]['network_down']
                    
                    arr_final_dates[dev]=[]
                    
                    for x in range(1, len(arr_dates[dev])):
                        
                        up=arr_dates[dev][x]['network_up']-substract_up
                        
                        down=arr_dates[dev][x]['network_down']-substract_down
                        
                        arr_final_dates[dev].append({'date': arr_dates[dev][x]['date'], 'network_up': up, 'network_down': down})
                        
                        substract_up=arr_dates[dev][x]['network_up']
                    
                        substract_down=arr_dates[dev][x]['network_down']
                        
                        pass
                    
            
                return json.dumps(arr_final_dates)
    
    else:
    
        # Obtain uptimes
        
        server.conditions=['where status=%s', [0]]
        
        num_servers_failed=server.select_count()
        
        server.conditions=['where status=%s', [1]]
        
        num_servers_uptime=server.select_count()
        
        # Obtain profiles
        
        server.distinct='DISTINCT'
        
        server.order_by='order by profile ASC'
        
        arr_profiles=server.select_to_array(['profile'])
        
        profiles=SelectForm('profile', '')
        
        profiles.arr_select['']=''
        
        for profile in arr_profiles.values():
            
            profiles.arr_select[profile['profile']]=profile['profile']
    
        server.distinct=''
        
        GetPostFiles.get['profile']=GetPostFiles.get.get('profile', '')
        
        url=add_get_parameters(url, profile= GetPostFiles.get['profile'])
        
        if GetPostFiles.get['profile'] in profiles.arr_select and GetPostFiles.get['profile']!='':
            server.conditions=['where profile=%s', [GetPostFiles.get['profile']]]
        
        profiles.default_value=GetPostFiles.get['profile']
    
        server_list=SimpleList(server, url, t)
        
        #server_list.fields=['id', 'type']
        
        server_list.fields_showed=['hostname', 'ip', 'profile', 'type', 'last_updated']
        
        server_list.yes_search=False
        
        server_list.arr_extra_fields=[I18n.lang('common', 'options', 'Options')]
        
        server_list.arr_extra_options=[server_options]
    
        return ts.load_template('servers.phtml', server_list=server_list, url=url, profiles=profiles, num_servers_failed=num_servers_failed, num_servers_uptime=num_servers_uptime)
示例#8
0
 def standard_options(url, id, arr_row):
     options=[]
     options.append('<a href="'+add_get_parameters(url, op_admin=1, id=id)+'">'+I18n.lang('common', 'edit', 'Edit')+'</a>')
     options.append('<a href="'+add_get_parameters(url, op_admin=3, id=id)+'">'+I18n.lang('common', 'delete', 'Delete')+'</a>')
     return options