⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callbacks.c

📁 linux下可以连接并查看交换机当前运行情况的东东
💻 C
📖 第 1 页 / 共 5 页
字号:
voidon_button_df_clicked (GtkButton *button, gpointer user_data){    // Call function to perform operation and output to textbox.    perform_wsutils_click("df");}voidon_button_path_clicked (GtkButton *button, gpointer user_data){    // Call function to perform operation and output to textbox.    perform_wsutils_click("path");}voidon_button_ldconfig_clicked (GtkButton *button, gpointer user_data){    // Call function to perform operation and output to textbox.    perform_wsutils_click("ldconfig");}voidon_button_lpq_clicked (GtkButton *button, gpointer user_data){    // Call function to perform operation and output to textbox.    perform_wsutils_click("lpq");}voidon_button_env_clicked (GtkButton *button, gpointer user_data){    // Call function to perform operation and output to textbox.    perform_wsutils_click("env");}voidon_button_w_clicked (GtkButton *button, gpointer user_data){    // Call function to perform operation and output to textbox.    perform_wsutils_click("w");}voidperform_wsutils_click (char *operation){    // Get pointers to window widgets, declare local vars    GtkWidget * text_wsutils  = lookup_widget(app1, "text_wsutils");    GtkWidget * checkbutton16 = lookup_widget(app1, "checkbutton16");    GtkWidget * checkbutton17 = lookup_widget(app1, "checkbutton17");    GtkWidget * checkbutton18 = lookup_widget(app1, "checkbutton18");    GdkFont   * fixed_font_ptr;    FILE      * pipein_fp;    char        readbuf[80]       = "";    char        timestamp_str[80] = "";    gchar       operation_str[80];    // Read user output options and perform appropriate action.    if (GTK_TOGGLE_BUTTON(checkbutton16)->active) {        gtk_text_backward_delete(GTK_TEXT(text_wsutils), gtk_text_get_length(GTK_TEXT(text_wsutils)));    }    if (GTK_TOGGLE_BUTTON(checkbutton17)->active) {        // PREFS: Fixed Font Size        fixed_font_ptr = gdk_font_load((gchar *)fixed_font);    }    else {        fixed_font_ptr = NULL;    }    // Construct full operation string - attach flags to base op as needed.    if (strcmp(operation, "df") == 0) {        sprintf(operation_str, "df");        // PREFS: df flags        if (df_flag_a) { strcat(operation_str, " -a"); }        if (df_flag_h) { strcat(operation_str, " -h"); }        if (df_flag_t) { strcat(operation_str, " -T"); }    }    else if (strcmp(operation, "ifconfig") == 0) {        // PREFS: ifconfig flag        strcpy(operation_str, "ifconfig 2>&1"); // use no flags for now!// Brent - crap!, now RH7.2 doesnt allow use of ifconfig outside of 'su'!!!// adding STDERR redirection so RH7.2 users can get feedback (12/28/2001)    strcpy(operation_str, "netstat -a --inet -p 2>&1");/* -- brent - CRAP! - 0.9.4 release testing (04/30) revealed the following:   -- RedHat 7.1 bombs when using these flags, but   -- they really arent great to begin with. (does anyone use these?! - i dont)        if (ifconfig_flag == 0) { strcpy(operation_str, "ifconfig -arp"); }        else if (ifconfig_flag == 1) { strcpy(operation_str, "ifconfig -promisc"); }        else if (ifconfig_flag == 2) { strcpy(operation_str, "ifconfig -allmulti"); }*/    }    else if (strcmp(operation, "path") == 0) {        sprintf(operation_str, "echo $PATH");    }    else if (strcmp(operation, "netstat") == 0) {        // PREFS: ifconfig flag        if (netstat_flag == 0)      { strcpy(operation_str, "netstat -u 2>&1"); }        else if (netstat_flag == 1) { strcpy(operation_str, "netstat -M 2>&1"); }        else if (netstat_flag == 2) { strcpy(operation_str, "netstat -i 2>&1"); }        else if (netstat_flag == 3) { strcpy(operation_str, "netstat -p 2>&1"); }    }    else {        strcpy(operation_str, operation);    }    // Create one way pipe line with call to popen()    if ((pipein_fp = popen(operation_str, "r")) == NULL) { perror("popen"); exit(1); }    while(fgets(readbuf, 80, pipein_fp)) {        gtk_text_insert(GTK_TEXT(text_wsutils), fixed_font_ptr, NULL, NULL, readbuf, -1);    }    pclose(pipein_fp);    // PREFS: Timestamp Screen Output    if (timestamp_scn_output) {        strcpy(timestamp_str, get_timestamp() );        gtk_text_insert(GTK_TEXT(text_wsutils), fixed_font_ptr, NULL, NULL, timestamp_str, -1);    }    // Insert divider after above output, if checkbutton clicked by client.    if (GTK_TOGGLE_BUTTON(checkbutton18)->active) {        gtk_text_insert(GTK_TEXT(text_wsutils), fixed_font_ptr, NULL, NULL,          "-------------------------------------------------------------------------------- \n", -1);    }}voidon_notebook1_switch_page (GtkNotebook     *notebook,                          GtkNotebookPage *page,                          gint             page_num,                          gpointer         user_data){    // Get pointers to window widgets, declare local vars    GtkWidget *gentry_network = lookup_widget(app1, "gentry_network");    GtkWidget *label_grep_ps  = lookup_widget(app1, "label_grep_ps");    GtkWidget *save1          = lookup_widget(app1, "save1");    GtkWidget *save_as1       = lookup_widget(app1, "save_as1");    GtkWidget *print1         = lookup_widget(app1, "print1");    GtkWidget *copy1          = lookup_widget(app1, "copy1");    GtkWidget *paste1         = lookup_widget(app1, "paste1");    GtkWidget *button_save    = lookup_widget(app1, "button_save");    GtkWidget *button_saveas  = lookup_widget(app1, "button_saveas");    GtkWidget *button_print   = lookup_widget(app1, "button_print");    GtkWidget *button_copy    = lookup_widget(app1, "button_copy");    GtkWidget *button_paste   = lookup_widget(app1, "button_paste");    gchar      grep_label_str[80];    // Network Utils Tab    if (page_num == 1) {        // Load history into Network Text GnomeEntry Widget        gentry_network = lookup_widget(app1, "gentry_network");        gnome_entry_load_history((GnomeEntry *) gentry_network);    }    // Process Grep Tab    // Change gtk_label "ps | grep" to match prefs!    else if (page_num == 2) {        // Construct the first part of the grep label string        if (grep_flag == 0) {            strcpy(grep_label_str, "ps | grep ");        }        else if (grep_flag == 1) {            strcpy(grep_label_str, "ps -e | grep ");        }        else if (grep_flag == 2) {            strcpy(grep_label_str, "ps -eH | grep ");        }        else if (grep_flag == 3) {            strcpy(grep_label_str, "ps -efH | grep ");        }        // Add `-i` flag if necessary        if (use_grep_i_flag == 1) {            strcat(grep_label_str, "-i ");        }        // Set the actual gtk_label to string value        gtk_label_set_text(GTK_LABEL(label_grep_ps), grep_label_str);    }    // Process CList    else if (page_num == 3) {        gtk_widget_set_sensitive((GtkWidget *) save1,         FALSE);        gtk_widget_set_sensitive((GtkWidget *) save_as1,      FALSE);        gtk_widget_set_sensitive((GtkWidget *) print1,        FALSE);        gtk_widget_set_sensitive((GtkWidget *) copy1,         FALSE);        gtk_widget_set_sensitive((GtkWidget *) paste1,        FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_save,   FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_saveas, FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_print,  FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_copy,   FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_paste,  FALSE);        on_process_refresh_clicked(NULL, NULL);        return;    }    // System Stats Tab    else if (page_num == 4) {        gtk_widget_set_sensitive((GtkWidget *) save1,         FALSE);        gtk_widget_set_sensitive((GtkWidget *) save_as1,      FALSE);        gtk_widget_set_sensitive((GtkWidget *) print1,        FALSE);        gtk_widget_set_sensitive((GtkWidget *) copy1,         TRUE);        gtk_widget_set_sensitive((GtkWidget *) paste1,        FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_save,   FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_saveas, FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_print,  FALSE);        gtk_widget_set_sensitive((GtkWidget *) button_copy,   TRUE);        gtk_widget_set_sensitive((GtkWidget *) button_paste,  FALSE);        update_sys_stats_tab(notebook, page, page_num, user_data);        return;    }    // Reactivate buttons that may have become inactive before in other tabs.    // The first two functs have no return statement so they do fall out here.    gtk_widget_set_sensitive((GtkWidget *) save1,         TRUE);    gtk_widget_set_sensitive((GtkWidget *) save_as1,      TRUE);    gtk_widget_set_sensitive((GtkWidget *) print1,        TRUE);    gtk_widget_set_sensitive((GtkWidget *) copy1,         TRUE);    gtk_widget_set_sensitive((GtkWidget *) paste1,        TRUE);    gtk_widget_set_sensitive((GtkWidget *) button_save,   TRUE);    gtk_widget_set_sensitive((GtkWidget *) button_saveas, TRUE);    gtk_widget_set_sensitive((GtkWidget *) button_copy,   TRUE);    gtk_widget_set_sensitive((GtkWidget *) button_paste,  TRUE);    gtk_widget_set_sensitive((GtkWidget *) button_print,  TRUE);    // We've done our few items of work for a given tab, now go on.    return;}voidupdate_sys_stats_tab (GtkNotebook     *notebook,                      GtkNotebookPage *page,                      gint             page_num,                      gpointer         user_data){    // Get pointers to window widgets, declare local vars    GtkWidget *users_clist         = lookup_widget(app1, "users_clist");    GtkWidget *entry_ipaddr        = lookup_widget(app1, "entry_ipaddr");    GtkWidget *label_apache        = lookup_widget(app1, "label_apache");    GtkWidget *label_samba         = lookup_widget(app1, "label_samba");    GtkWidget *label_sendmail      = lookup_widget(app1, "label_sendmail");    GtkWidget *label_uptime        = lookup_widget(app1, "label_uptime");    GtkWidget *label_totalram      = lookup_widget(app1, "label_totalram");    GtkWidget *label_totalswap     = lookup_widget(app1, "label_totalswap");    GtkWidget *label_hardware      = lookup_widget(app1, "label_hardware");    GtkWidget *label_kernel        = lookup_widget(app1, "label_kernel");    GtkWidget *progressbar_mem     = lookup_widget(app1, "progressbar_mem");    GtkWidget *progressbar_swap    = lookup_widget(app1, "progressbar_swap");    GtkWidget *progressbar_sleep   = lookup_widget(app1, "progressbar_sleep");    GtkWidget *progressbar_run     = lookup_widget(app1, "progressbar_run");    GtkWidget *progressbar_zombie  = lookup_widget(app1, "progressbar_zombie");    GtkWidget *progressbar_stopped = lookup_widget(app1, "progressbar_stopped");    FILE      *pipein_fp;    DIR       *dir;    struct    dirent    *dinfo;    struct    sysinfo    info;//    struct    hostent   *hostentAnswer;//    struct    in_addr   *netAddr;    char      readbuf[1024];    char      uptime_str[80]      = "";    char      apache_str[80]      = "Not Running";    char      sendmail_str[80]    = "Not Running";    char      samba_str[80]       = "Not Running";    char      users_str[1024]     = "";    char      hardware_str[80]    = "";    char      kernel_str[80]      = "";    char     *hardware_cpu;    char     *hardware_clock;    char     *hardware_machine;    char     *hardware_str_ptr;    char     *kernel_str_ptr;    char      totalram_str[80];    char      totalswap_str[80];//    char      hostname[256];    char      IPaddress[32];    char      proc_buffer[128];    char      proc_file_name[256];    char      proc_state;    char     *dir_chr;    char     *users_str_list[3] = {"user", "term", "time"};    char     *tmp1;    char     *tmp2;    char     *tmp3;    int       uptime_hours        = 0;    int       uptime_days         = 0;//    int       uptime_months       = 0;    int       num_proc_total      = 0;    int       num_proc_sleep      = 0;    int       num_proc_run        = 0;    int       num_proc_zombie     = 0;    int       num_proc_stopped    = 0;//    int       a                   = 0;    gfloat    mem_percentage    = 0.0;    gfloat    swap_percentage   = 0.0;    extern int h_errno; // Comes from <netdb.h> - used for determining error code...IPaddr    // Exee sysinfo() system call (fill struct with data).    if (sysinfo(&info) != 0) {        printf("ERROR: sysinfo call FAILED. \n");        return;    }    // ------------------    // Set Uptime TextBox    // ------------------    // 12/11 - these formulas are gay - why cant we employ UNIX-style or Oracle style (decimal pts)    //         by reading /proc/* files?    uptime_days   = (((info.uptime / 60) / 60) / 24);    uptime_hours  = (((info.uptime / 60) / 60) - (uptime_days * 24));//    uptime_months = (  uptime_days / 30  ); // help!//    sprintf(uptime_str, "%d Months, %ld Days, %0.1f Hours", uptime_months, uptime_days, uptime_hours);    sprintf(uptime_str, "%ld Days, %d Hours", (long)uptime_days, uptime_hours);    gtk_label_set_text(GTK_LABEL(label_uptime), uptime_str);    // --------------------    // Set Free/Swap Memory    // --------------------    // PREFS: display units    if (display_units == 0) {        sprintf(totalram_str,  " %ld M ", info.totalram /1048576);        sprintf(totalswap_str, " %ld M ", info.totalswap/1048576);    }    else if (display_units == 1) {        sprintf(totalram_str,  " %ld k ", info.totalram /1024);        sprintf(totalswap_str, " %ld k ", info.totalswap/1024);    }    gtk_label_set_text(GTK_LABEL(label_totalram),  totalram_str);    gtk_label_set_text(GTK_LABEL(label_totalswap), totalswap_str);    // ----------------------------------------    // Set Memory ProgressBars (i love these!)    // ----------------------------------------    mem_percentage  = ( 1 - ((float)info.freeram  / (float)info.totalram));    swap_percentage = ( 1 - ((float)info.freeswap / (float)info.totalswap));    if (swap_percentage < 0) { swap_percentage = 0; } // Keep bar looking good    gtk_progress_bar_update((GtkProgressBar *)progressbar_mem,  mem_percentage);    gtk_progress_bar_update((GtkProgressBar *)progressbar_swap, swap_percentage);/*    gtk_progress_configure((GtkProgress *)progressbar_mem,                           (gfloat)(info.totalram/1000000 - info.freeram/1000000),                            0.0, (gfloat)info.totalram/1000000);*/// above is experimental (unused in 0.9.5) - 06/15/01

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -