Ejemplo n.º 1
0
void
msg_diff_create(ui_t *ui)
{
    int hwidth;
    msg_diff_info_t *info;

    // Create a new panel to fill all the screen
    ui_panel_create(ui, LINES, COLS);

    // Initialize panel specific data
    info = sng_malloc(sizeof(msg_diff_info_t));

    // Store it into panel userptr
    set_panel_userptr(ui->panel, (void*) info);

    // Calculate subwindows width
    hwidth = ui->width / 2 - 1;

    // Create 2 subwindows, one for each message
    info->one_win = subwin(ui->win, ui->height - 2, hwidth, 1, 0);
    info->two_win = subwin(ui->win, ui->height - 2, hwidth, 1, hwidth + 1); // Header - Footer - Address

    // Draw a vertical line to separe both subwindows
    mvwvline(ui->win, 0, hwidth, ACS_VLINE, ui->height);

    // Draw title
    ui_set_title(ui, "sngrep - SIP messages flow viewer");

    // Draw keybindings
    msg_diff_draw_footer(ui);
}
Ejemplo n.º 2
0
int ui_gtk_initialize(int argc, char *argv[])
{
    GtkWidget *vbox;

    /* Create the main window */
    ui_main_data.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    ui_init_filters (TRUE, FALSE);

    // gtk_window_set_default_icon_from_file ("../analyzer.png", NULL);
    gtk_window_set_default_icon_name (GTK_STOCK_FIND);

    gtk_window_set_position (GTK_WINDOW(ui_main_data.window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size (GTK_WINDOW(ui_main_data.window), 1024, 800);
    ui_set_title("");
    gtk_window_set_resizable (GTK_WINDOW(ui_main_data.window), TRUE);

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

    CHECK_FCT(ui_menu_bar_create(vbox));
    CHECK_FCT(ui_toolbar_create(vbox));
    CHECK_FCT(ui_notebook_create(vbox));

    gtk_container_add (GTK_CONTAINER(ui_main_data.window), vbox);

    /* Assign the destroy event */
    g_signal_connect(ui_main_data.window, "destroy", ui_main_window_destroy, NULL);

    /* Show the application window */
    gtk_widget_show_all (ui_main_data.window);

    g_idle_add (ui_idle_callback, NULL);

    return RC_OK;
}
Ejemplo n.º 3
0
int ui_enable_connect_button(void)
{
    /* Disable Disconnect button and enable connect button */
    gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.connect), TRUE);
    gtk_widget_set_sensitive (GTK_WIDGET (ui_main_data.disconnect), FALSE);
    socket_abort_connection = TRUE;
    ui_set_sensitive_save_message_buttons (TRUE);
    ui_set_title ("");

    return RC_OK;
}
Ejemplo n.º 4
0
static void menu_cardview_analyzer_load_cb(GtkWidget *w, gpointer user_data)
{
    char **select_info;
    UNUSED(w);
    UNUSED(user_data);

    select_info = ui_select_file("Load card script",path_config_get_string(PATH_CONFIG_FOLDER_SCRIPTS),NULL);

    if (select_info[1])
    {
        path_config_set_string(PATH_CONFIG_FOLDER_WORKING,select_info[0]);
        chdir(select_info[0]);
        ui_set_title(select_info[1]);
        luax_run_script(select_info[1]);
        g_free(select_info[0]);
        g_free(select_info[1]);
    }
}
Ejemplo n.º 5
0
static void menu_run_script_cb(GtkWidget *widget,
                               gpointer callback_data,
                               guint callback_action)
{
    ScriptInfo *script = (ScriptInfo *)callback_data;
    UNUSED(widget);
    UNUSED(callback_action);

    if (!script->script_targeted_version)
    {
        log_printf(LOG_WARNING,"The script '%s' does not contain version information, and may use an older incompatible API", script->script_file);
        log_printf(LOG_WARNING,"To remove this warning, add the following line at the begining of '%s':\n\t -- @targets %s", script->script_file, VERSION);
    }

    ui_set_title(script->script_name);
    luax_run_script(script->script_file);
    gtk_tree_view_expand_all (GTK_TREE_VIEW(CARDVIEW));
    ui_update(0);
}
Ejemplo n.º 6
0
int ui_messages_read(char *file_name)
{
    int result = RC_OK;
    int source;
    int read_data = 0;
    void *input_data = NULL;
    size_t input_data_length = 0;
    int read_messages = 0;

    ui_change_cursor (TRUE);

    source = open (file_name, O_RDONLY);
    if (source < 0)
    {
        ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "open messages", "Failed to open file \"%s\": %s", file_name,
                                g_strerror (errno));
        result = RC_FAIL;
    }
    else
    {
        itti_socket_header_t message_header;
        struct stat st;
        int size;
        double read_fraction = 0.f;

        if (stat (file_name, &st) < 0)
        {
            ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "get file length",
                                    "Failed to retrieve length for file \"%s\": %s", file_name, g_strerror (errno));
            result = RC_FAIL;
        }
        size = st.st_size;

        ui_callback_signal_clear_list (NULL, NULL);

        /* Initialize the progress bar */
        ui_abort = FALSE;
        ui_progress_bar_set_fraction (0);

        do
        {
            read_data = read (source, &message_header, sizeof(itti_socket_header_t));

            if (read_data == -1)
            {
                ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "open messages", "Failed to read from file \"%s\": %s",
                                        file_name, g_strerror (errno));
                result = RC_FAIL;
                break;
            }

            if (read_data == 0)
            {
                break;
            }

            if (read_data < sizeof(itti_socket_header_t))
            {
                if (ui_notification_dialog (GTK_MESSAGE_WARNING, TRUE, "open messages",
                                            "Failed to read a complete message header from file \"%s\": %s", file_name, g_strerror (errno)) == RC_FAIL)
                {
                    read_data = 0;
                }
            }
            else
            {
                read_fraction += (double) read_data / size;

                input_data_length = message_header.message_size - sizeof(itti_socket_header_t);

                g_debug("%x, %x, %zd", message_header.message_type, message_header.message_size, input_data_length);

                /* Checking for non-header part */
                if (input_data_length > 0)
                {
                    input_data = malloc (input_data_length);

                    read_data = read (source, input_data, input_data_length);
                    if (read_data < input_data_length)
                    {
                        if (ui_notification_dialog (GTK_MESSAGE_WARNING, TRUE, "open messages",
                                                    "Failed to read a complete message from file \"%s\": %s", file_name, g_strerror (errno)) == RC_FAIL)
                        {
                            read_data = 0;
                        }
                        break;
                    }

                    read_fraction += (double) input_data_length / size;
                }

                switch (message_header.message_type)
                {
                    case ITTI_DUMP_XML_DEFINITION:
                        ui_gtk_flush_events ();
                        if (memcmp (&(((char *) input_data)[input_data_length - sizeof (itti_message_types_t)]),
                            &itti_dump_xml_definition_end, sizeof (itti_message_types_t)) == 0)
                        {
                            result = xml_parse_buffer (input_data, input_data_length - sizeof (itti_message_types_t));
                            if (result != RC_OK)
                            {
                                ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "open messages",
                                                        "Error in parsing XML definitions in file \"%s\": %s", file_name,
                                                        rc_strings[-result]);
                                read_data = 0;
                            }
                            ui_gtk_flush_events ();
                            g_message("Parsed XML definition from file \"%s\"", file_name);
                        }
                        else
                        {
                            ui_notification_dialog (GTK_MESSAGE_ERROR, FALSE, "open messages",
                                                    "Error in parsing XML definitions in file \"%s\", end mark is missing", file_name);
                        }
                        /* Data input buffer is kept in case user when to save the log file later */
                        break;

                    case ITTI_DUMP_MESSAGE_TYPE:
                    {
                        itti_signal_header_t *itti_signal_header = input_data;
                        buffer_t *buffer;

                        if (memcmp (&(((char *) input_data)[input_data_length - sizeof (itti_message_types_t)]),
                            &itti_dump_message_type_end, sizeof (itti_message_types_t)) == 0)
                        {
                            /* Create the new buffer */
                            if (buffer_new_from_data (&buffer, input_data + sizeof(itti_signal_header_t),
                                                      input_data_length - sizeof(itti_signal_header_t) - sizeof(itti_message_types_t), 0) != RC_OK)
                            {
                                g_error("Failed to create new buffer");
                                g_assert_not_reached ();
                            }

                            sscanf (itti_signal_header->message_number_char, MESSAGE_NUMBER_CHAR_FORMAT, &buffer->message_number);

                            ui_signal_add_to_list (buffer, ((read_messages % 1000) == 0) ? (gpointer) 1 : NULL);

                            if ((read_messages % 100) == 0)
                            {
                                ui_progress_bar_set_fraction (read_fraction);
                                ui_gtk_flush_events ();
                            }

                            read_messages++;
                        }
                        else
                        {
                            if (ui_notification_dialog (GTK_MESSAGE_WARNING, TRUE, "open messages",
                                                        "Failed to read a message from file \"%s\", end mark is missing", file_name) == RC_FAIL)
                            {
                                read_data = 0;
                            }
                            break;
                        }

                        free (input_data);
                        break;
                    }

                    case ITTI_STATISTIC_MESSAGE_TYPE:
                    default:
                        if (ui_notification_dialog (GTK_MESSAGE_WARNING, TRUE, "open messages",
                                                    "Unknown (or not implemented) record type: %d in file \"%s\"",
                                                    message_header.message_type, file_name) == RC_FAIL)
                        {
                            read_data = 0;
                        }

                        free (input_data);
                        break;
                }
            }
        } while ((ui_abort == FALSE) && (read_data > 0));

        if (read_messages > 0)
        {
            char *basename;

            /* Enable buttons to move in the list of signals */
            ui_set_sensitive_move_buttons (TRUE);

            if (ui_main_data.follow_last)
            {
                /* Advance to the last signal */
                ui_tree_view_select_row (ui_tree_view_get_filtered_number () - 1);
            }

            basename = g_path_get_basename (file_name);
            ui_set_title ("\"%s\"", basename);
        }
        else
        {
            result = RC_FAIL;
        }

        ui_progress_bar_terminate ();

        g_message("Read %d messages (%d to display) from file \"%s\"\n", read_messages, ui_tree_view_get_filtered_number(), file_name);

        close (source);
    }

    ui_change_cursor (FALSE);

    return result;
}
Ejemplo n.º 7
0
int install_from_cwd(Options *op)
{
    Package *p;
    CommandList *c;
    int ret;
    int ran_pre_install_hook = FALSE;
    HookScriptStatus res;

    static const char* edit_your_xf86config =
        "Please update your XF86Config or xorg.conf file as "
        "appropriate; see the file /usr/share/doc/"
        "NVIDIA_GLX-1.0/README.txt for details.";

    /*
     * validate the manifest file in the cwd, and process it, building
     * a Package struct
     */
    
    if ((p = parse_manifest(op)) == NULL) goto failed;

    if (!op->x_files_packaged) {
        edit_your_xf86config = "";
    }

    ui_set_title(op, "%s (%s)", p->description, p->version);
    
    /* 
     * warn the user if "legacy" GPUs are installed in this system
     * and if no supported GPU is found, at all.
     */

    check_for_nvidia_graphics_devices(op, p);

    /* check that we are not running any X server */

    if (!check_for_running_x(op)) goto failed;

    /* make sure the kernel module is unloaded */
    
    if (!check_for_unloaded_kernel_module(op)) goto failed;
    
    /* ask the user to accept the license */
    
    if (!get_license_acceptance(op)) goto exit_install;
    
    ui_log(op, "Installing NVIDIA driver version %s.", p->version);

    /*
     * determine the current NVIDIA version (if any); ask the user if
     * they really want to overwrite the existing installation
     */

    if (!check_for_existing_driver(op, p)) goto exit_install;

    /*
     * check to see if an alternate method of installation is already installed
     * or is available, but not installed; ask the user if they really want to
     * install anyway despite the presence/availability of an alternate install.
     */

    if (!check_for_alternate_install(op)) goto exit_install;

    /* run the distro preinstall hook */

    res = run_distro_hook(op, "pre-install");
    if (res == HOOK_SCRIPT_FAIL) {
        if (ui_multiple_choice(op, CONTINUE_ABORT_CHOICES,
                               NUM_CONTINUE_ABORT_CHOICES,
                               CONTINUE_CHOICE, /* Default choice */
                               "The distribution-provided pre-install "
                               "script failed!  Are you sure you want "
                               "to continue?") == ABORT_CHOICE) {
            goto failed;
        }
    } else if (res == HOOK_SCRIPT_SUCCESS) {
        if (ui_multiple_choice(op, CONTINUE_ABORT_CHOICES,
                               NUM_CONTINUE_ABORT_CHOICES,
                               CONTINUE_CHOICE, /* Default choice */
                               "The distribution-provided pre-install script "
                               "completed successfully. If this is the first "
                               "time you have run the installer, this script "
                               "may have helped disable Nouveau, but a reboot "
                               "may be required first.  "
                               "Would you like to continue, or would you "
                               "prefer to abort installation to reboot the "
                               "system?") == ABORT_CHOICE) {
            goto exit_install;
        }
        ran_pre_install_hook = TRUE;
    }

    /* fail if the nouveau driver is currently in use */

    if (!check_for_nouveau(op)) goto failed;

    /* ask if we should install the UVM kernel module */

    should_install_uvm(op, p);

    /* attempt to build the kernel modules for the target kernel */

    if (!op->no_kernel_module) {
        if (!install_kernel_modules(op, p)) {
            goto failed;
        }
    } else {
        ui_warn(op, "You specified the '--no-kernel-module' command line "
                "option, nvidia-installer will not install a kernel "
                "module as part of this driver installation, and it will "
                "not remove existing NVIDIA kernel modules not part of "
                "an earlier NVIDIA driver installation.  Please ensure "
                "that an NVIDIA kernel module matching this driver version "
                "is installed seperately.");

        /* no_kernel_module should imply no DKMS */

        if (op->dkms) {
            ui_warn(op, "You have specified both the '--no-kernel-module' "
                    "and the '--dkms' command line options. The '--dkms' "
                    "option will be ignored.");
            op->dkms = FALSE;
        }
    }
    
    /*
     * if we are only installing the kernel module, then remove
     * everything else from the package; otherwise do some
     * OpenGL-specific stuff
     */

    if (op->kernel_module_only) {
        remove_non_kernel_module_files_from_package(op, p);
    } else {

        /* ask for the XFree86 and OpenGL installation prefixes. */
    
        if (!get_prefixes(op)) goto failed;

        /* ask if we should install the OpenGL header files */

        should_install_opengl_headers(op, p);

        /*
         * select the appropriate TLS class, modifying the package as
         * necessary.
         */
    
        select_tls_class(op, p);

        /*
         * if the package contains any libGL.la or .desktop files,
         * process them (perform some search and replacing so
         * that they reflect the correct installation path, etc)
         * and add them to the package list (files to be installed).
         */
        
        process_libGL_la_files(op, p);
        process_dot_desktop_files(op, p);

#if defined(NV_X86_64)
        /*
         * ask if we should install the 32bit compatibility files on
         * this machine.
         */

        should_install_compat32_files(op, p);
#endif /* NV_X86_64 */
    }

    if (op->no_opengl_files) {
        remove_opengl_files_from_package(op, p);
    }

    /*
     * now that we have the installation prefixes, build the
     * destination for each file to be installed
     */
    
    if (!set_destinations(op, p)) goto failed;

    /*
     * if we are installing OpenGL libraries, ensure that a symlink gets
     * installed to /usr/lib/libGL.so.1. add_libgl_abi_symlink() sets its own
     * destination, so it must be called after set_destinations().
     */
    if (!op->kernel_module_only && !op->no_opengl_files) {
        add_libgl_abi_symlink(op, p);
    }
    
    /*
     * uninstall the existing driver; this needs to be done before
     * building the command list.
     *
     * XXX if we uninstall now, then build the command list, and
     * then ask the user if they really want to execute the
     * command list, if the user decides not to execute the
     * command list, they'll be left with no driver installed.
     */

    if (!op->kernel_module_only) {
        if (!run_existing_uninstaller(op)) goto failed;
    }

    if (!check_libglvnd_files(op, p)) {
        goto failed;
    }

    /* build a list of operations to execute to do the install */
    
    if ((c = build_command_list(op, p)) == NULL) goto failed;

    /* call the ui to get approval for the list of commands */
    
    if (!ui_approve_command_list(op, c, "%s", p->description)) {
        goto exit_install;
    }
    
    /* initialize the backup log file */

    if (!op->kernel_module_only) {
        if (!init_backup(op, p)) goto failed;
    }

    /* execute the command list */

    if (!do_install(op, p, c)) goto failed;

    /* Register, build, and install the module with DKMS, if requested */

    if (op->dkms && !dkms_install_module(op, p->version, get_kernel_name(op)))
        goto failed;

    /*
     * Leave the RM loaded in case an X server with OutputClass-based driver
     * matching is being used.
     */

    if (!op->no_kernel_module || op->dkms) {
        if (!load_kernel_module(op, p->kernel_modules[0].module_name)) {
            goto failed;
        }
    }

    /* run the distro postinstall script */

    run_distro_hook(op, "post-install");

    /*
     * check that everything is installed properly (post-install
     * sanity check)
     */

    check_installed_files_from_package(op, p);

    if (!check_runtime_configuration(op, p)) goto failed;
    
    /* done */

    if (op->kernel_module_only || op->no_nvidia_xconfig_question) {

        ui_message(op, "Installation of the kernel module for the %s "
                   "(version %s) is now complete.",
                   p->description, p->version);
    } else {
        
        /* ask the user if they would like to run nvidia-xconfig */
        
        const char *msg = "Would you like to run the nvidia-xconfig utility "
                          "to automatically update your X configuration file "
                          "so that the NVIDIA X driver will be used when you "
                          "restart X?  Any pre-existing X configuration "
                          "file will be backed up.";
        
        ret = run_nvidia_xconfig(op, FALSE, msg, op->run_nvidia_xconfig);
        
        if (ret) {
            ui_message(op, "Your X configuration file has been successfully "
                       "updated.  Installation of the %s (version: %s) is now "
                       "complete.", p->description, p->version);
        } else {
            ui_message(op, "Installation of the %s (version: %s) is now "
                       "complete.  %s", p->description,
                       p->version, edit_your_xf86config);
        }
    }
    
    free_package(p);

    return TRUE;
    
 failed:

    /*
     * something bad happened during installation; print an error
     * message and return FALSE
     */
    
    if (op->logging) {
        ui_error(op, "Installation has failed.  Please see the file '%s' "
                 "for details.  You may find suggestions on fixing "
                 "installation problems in the README available on the "
                 "Linux driver download page at www.nvidia.com.",
                 op->log_file_name);
    } else {
        ui_error(op, "Installation has failed.  You may find suggestions "
                 "on fixing installation problems in the README available "
                 "on the Linux driver download page at www.nvidia.com.");
    }

    if (ran_pre_install_hook)
        run_distro_hook(op, "failed-install");

    /* fall through into exit_install... */

 exit_install:

    /*
     * we are exiting installation; this can happen for reasons that
     * do not merit the error message (e.g., the user declined the
     * license agreement)
     */
    
    free_package(p);
    
    return FALSE;

} /* install_from_cwd() */
Ejemplo n.º 8
0
void
log_open(GSList   *filenames,
         gboolean  merge)
{
    gchar *filename;
    gzFile gzfp;
    gint n, err;
    guchar buffer[READ_BUFFER_LEN];
    const gchar *err_string;

    yajl_handle json;
    yajl_status status;
    read_ctx_t context;

    if(ui.changed && !ui_dialog_ask_unsaved())
        return;

    context.merge = merge;
    context.changed = FALSE;

    if(!merge)
        ui_clear();

    ui_view_lock(ui.treeview);

    while(filenames != NULL)
    {
        filename = (gchar*)filenames->data;
        gzfp = gzopen(filename, "r");
        if(!gzfp)
        {
            ui_dialog(ui.window,
                      GTK_MESSAGE_ERROR,
                      "Error",
                      "Failed to open a file:\n%s", filename);
        }
        else
        {
            context.key = KEY_UNKNOWN;
            context.level = LEVEL_ROOT;
            context.level_signals = FALSE;
            context.signal = NULL;
            network_init(&context.network);

            json = yajl_alloc(&json_callbacks, NULL, &context);
            do
            {
                n = gzread(gzfp, buffer, READ_BUFFER_LEN-1);
                status = yajl_parse(json, buffer, n);

                if(n < READ_BUFFER_LEN-1)
                {
                    if(gzeof(gzfp))
                        break;
                    err_string = gzerror(gzfp, &err);
                    if(err)
                    {
                        ui_dialog(ui.window,
                                  GTK_MESSAGE_ERROR,
                                  "Error",
                                  "Failed to read a file:\n%s\n\n%s",
                                  filename, err_string);
                        break;
                    }
                }
            } while (status == yajl_status_ok);
            gzclose(gzfp);

            if(status == yajl_status_ok)
                status = yajl_complete_parse(json);

            yajl_free(json);

            if(status != yajl_status_ok)
            {
                network_free(&context.network);
                g_free(context.signal);
                ui_dialog(ui.window,
                          GTK_MESSAGE_ERROR,
                          "Error",
                          "The selected file is corrupted or is not a valid MTscan log:\n%s",
                          filename);
            }
            else if(!merge)
            {
                /* Take the allocated filename for the UI */
                ui_set_title(filename);
                filenames->data = NULL;
            }
        }
        filenames = filenames->next;
    }

    ui_view_unlock(ui.treeview);

    if(context.changed)
    {
        ui_status_update_networks();
        if(merge)
        {
            /* Set filename to NULL after merge */
            ui_set_title(NULL);
            ui_changed();
        }
    }
}