int drop_rule(dialogMenuItem * self) { FILE *stream = NULL; int d = atoi(self->prompt); int i = 0; unlink(RULESCRIPT); stream = fopen(RULESCRIPT, "a+"); if (stream == NULL) return -1; for (i = 0; i <= 50; ++i) if (rlist[i].title) if (atoi(rlist[i].prompt) != d) fprintf(stream, "/sbin/ipfw -q%s\n", rlist[i].title); fclose(stream); system("/sbin/ipfw -q flush"); system("/sbin/chmod 755 /etc/rules"); system("/bin/sh /etc/rules"); dialog_clear(); dialog_msgbox("ClosedBSD", "Rule deleted ", -1, -1, 1); return 0; }
static int display_menu(void) { int ret=0; int maxx,maxy; int curr; do_init_dialog(); getmaxyx(stdscr, maxy, maxx); dialog_vars.help_button=1; dialog_vars.item_help=1; loop: switch(ret=dlg_checklist("Welcome to pkg_cleanup.", "These are the leaf packages installed on your system\nChose the packages to deinstall. Help will display the package description.", maxy-1, maxx, maxy-9, menulen, menu, " X", FLAG_CHECK, &curr)) { case DLG_EXIT_HELP: { char *p = read_desc(menu[curr].ITEM_PROMPT); if(p) { dialog_vars.help_button=0; dialog_msgbox(menu[curr].ITEM_DATA, p, maxy-4, maxx-4, TRUE); dialog_vars.help_button=1; free(p); } goto loop; } case 0: ret=0; break; default: ret=-1; break; } dialog_vars.help_button=0; dialog_vars.item_help=0; end_dialog(); return(ret); }
static DC_Dev *menu_choose_device(DC_DevList *devlist) { int devs_num = dc_dev_list_size(devlist); if (devs_num == 0) { dialog_msgbox("Info", "No devices found", 0, 0, 1); return NULL; } char *items[2 * devs_num]; int i; for (i = 0; i < devs_num; i++) { DC_Dev *dev = dc_dev_list_get_entry(devlist, i); char dev_descr_buf[80]; ui_dev_descr_format(dev_descr_buf, sizeof(dev_descr_buf), dev); items[2*i] = dev->dev_fs_name; items[2*i+1] = strdup(dev_descr_buf); } clear_body(); dialog_vars.no_items = 0; dialog_vars.item_help = 0; dialog_vars.input_result = NULL; dialog_vars.default_button = 0; // Focus on "OK" int ret = dialog_menu("Choose device", "", 0, 0, 0, devs_num, items); for (i = 0; i < devs_num; i++) free(items[2*i+1]); if (ret != 0) return NULL; for (i = 0; i < devs_num; i++) { DC_Dev *dev = dc_dev_list_get_entry(devlist, i); if (!strcmp(dev->dev_fs_name, dialog_vars.input_result)) return dev; } assert(0); return NULL; }
static void gpart_show_error(const char *title, const char *explanation, const char *errstr) { char *errmsg; char message[512]; int error; if (explanation == NULL) explanation = ""; error = strtol(errstr, &errmsg, 0); if (errmsg != errstr) { while (errmsg[0] == ' ') errmsg++; if (errmsg[0] != '\0') sprintf(message, "%s%s. %s", explanation, strerror(error), errmsg); else sprintf(message, "%s%s", explanation, strerror(error)); } else { sprintf(message, "%s%s", explanation, errmsg); } dialog_msgbox(title, message, 0, 0, TRUE); }
static int j_infobox(JUMPARGS) { *offset_add = 4; return dialog_msgbox(t, av[1], numeric_arg(av, 2), numeric_arg(av, 3), 0); }
int _afm_flush(dialogMenuItem *self) { dialog_clear(); system("/sbin/ipfw -q flush"); unlink("/etc/rules"); dialog_msgbox("ClosedBSD", "Ruleset has been cleared.", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
void MainWindow::progress(string title, string msg) { if (msg.empty()) { msg = title; title = "Status"; } reinitScreen(); dialog_msgbox(title.c_str(), msg.c_str(),3,50,0); }
/* Goes through the glob contents, looking for zero-length +REQUIRED-BY */ static int read_pkglist(int loops) { FILE *pkg; char line[1024]; char *p; do_init_dialog(); dialog_msgbox(NULL, "Searching for leaves", 5, 23, FALSE); fflush(stdout); pkg=popen("/usr/sbin/pkg query -e \"%#r=0 && %k=0\" \"%n-%v\\t%c\"", "r"); if(!pkg) { fputs("Error executing pkg.\n", stderr); return -1; } while(fgets(line, sizeof(line), pkg)!=NULL) { for(p=strchr(line, 0)-1; p>line && isspace(*p); p--) *p=0; p=strtok(line, "\t"); p=strtok(NULL, "\0"); add_item(line, p?p:""); } if(WEXITSTATUS(pclose(pkg)) && menulen==0) { fputs("pkg returned an error.\n", stderr); return -1; } dlg_clear(); if(menulen==0) { if(loops) dialog_msgbox(NULL, "No new leaves found", 5, 23, TRUE); else dialog_msgbox(NULL, "No leaves found", 5, 19, TRUE); end_dialog(); return(-1); } end_dialog(); return(0); }
/* Kick it off, James! */ int main(int argc, char **argv) { int retval; init_dialog(); retval = dialog_msgbox("This is dialog_msgbox() in action with pause on", "Hi there. Please press return now.", -1, -1, 1); dialog_clear(); fprintf(stderr, "returned value for dialog_msgbox was %d\n", retval); end_dialog(); return 0; }
int delete_rule() { FILE *stream = NULL; int i = 0; char buf[256]; char pr[3]; char *s; dialog_clear(); stream = fopen(RULESCRIPT, "r"); if (stream == NULL) { end_dialog(); return -1; } dialog_clear(); bzero(rlist, sizeof(rlist)); while (fgets(buf, sizeof(buf), stream) != NULL) { if (strlen(buf) > 1) { buf[strlen(buf) - 1] = '\0'; if (i < 9) snprintf(pr, sizeof(pr), "0%d", i + 1); else snprintf(pr, sizeof(pr), "%d", i + 1); strtok(strdup(buf), "q"); s = strtok(NULL, "q"); rlist[i].prompt = strdup(pr); rlist[i].title = s; rlist[i].checked = NULL; rlist[i].fire = drop_rule; i++; } } if (i == 0) { dialog_msgbox("ClosedBSD", "There are no rules to delete ", -1, -1, 1); fclose(stream); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } fclose(stream); dialog_menu("ClosedBSD", "Please select a rule to remove", -1, -1, i, -i, rlist, NULL, NULL, NULL); return 0; }
static int ask_option_value(DC_Procedure *act, DC_OptionSetting *setting, DC_ProcedureOption *option) { char *suggested_value = setting->value; char entered_value[200]; const char *param_type_str; char *config_supplied_value; char *config_suggested_value; char config_search_command[200]; snprintf(config_search_command, sizeof(config_search_command), "grep ^%s.%s= ~/.whddrc 2>/dev/null | awk -F= '{print $2}' | tr -d '\\n'", act->name, option->name); config_supplied_value = cmd_output(config_search_command); if (config_supplied_value) { setting->value = config_supplied_value; return 0; } snprintf(config_search_command, sizeof(config_search_command), "grep ^%s.%s.suggest= ~/.whddrc 2>/dev/null | awk -F= '{print $2}' | tr -d '\\n'", act->name, option->name); config_suggested_value = cmd_output(config_search_command); if (config_suggested_value) suggested_value = config_suggested_value; switch (option->type) { case DC_ProcedureOptionType_eInt64: param_type_str = "numeric"; break; case DC_ProcedureOptionType_eString: param_type_str = "string"; break; } char prompt[500]; snprintf(prompt, sizeof(prompt), "Please enter %s parameter: %s (%s)", param_type_str, option->name, option->help); dialog_vars.default_button = -1; // Workaround for surprisingly unfocused input field on old libdialog dialog_vars.input_result = NULL; int r = dialog_inputbox("Input box", prompt, 0, 0, suggested_value, 0); if (r != 0) { dialog_msgbox("Info", "Action cancelled", 0, 0, 1); return 1; } // Wow, libdialog is awesomely sane and brilliantly documented lib, i f****n love it snprintf(entered_value, sizeof(entered_value), "%s", dialog_vars.input_result); if (entered_value[0] == '\0' || entered_value[0] == '\n') snprintf(entered_value, sizeof(entered_value), "%s", suggested_value); setting->value = strdup(entered_value); free(suggested_value); return 0; }
/* Put up a message in a popup information box */ void msgNotify(const char *fmt, ...) { va_list args; char *errstr; errstr = (char *)alloca(FILENAME_MAX); va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); use_helpline(NULL); use_helpfile(NULL); if (isDebug()) msgDebug("Notify: %s\n", errstr); dialog_msgbox(NULL, errstr, -1, -1, 0); }
void MainWindow::startISCSI() { mountSystemPartition(); progress("Loading iSCSI drivers"); system("gzip -dc /boot/shared.tgz | tar x -C /"); system("modprobe iscsi_tcp"); progress("Enabling network interface"); b.startNetworking(); progress("Connecting to iSCSI SAN"); if (system("sh /boot/iscsi.sh 2>/dev/null") != 0) { dialog_msgbox("iSCSI error", "Error connecting to server",5,50,1); } system("ln -s /dev/sda1 /dev/iscsi"); b.umountSystemPartition(); }
static void ask(dialogMenuItem *self, int is_selected) { if (is_selected) { char *str; if (!strcmp(self->prompt, "1000")) str = "You'd better ask both your parents first! "; else if (!strcmp(self->prompt, "500")) str = "You'd better at least ask your Dad! "; else str = "Yes, being frugal is probably a good idea!"; DialogX = 15; DialogY = 17; dialog_msgbox("Free Advice", str, -1, -1, 0); } }
int run(GList **config) { char *version = get_version(); char *title=NULL; asprintf(&title, _("Welcome to %s"), version); dialog_vars.backtitle=gen_backtitle(_("Welcome")); dlg_put_backtitle(); dlg_clear(); dialog_msgbox(title, _("Welcome among the users of Frugalware!\n\n" "The aim of creating Frugalware was to help you to do your work " "faster and simpler. We hope that you will like our " "product.\n\n" "The Frugalware Developer Team"), 0, 0, 1); FREE(version); return(0); }
/* Tell the user there's some output to go look at */ void msgWeHaveOutput(const char *fmt, ...) { va_list args; char *errstr; WINDOW *w = savescr(); errstr = (char *)alloca(FILENAME_MAX); va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); use_helpline(NULL); use_helpfile(NULL); msgDebug("Notify: %s\n", errstr); dialog_clear_norefresh(); sleep(2); dialog_msgbox(NULL, errstr, -1, -1, 0); restorescr(w); }
void MainWindow::mountSystemPartition() { bool success = false; reinitScreen(); progress("Mounting system partition...", "Waiting for storage..."); /* Attempt mounting the data partition 10 times, at 0.5 second intervals */ for (unsigned int i=0; i<10 && !success; i++) { if (i != 0) usleep(500000); success = b.mountSystemPartition(); } if (!success) { dialog_msgbox("Mount error", "Error mounting system partition.",5,50,1); } }
static int _menu1_sa_action(dialogMenuItem * self) { int ret; dialog_clear(); dialog_msgbox("ClosedBSD", "Please insert a floppy diskette and press a key.", -1, -1, 1); dialog_clear(); if ((ret = system("/sbin/mount /dev/fd0 /mnt")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "This floppy is not formatted. Press a key to format. (This may take a few minutes)", -1, -1, 1); dialog_clear(); dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 10); if ((ret = system("/sbin/fdformat -y /dev/fd0 >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Some error occured during 'fdformat'. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 30); if ((ret = system("/sbin/disklabel -w -r /dev/fd0 fd1440 >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Some error occured during 'disklabel'. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 60); if ((ret = system("/sbin/newfs -T fd1440 /dev/fd0 fd1440 >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Some error occured during 'newfs'. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } dialog_gauge("ClosedBSD", "Formatting /dev/fd0", 10, 1, 7, 70, 100); if ((ret = system("/sbin/mount /dev/fd0 /mnt >/dev/null")) != 0) { dialog_clear(); dialog_msgbox("ClosedBSD", "Unable to mount floppy. Contact [email protected].", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } system("/sbin/writetcnp"); } else system("/sbin/umount /dev/fd0"); system("/sbin/writetcnp"); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; }
void MainWindow::exec() { bool success = false; size_t pos; string datadev, options = b.getBootOptions(); if ((pos = options.find("datadev=")) != string::npos) { datadev = options.substr(pos+8); if ((pos = datadev.find(" ")) != string::npos || (pos = datadev.find("\n")) != string::npos) datadev = datadev.substr(0, pos); if (datadev == "iscsi") { startISCSI(); } } else { initializeA10(); startInstaller(); return; } reinitScreen(); progress("Mounting data partition...", "Waiting for storage... "+datadev); /* Wait 10 seconds for named data partition */ b.waitForDevice(datadev); success = b.mountDataPartition(datadev); if (!success) { progress("Searching other partitions...", "Data is not at "+datadev); datadev.clear(); /* Search 4 times */ for (unsigned int i=0; i<4 && datadev.empty(); i++) { if (i != 0) sleep(1); datadev = b.getPartitionByLabel(); } if (!datadev.empty()) { progress("Mounting data partition...", "Found other berryboot partition to mount... "+datadev); success = b.mountDataPartition(datadev); } } initializeA10(); reinitScreen(); if (!success) { //dialog_msgbox("No data found...", "No existing data found, performing a new installation",0,0,1); dialog_msgbox("No data found...", "Cannot find my data partition :-(",5,50,1); return; } if (b.file_exists(runonce_file)) { progress("Removing runonce file"); string runonce = b.file_get_contents(runonce_file); unlink(runonce_file); sync(); std::cerr << runonce; return; } map<string,string> images = b.listInstalledImages(); /* Default selection */ if (!images.empty() && options.find("nobootmenutimeout") == string::npos ) { string def; if (b.file_exists(default_file)) def = b.file_get_contents(default_file); else def = images.begin()->first; if (b.file_exists("/mnt/images/"+def)) { time_t t1 = time(NULL); dialog_pause("", "Press <enter> if you wish to access the boot menu...",9,50,2); /* return code from dialog_pause is not very useful (returns both OK in case of timeout and when key is pressed) * as a workaround just look at the time elapsed */ if (time(NULL)-t1 >= 3) { bootImage(def); return; } } } /* Boot menu */ const char **menulist = new const char *[(images.size()+1)*2]; unsigned int nr = 0; for (map<string,string>::iterator iter = images.begin(); iter != images.end(); iter++) { menulist[nr++] = iter->second.c_str(); menulist[nr++] = ""; } menulist[nr++] = "Operating system installer"; menulist[nr++] = ""; dialog_menu("", "Select operating system to boot:", 15, 50, 10, images.size()+1, (char **) menulist); if (dialog_vars.input_result && dialog_vars.input_result[0]) { if (strcmp(dialog_vars.input_result, "Operating system installer") == 0) { startInstaller(); } else { /* Find image name by friendly name */ string friendlyname = dialog_vars.input_result; for (map<string,string>::iterator iter = images.begin(); iter != images.end(); iter++) { if (iter->second == friendlyname) { bootImage(iter->first); break; } } } } delete menulist; }
void /* ANSI C can bite me */ main() { int rc; char result[20]; int sc=0, ch=0; extern int LINES, COLS; init_dialog(); while (1) { rc = dialog_menu(0, "Choose a dialog function to test", LINES-2, COLS-2, NRCHOICES, NRCHOICES, choices, result, &sc, &ch); if (rc != 0) break; if (strstr(result, "menu")) { int sc2=0, ch2=0; rc = dialog_menu("menu", "menu box", -1, -1, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); sc2=0, ch2=0; rc = dialog_menu("menu", "menu box\nnumber 2", 13, 35, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"check")) { rc = dialog_checklist("checklist", "checklist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"radio")) { rc = dialog_radiolist("radiolist", "radiolist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result, "notify")) dialog_notify("A Notification box"); else if (strstr(result, "msg")) { dialog_msgbox("msgbox", "Sleeping 2 seconds on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "Sleeping 1 second on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "A msg box that wants user input", -1, -1, 1); } else if (strstr(result, "mesg")) dialog_mesgbox("mesgbox", "A mesg box", -1, -1); else if (strstr(result, "yesno")) { rc = dialog_yesno("yesno", "Test me\nPress YES or NO", -1, -1); if (rc == 0) dialog_notify("You pressed YES"); else if (rc > 0) dialog_notify("You pressed NO"); else dialog_notify("Something Wicked Happened!"); } else if (strstr(result, "gauge")) { int x; for (x=0; x<=20; x++) { dialog_gauge("test", "gauge", -1, -1, -1, 40, x*5); usleep(300000); } } } end_dialog(); exit((rc < 0) ? 1 : 0); }
int main(void) { char *chrootdir; char *distributions; int retval; size_t config_size = sizeof(struct dpv_config); size_t file_node_size = sizeof(struct dpv_file_node); size_t span; struct dpv_config *config; struct dpv_file_node *dist = dists; static char backtitle[] = "FreeBSD Installer"; static char title[] = "Archive Extraction"; static char aprompt[] = "\n Overall Progress:"; static char pprompt[] = "Extracting distribution files...\n"; struct sigaction act; char error[PATH_MAX + 512]; if ((distributions = getenv("DISTRIBUTIONS")) == NULL) errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set"); if ((distdir = getenv("BSDINSTALL_DISTDIR")) == NULL) distdir = __DECONST(char *, ""); /* Initialize dialog(3) */ init_dialog(stdin, stdout); dialog_vars.backtitle = backtitle; dlg_put_backtitle(); dialog_msgbox("", "Checking distribution archives.\nPlease wait...", 4, 35, FALSE); /* * Parse $DISTRIBUTIONS into dpv(3) linked-list */ while (*distributions != '\0') { span = strcspn(distributions, "\t\n\v\f\r "); if (span < 1) { /* currently on whitespace */ distributions++; continue; } /* Allocate a new struct for the distribution */ if (dist == NULL) { if ((dist = calloc(1, file_node_size)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); dists = dist; } else { dist->next = calloc(1, file_node_size); if (dist->next == NULL) _errx(EXIT_FAILURE, "Out of memory!"); dist = dist->next; } /* Set path */ if ((dist->path = malloc(span + 1)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); snprintf(dist->path, span + 1, "%s", distributions); dist->path[span] = '\0'; /* Set display name */ dist->name = strrchr(dist->path, '/'); if (dist->name == NULL) dist->name = dist->path; /* Set initial length in files (-1 == error) */ dist->length = count_files(dist->path); if (dist->length < 0) { end_dialog(); return (EXIT_FAILURE); } distributions += span; } /* Optionally chdir(2) into $BSDINSTALL_CHROOT */ chrootdir = getenv("BSDINSTALL_CHROOT"); if (chrootdir != NULL && chdir(chrootdir) != 0) { snprintf(error, sizeof(error), "Could not change to directory %s: %s\n", chrootdir, strerror(errno)); dialog_msgbox("Error", error, 0, 0, TRUE); end_dialog(); return (EXIT_FAILURE); } /* Set cleanup routine for Ctrl-C action */ act.sa_handler = sig_int; sigaction(SIGINT, &act, 0); /* * Hand off to dpv(3) */ if ((config = calloc(1, config_size)) == NULL) _errx(EXIT_FAILURE, "Out of memory!"); config->backtitle = backtitle; config->title = title; config->pprompt = pprompt; config->aprompt = aprompt; config->options |= DPV_WIDE_MODE; config->label_size = -1; config->action = extract_files; config->status_solo = "%10lli files read @ %'9.1f files/sec."; config->status_many = "%10lli files read @ %'9.1f files/sec. [%i/%i busy/wait]"; end_dialog(); retval = dpv(config, dists); dpv_free(); while ((dist = dists) != NULL) { dists = dist->next; if (dist->path != NULL) free(dist->path); free(dist); } return (retval); }
int main() { int r; r = global_init(); if (r) { fprintf(stderr, "init fail\n"); return r; } // get list of devices DC_DevList *devlist = dc_dev_list(); assert(devlist); while (1) { // draw menu of device choice DC_Dev *chosen_dev = menu_choose_device(devlist); if (!chosen_dev) { break; } // draw procedures menu DC_Procedure *act = menu_choose_procedure(chosen_dev); if (!act) continue; if (act->flags & DC_PROC_FLAG_INVASIVE) { char *ask; r = asprintf(&ask, "This operation is invasive, i.e. it may make your data unreachable or even destroy it completely. Are you sure you want to proceed it on %s (%s)?", chosen_dev->dev_fs_name, chosen_dev->model_str); assert(r != -1); dialog_vars.default_button = 1; // Focus on "No" r = dialog_yesno("Confirmation", ask, 0, 0); // Yes = 0 (FALSE), No = 1, Escape = -1 free(ask); if (/* No */ r) continue; if (chosen_dev->mounted) { dialog_vars.default_button = 1; // Focus on "No" r = dialog_yesno("Confirmation", "This disk is mounted. Are you really sure you want to proceed?", 0, 0); if (r) continue; } } DC_OptionSetting *option_set = calloc(act->options_num + 1, sizeof(DC_OptionSetting)); int i; r = 0; for (i = 0; i < act->options_num; i++) { option_set[i].name = act->options[i].name; r = act->suggest_default_value(chosen_dev, &option_set[i]); if (r) { dc_log(DC_LOG_ERROR, "Failed to get default value suggestion on '%s'", option_set[i].name); break; } r = ask_option_value(act, &option_set[i], &act->options[i]); if (r) break; } if (r) continue; // Show relaxing banner when copying with journal. Copy journal processing takes some time. if (!strcmp(act->name, "copy")) { int uses_journal = 0; for (i = 0; i < act->options_num; i++) { if (!strcmp(option_set[i].name, "use_journal")) { uses_journal = 1; break; } } if (uses_journal) dialog_msgbox("Info", "Please wait while operation journal is processed", 0, 0, 0 /* non-pausing */); } DC_ProcedureCtx *actctx; r = dc_procedure_open(act, chosen_dev, &actctx, option_set); if (r) { dialog_msgbox("Error", "Procedure init fail", 0, 0, 1); continue; } if (!act->perform) continue; DC_Renderer *renderer; if (!strcmp(act->name, "copy")) renderer = dc_find_renderer("whole_space"); else renderer = dc_find_renderer("sliding_window"); render_procedure(actctx, renderer); } // while(1) return 0; }
/* * Returns number of files in archive file. Parses $BSDINSTALL_DISTDIR/MANIFEST * if it exists, otherwise uses archive(3) to read the archive file. */ static int count_files(const char *file) { static FILE *manifest = NULL; char *p; int file_count; int retval; size_t span; struct archive_entry *entry; char line[512]; char path[PATH_MAX]; char errormsg[PATH_MAX + 512]; if (manifest == NULL) { snprintf(path, sizeof(path), "%s/MANIFEST", distdir); manifest = fopen(path, "r"); } if (manifest != NULL) { rewind(manifest); while (fgets(line, sizeof(line), manifest) != NULL) { p = &line[0]; span = strcspn(p, "\t") ; if (span < 1 || strncmp(p, file, span) != 0) continue; /* * We're at the right manifest line. The file count is * in the third element */ span = strcspn(p += span + (*p != '\0' ? 1 : 0), "\t"); span = strcspn(p += span + (*p != '\0' ? 1 : 0), "\t"); if (span > 0) { file_count = (int)strtol(p, (char **)NULL, 10); if (file_count == 0 && errno == EINVAL) continue; return (file_count); } } } /* * Either no manifest, or manifest didn't mention this archive. * Use archive(3) to read the archive, counting files within. */ if ((archive = archive_read_new()) == NULL) { snprintf(errormsg, sizeof(errormsg), "Error: %s\n", archive_error_string(NULL)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); return (-1); } archive_read_support_format_all(archive); archive_read_support_filter_all(archive); snprintf(path, sizeof(path), "%s/%s", distdir, file); retval = archive_read_open_filename(archive, path, 4096); if (retval != ARCHIVE_OK) { snprintf(errormsg, sizeof(errormsg), "Error while extracting %s: %s\n", file, archive_error_string(archive)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); archive = NULL; return (-1); } file_count = 0; while (archive_read_next_header(archive, &entry) == ARCHIVE_OK) file_count++; archive_read_free(archive); archive = NULL; return (file_count); }
static int extract_files(struct dpv_file_node *file, int out __unused) { int retval; struct archive_entry *entry; char path[PATH_MAX]; char errormsg[PATH_MAX + 512]; /* Open the archive if necessary */ if (archive == NULL) { if ((archive = archive_read_new()) == NULL) { snprintf(errormsg, sizeof(errormsg), "Error: %s\n", archive_error_string(NULL)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); dpv_abort = 1; return (-1); } archive_read_support_format_all(archive); archive_read_support_filter_all(archive); snprintf(path, sizeof(path), "%s/%s", distdir, file->path); retval = archive_read_open_filename(archive, path, 4096); if (retval != 0) { snprintf(errormsg, sizeof(errormsg), "Error opening %s: %s\n", file->name, archive_error_string(archive)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); file->status = DPV_STATUS_FAILED; dpv_abort = 1; return (-1); } } /* Read the next archive header */ retval = archive_read_next_header(archive, &entry); /* If that went well, perform the extraction */ if (retval == ARCHIVE_OK) retval = archive_read_extract(archive, entry, ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_ACL | ARCHIVE_EXTRACT_XATTR | ARCHIVE_EXTRACT_FFLAGS); /* Test for either EOF or error */ if (retval == ARCHIVE_EOF) { archive_read_free(archive); archive = NULL; file->status = DPV_STATUS_DONE; return (100); } else if (retval != ARCHIVE_OK && !(retval == ARCHIVE_WARN && strcmp(archive_error_string(archive), "Can't restore time") == 0)) { /* * Print any warning/error messages except inability to set * ctime/mtime, which is not fatal, or even interesting, * for our purposes. Would be nice if this were a libarchive * option. */ snprintf(errormsg, sizeof(errormsg), "Error while extracting %s: %s\n", file->name, archive_error_string(archive)); dialog_msgbox("Extract Error", errormsg, 0, 0, TRUE); file->status = DPV_STATUS_FAILED; dpv_abort = 1; return (-1); } dpv_overall_read++; file->read++; /* Calculate [overall] percentage of completion (if possible) */ if (file->length >= 0) return (file->read * 100 / file->length); else return (-1); }
static int remove_packages(void) { char **args; char *env[1]={NULL}; char **p; int i; int delete_count=0; pid_t child; int status; size_t st; args=(char **)malloc((menulen+4) * sizeof(char *)); if(!args) { do_init_dialog(); dialog_msgbox("ERROR", "Can not allocate memory for package list!", 5, 45, TRUE); end_dialog(); return(-1); } p=args; *(p++)="/usr/sbin/pkg"; *(p++)="delete"; *(p++)="-y"; for(i=0;i<menulen;i++) { if(menu[i].ITEM_CHECKED) { *(p++)=menu[i].ITEM_PROMPT; delete_count++; } } *(p)=NULL; if(!delete_count) { do_init_dialog(); dialog_msgbox(NULL, "No packages selected", 5, 24, TRUE); end_dialog(); free(args); return(-1); } /* Ensure stdio is "right" */ if(!isendwin()) endwin(); child=vfork(); if(child==0) { execve(args[0], args, env); fprintf(stderr,"ERROR: %d!\n",errno); _exit(EXIT_FAILURE); } free(args); if(child==-1) { do_init_dialog(); dialog_msgbox(NULL, "Can not fork()", 5, 18, TRUE); end_dialog(); return(-1); } waitpid(child, &status, 0); /* On an error return, pause */ if(WIFSIGNALED(status) || (WIFEXITED(status) && WEXITSTATUS(status))) { fputs("\n\nPress ENTER to continue... ",stderr); fgetln(stdin, &st); } return(0); }
static void newfs_command(const char *fstype, char *command, int use_default) { if (strcmp(fstype, "freebsd-ufs") == 0) { int i; DIALOG_LISTITEM items[] = { {"UFS1", "UFS Version 1", "Use version 1 of the UFS file system instead " "of version 2 (not recommended)", 0 }, {"SU", "Softupdates", "Enable softupdates (default)", 1 }, {"SUJ", "Softupdates journaling", "Enable file system journaling (default - " "turn off for SSDs)", 1 }, {"TRIM", "Enable SSD TRIM support", "Enable TRIM support, useful on solid-state drives", 0 }, }; if (!use_default) { int choice; choice = dlg_checklist("UFS Options", "", 0, 0, 0, sizeof(items)/sizeof(items[0]), items, NULL, FLAG_CHECK, &i); if (choice == 1) /* Cancel */ return; } strcpy(command, "newfs "); for (i = 0; i < (int)(sizeof(items)/sizeof(items[0])); i++) { if (items[i].state == 0) continue; if (strcmp(items[i].name, "UFS1") == 0) strcat(command, "-O1 "); else if (strcmp(items[i].name, "SU") == 0) strcat(command, "-U "); else if (strcmp(items[i].name, "SUJ") == 0) strcat(command, "-j "); else if (strcmp(items[i].name, "TRIM") == 0) strcat(command, "-t "); } } else if (strcmp(fstype, "fat32") == 0 || strcmp(fstype, "efi") == 0) { int i; DIALOG_LISTITEM items[] = { {"FAT32", "FAT Type 32", "Create a FAT32 filesystem (default)", 1 }, {"FAT16", "FAT Type 16", "Create a FAT16 filesystem", 0 }, {"FAT12", "FAT Type 12", "Create a FAT12 filesystem", 0 }, }; if (!use_default) { int choice; choice = dlg_checklist("FAT Options", "", 0, 0, 0, sizeof(items)/sizeof(items[0]), items, NULL, FLAG_RADIO, &i); if (choice == 1) /* Cancel */ return; } strcpy(command, "newfs_msdos "); for (i = 0; i < (int)(sizeof(items)/sizeof(items[0])); i++) { if (items[i].state == 0) continue; if (strcmp(items[i].name, "FAT32") == 0) strcat(command, "-F 32 "); else if (strcmp(items[i].name, "FAT16") == 0) strcat(command, "-F 16 "); else if (strcmp(items[i].name, "SUJ") == 0) strcat(command, "-F 12 "); } } else { if (!use_default) dialog_msgbox("Error", "No configurable options exist " "for this filesystem.", 0, 0, TRUE); command[0] = '\0'; } }
int main(int argc, const char **argv) { struct partition_metadata *md; const char *prompt; struct partedit_item *items = NULL; struct gmesh mesh; int i, op, nitems, nscroll; int error; if (strcmp(basename(argv[0]), "sade") == 0) sade_mode = 1; TAILQ_INIT(&part_metadata); init_fstab_metadata(); init_dialog(stdin, stdout); if (!sade_mode) dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); dialog_vars.item_help = TRUE; nscroll = i = 0; /* Revert changes on SIGINT */ signal(SIGINT, sigint_handler); if (strcmp(basename(argv[0]), "autopart") == 0) { /* Guided */ prompt = "Please review the disk setup. When complete, press " "the Finish button."; /* Experimental ZFS autopartition support */ if (argc > 1 && strcmp(argv[1], "zfs") == 0) { part_wizard("zfs"); } else { part_wizard("ufs"); } } else if (strcmp(basename(argv[0]), "scriptedpart") == 0) { error = scripted_editor(argc, argv); prompt = NULL; if (error != 0) { end_dialog(); return (error); } } else { prompt = "Create partitions for FreeBSD. No changes will be " "made until you select Finish."; } /* Show the part editor either immediately, or to confirm wizard */ while (prompt != NULL) { dlg_clear(); dlg_put_backtitle(); error = geom_gettree(&mesh); if (error == 0) items = read_geom_mesh(&mesh, &nitems); if (error || items == NULL) { dialog_msgbox("Error", "No disks found. If you need to " "install a kernel driver, choose Shell at the " "installation menu.", 0, 0, TRUE); break; } get_mount_points(items, nitems); if (i >= nitems) i = nitems - 1; op = diskeditor_show("Partition Editor", prompt, items, nitems, &i, &nscroll); switch (op) { case 0: /* Create */ gpart_create((struct gprovider *)(items[i].cookie), NULL, NULL, NULL, NULL, 1); break; case 1: /* Delete */ gpart_delete((struct gprovider *)(items[i].cookie)); break; case 2: /* Modify */ gpart_edit((struct gprovider *)(items[i].cookie)); break; case 3: /* Revert */ gpart_revert_all(&mesh); while ((md = TAILQ_FIRST(&part_metadata)) != NULL) { if (md->fstab != NULL) { free(md->fstab->fs_spec); free(md->fstab->fs_file); free(md->fstab->fs_vfstype); free(md->fstab->fs_mntops); free(md->fstab->fs_type); free(md->fstab); } if (md->newfs != NULL) free(md->newfs); free(md->name); TAILQ_REMOVE(&part_metadata, md, metadata); free(md); } init_fstab_metadata(); break; case 4: /* Auto */ part_wizard("ufs"); break; } error = 0; if (op == 5) { /* Finished */ dialog_vars.ok_label = __DECONST(char *, "Commit"); dialog_vars.extra_label = __DECONST(char *, "Revert & Exit"); dialog_vars.extra_button = TRUE; dialog_vars.cancel_label = __DECONST(char *, "Back"); op = dialog_yesno("Confirmation", "Your changes will " "now be written to disk. If you have chosen to " "overwrite existing data, it will be PERMANENTLY " "ERASED. Are you sure you want to commit your " "changes?", 0, 0); dialog_vars.ok_label = NULL; dialog_vars.extra_button = FALSE; dialog_vars.cancel_label = NULL; if (op == 0 && validate_setup()) { /* Save */ error = apply_changes(&mesh); if (!error) apply_workaround(&mesh); break; } else if (op == 3) { /* Quit */ gpart_revert_all(&mesh); error = -1; break; } } geom_deletetree(&mesh); free(items); }
int proto_forward() { WINDOW *w; int p = 1; int key; int done = 0; struct ruleset r; char src[128]; char dst[128]; char forw[128]; char src_port[5]; char dst_port[5]; char forw_port[5]; int ret; r.action = FWD; r.proto = TCP; // where is the methlab bzero(r.src, sizeof(r.src)); bzero(r.src_port, sizeof(r.src_port)); bzero(r.dst, sizeof(r.dst)); bzero(r.dst_port, sizeof(r.dst_port)); bzero(src, sizeof(src)); bzero(dst, sizeof(dst)); bzero(forw, sizeof(forw)); bzero(src_port, sizeof(src_port)); bzero(dst_port, sizeof(dst_port)); bzero(forw_port, sizeof(forw_port)); // now initialize the layout dialog_clear(); w = newwin(22, 76, 1, 1); _std_window(w, "ClosedBSD: Insert a TCP/UDP port forward"); wrefresh(w); draw_protocol_forward_box(w, 2, 13, 1, r); draw_host_inputbox(w, 7, 19); wattrset(w, dialog_attr); mvwprintw(w, 8, 54, ":"); draw_port_inputbox(w, 7, 55); draw_host_inputbox(w, 10, 19); wattrset(w, dialog_attr); mvwprintw(w, 11, 54, ":"); draw_port_inputbox(w, 10, 55); draw_host_inputbox(w, 13, 19); wattrset(w, dialog_attr); mvwprintw(w, 14, 54, ":"); draw_port_inputbox(w, 13, 55); buttons(w, 0); mvwprintw(w, 8, 7, "packet src"); mvwprintw(w, 11, 7, "packet dst"); mvwprintw(w, 14, 7, "forward to"); wmove(w, 0, 0); help(w, 31, r); wrefresh(w); keypad(w, TRUE); while(!done) { switch(key = wgetch(w)) { case KEY_DOWN: down: switch(p) { case 1: p++; help(w, 32, r); draw_protocol_forward_box(w, 2, 13, p, r); break; case 2: p++; help(w, 8, r); draw_protocol_forward_box(w, 2, 13, 0, r); ret = forw_input(w, p, src, dst, forw, src_port, dst_port, forw_port); if (ret < p) { p = 1; goto down; } else { p = 3; goto down; } break; case 3: p++; help(w, 9, r); ret = forw_input(w, p, src, dst, forw, src_port, dst_port, forw_port); if (ret < p) { p = 2; goto down; } else { p = 4; goto down; } break; case 4: p++; help(w, 10, r); ret = forw_input(w, p, src, dst, forw, src_port, dst_port, forw_port); if (ret < p) { p = 3; goto down; } else { p = 5; goto down; } break; case 5: p++; help(w, 9, r); ret = forw_input(w, p, src, dst, forw, src_port, dst_port, forw_port); if (ret < p) { p = 4; goto down; } else { p = 6; goto down; } break; case 6: p++; help(w, 12, r); ret = forw_input(w, p, src, dst, forw, src_port, dst_port, forw_port); if (ret < p) { p = 5; goto down; } else { p = 7; goto down; } break; case 7: p++; buttons(w, 0); help(w, 9, r); ret = forw_input(w, p, src, dst, forw, src_port, dst_port, forw_port); if (ret < p) { p = 6; goto down; } else { p = 8; goto down; } break; case 8: p++; help(w, 33, r); buttons(w, 1); break; case 9: p++; help(w, 34, r); buttons(w, 2); break; } break; case KEY_RIGHT: switch(p) { case 9: p++; buttons(w, 2); break; } break; case KEY_LEFT: switch(p) { case 10: p--; buttons(w, 1); break; } break; case KEY_UP: switch(p) { case 1: p = 1; help(w, 31, r); draw_protocol_forward_box(w, 2, 13, p, r); break; case 2: p--; help(w, 31, r); draw_protocol_forward_box(w, 2, 13, p, r); break; case 9: p = 7; buttons(w, 0); goto down; case 10: p = 8; buttons(w, 1); goto down; } break; case 10: switch(p) { case 9: snprintf(r.src, sizeof(r.src), "%s", src); snprintf(r.src_port, sizeof(r.src_port), "%s", src_port); snprintf(r.dst, sizeof(r.dst), "%s", dst); snprintf(r.dst_port, sizeof(r.dst_port), "%s", dst_port); snprintf(r.other_a, sizeof(r.other_a),"%s", forw); snprintf(r.other_b, sizeof(r.other_b), "%s", forw_port); ret = __insert_rule(r); if (ret == 0) { dialog_msgbox("ClosedBSD: Notice", "Rule has been added", -1, -1, 1); return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } else { dialog_msgbox("ClosedBSD: Notice", "There was an error adding the rule. Verify proper information!", -1, -1, 1); break; } case 10: return DITEM_SUCCESS | DITEM_RESTORE | DITEM_CONTINUE; } break; case 32: switch(p) { case 1: r.proto = TCP; draw_protocol_forward_box(w, 2, 13, p, r); break; case 2: r.proto = UDP; draw_protocol_forward_box(w, 2, 13, p, r); break; } break; } } wmove(w, 0, 0); wrefresh(w); return 0; }
int run(GList **config) { GList *drives=NULL; int i; int found = 0; char *ptr; umount_if_needed(SOURCEDIR); dialog_vars.backtitle=gen_backtitle(_("Selecting source media")); dlg_put_backtitle(); dlg_clear(); dialog_msgbox(_("Scanning"), _("Scanning for a CD/DVD drive containing " "a Frugalware install disc..."), 0, 0, 0); drives = grep_drives("/proc/sys/dev/cdrom/info"); for (i=0; i<g_list_length(drives); i++) { ptr = get_blkid((char*)g_list_nth_data(drives, i)); if(ptr && !strcmp(ptr, "Frugalware Install")) { LOG("install medium found in %s", (char*)g_list_nth_data(drives, i)); FREE(ptr); ptr = g_strdup_printf("mount -o ro -t iso9660 /dev/%s %s", (char*)g_list_nth_data(drives, i), SOURCEDIR); fw_system(ptr); data_put(config, "srcdev", (char*)g_list_nth_data(drives, i)); dlg_put_backtitle(); dialog_msgbox(_("CD/DVD drive found"), g_strdup_printf(_("A Frugalware install disc was found in device /dev/%s."), (char*)g_list_nth_data(drives, i)), 0, 0, 0); if(is_netinstall(SOURCEDIR)) { data_put(config, "netinstall", ""); LOG("install medium contains no packages, performing a network installation"); } else LOG("install medium contains packages, performing an offline installation"); found = 1; break; } else LOG("skipping non-install medium in %s", (char*)g_list_nth_data(drives, i)); FREE(ptr); } if(!found) { LOG("no package database found, performing a network installation"); data_put(config, "netinstall", ""); } // disable caching for cds if((char*)data_get(*config, "netinstall")==NULL) { char *pacbindir = g_strdup_printf("%s/frugalware-%s", SOURCEDIR, ARCH); disable_cache(pacbindir); FREE(pacbindir); } if(data_get(*config, "srcdev")==NULL) { LOG("no cd/dvd drive found, this is normal if you are running setup from a pendrive or in an emulator"); } return(0); }