[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3921 - in GNUnet: . src/setup src/setup/gtk src/setup/ncur
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3921 - in GNUnet: . src/setup src/setup/gtk src/setup/ncurses src/util/os src/util/string |
Date: |
Mon, 11 Dec 2006 19:27:09 -0800 (PST) |
Author: grothoff
Date: 2006-12-11 19:27:03 -0800 (Mon, 11 Dec 2006)
New Revision: 3921
Modified:
GNUnet/src/setup/gnunet-setup.c
GNUnet/src/setup/gtk/wizard_gtk.c
GNUnet/src/setup/ncurses/Makefile.am
GNUnet/src/setup/ncurses/wizard_curs.c
GNUnet/src/setup/ncurses/wizard_curs.h
GNUnet/src/util/os/user.c
GNUnet/src/util/string/xmalloc.c
GNUnet/todo
Log:
fixes
Modified: GNUnet/src/setup/gnunet-setup.c
===================================================================
--- GNUnet/src/setup/gnunet-setup.c 2006-12-11 21:09:18 UTC (rev 3920)
+++ GNUnet/src/setup/gnunet-setup.c 2006-12-12 03:27:03 UTC (rev 3921)
@@ -129,7 +129,7 @@
static const char * INFO =
"gnunet-setup [OPTIONS] config"
-#if HAVE_CURSES
+#if HAVE_DIALOG
"|menuconfig|wizard-curses"
#endif
#if HAVE_GTK
@@ -189,7 +189,7 @@
GE_WARNING | GE_REQUEST | GE_USER,
_("No interface specified, using default\n"));
operation = "config";
-#if HAVE_CURSES
+#if HAVE_DIALOG
operation = "menuconfig";
#endif
#if HAVE_GTK
Modified: GNUnet/src/setup/gtk/wizard_gtk.c
===================================================================
--- GNUnet/src/setup/gtk/wizard_gtk.c 2006-12-11 21:09:18 UTC (rev 3920)
+++ GNUnet/src/setup/gtk/wizard_gtk.c 2006-12-12 03:27:03 UTC (rev 3921)
@@ -154,7 +154,7 @@
}
void load_step2setup_gtk(GtkButton * button,
- gpointer prev_window) {
+ gpointer prev_window) {
GtkWidget * entIP;
GtkWidget * chkFW;
GtkTreeIter iter;
@@ -261,7 +261,7 @@
}
void load_step4setup_gtk(GtkButton * button,
- gpointer prev_window) {
+ gpointer prev_window) {
GtkWidget * entUser;
GtkWidget * entGroup;
char * uname = NULL;
@@ -352,7 +352,7 @@
void load_step5setup_gtk(GtkButton * button,
- gpointer prev_window) {
+ gpointer prev_window) {
GtkWidget * chkMigr;
GtkWidget * entQuota;
GtkWidget * chkEnh;
@@ -366,13 +366,19 @@
chkStart = lookup_widget("chkStart");
chkEnh = lookup_widget("chkEnh");
- GC_get_configuration_value_string(editCfg, "FS", "QUOTA", "1024",
- &val);
+ GC_get_configuration_value_string(editCfg,
+ "FS",
+ "QUOTA",
+ "1024",
+ &val);
gtk_entry_set_text(GTK_ENTRY(entQuota), val);
FREE(val);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkMigr),
- GC_get_configuration_value_yesno(editCfg, "FS",
"ACTIVEMIGRATION", YES) == YES);
+ GC_get_configuration_value_yesno(editCfg,
+ "FS",
+
"ACTIVEMIGRATION",
+ YES) == YES);
if (os_modify_autostart(err_ctx, 1, 1, NULL, NULL, NULL))
gtk_widget_set_sensitive(chkStart, TRUE);
@@ -468,23 +474,26 @@
char * gup;
char * bin;
if (doAutoStart && (user_name != NULL))
- if (!wiz_createGroupUser(group_name, user_name)) {
+ if (!wiz_createGroupUser(group_name,
+ user_name)) {
#ifndef MINGW
- showErr(_("Unable to create user account:"), STRERROR(errno));
+ showErr(_("Unable to create user account:"),
+ STRERROR(errno));
#endif
return;
}
- if (wiz_autostartService(doAutoStart, user_name, group_name) != OK) {
+ if (wiz_autostartService(doAutoStart,
+ user_name,
+ group_name) != OK) {
#ifndef MINGW
- showErr(_("Unable to change startup process:"), STRERROR(errno));
+ showErr(_("Unable to change startup process:"),
+ STRERROR(errno));
#endif
}
if (OK != save_conf())
- return;
-
-
+ return;
if (doUpdate) {
bin = os_get_installation_path(IPK_BINDIR);
gup = MALLOC(strlen(bin) + 30 + strlen(cfg_fn));
@@ -502,13 +511,13 @@
}
void on_updateFailedOK_clickedsetup_gtk (GtkButton * button,
- gpointer user_data) {
+ gpointer user_data) {
GtkWidget * dialog = user_data;
gtk_widget_destroy(dialog);
}
void on_entIP_changedsetup_gtk (GtkEditable * editable,
- gpointer user_data) {
+ gpointer user_data) {
gchar * ret;
ret = gtk_editable_get_chars(editable, 0, -1);
@@ -522,13 +531,13 @@
void on_chkFW_toggledsetup_gtk (GtkToggleButton * togglebutton,
- gpointer user_data) {
+ gpointer user_data) {
GC_set_configuration_value_choice(editCfg, err_ctx, "LIMITED", "NAT",
gtk_toggle_button_get_active(togglebutton) ? "YES" : "NO");
}
void on_entUp_changedsetup_gtk (GtkEditable * editable,
- gpointer user_data) {
+ gpointer user_data) {
gchar * ret;
ret = gtk_editable_get_chars(editable, 0, -1);
@@ -557,15 +566,25 @@
void on_radGNUnet_toggledsetup_gtk(GtkToggleButton * togglebutton,
gpointer user_data) {
- GC_set_configuration_value_choice(editCfg, err_ctx, "LOAD", "BASICLIMITING",
- gtk_toggle_button_get_active(togglebutton) ? "YES" : "NO");
+ GC_set_configuration_value_choice(editCfg,
+ err_ctx,
+ "LOAD",
+ "BASICLIMITING",
+ gtk_toggle_button_get_active(togglebutton)
+ ? "YES"
+ : "NO");
}
void on_radShare_toggledsetup_gtk (GtkToggleButton * togglebutton,
- gpointer user_data) {
- GC_set_configuration_value_choice(editCfg, err_ctx, "LOAD", "BASICLIMITING",
- gtk_toggle_button_get_active(togglebutton) ? "NO" : "YES");
+ gpointer user_data) {
+ GC_set_configuration_value_choice(editCfg,
+ err_ctx,
+ "LOAD",
+ "BASICLIMITING",
+ gtk_toggle_button_get_active(togglebutton)
+ ? "NO"
+ : "YES");
}
@@ -581,13 +600,18 @@
}
void on_chkMigr_toggledsetup_gtk (GtkToggleButton * togglebutton,
- gpointer user_data) {
- GC_set_configuration_value_choice(editCfg, err_ctx, "FS", "ACTIVEMIGRATION",
- gtk_toggle_button_get_active(togglebutton) ? "YES" : "NO");
+ gpointer user_data) {
+ GC_set_configuration_value_choice(editCfg,
+ err_ctx,
+ "FS",
+ "ACTIVEMIGRATION",
+ gtk_toggle_button_get_active(togglebutton)
+ ? "YES"
+ : "NO");
}
void on_entQuota_changedsetup_gtk (GtkEditable * editable,
- gpointer user_data) {
+ gpointer user_data) {
gchar * ret;
ret = gtk_editable_get_chars(editable, 0, -1);
@@ -634,7 +658,7 @@
}
void on_entGroup_changedsetup_gtk (GtkEditable * editable,
- gpointer user_data) {
+ gpointer user_data) {
gchar * ret;
FREENONNULL(group_name);
Modified: GNUnet/src/setup/ncurses/Makefile.am
===================================================================
--- GNUnet/src/setup/ncurses/Makefile.am 2006-12-11 21:09:18 UTC (rev
3920)
+++ GNUnet/src/setup/ncurses/Makefile.am 2006-12-12 03:27:03 UTC (rev
3921)
@@ -9,8 +9,8 @@
libgnunetsetup_curses.la
libgnunetsetup_curses_la_SOURCES = \
- mconf.c mconf.h
-# wizard_curs.c wizard_curs.h
+ mconf.c mconf.h \
+ wizard_curs.c wizard_curs.h
libgnunetsetup_curses_la_LDFLAGS = \
-lncursesw -ldialog \
Modified: GNUnet/src/setup/ncurses/wizard_curs.c
===================================================================
--- GNUnet/src/setup/ncurses/wizard_curs.c 2006-12-11 21:09:18 UTC (rev
3920)
+++ GNUnet/src/setup/ncurses/wizard_curs.c 2006-12-12 03:27:03 UTC (rev
3921)
@@ -22,6 +22,13 @@
* @file setup/ncurses/wizard_curs.c
* @brief A easy-to-use configuration assistant for curses
* @author Nils Durner
+ * @author Christian Grothoff
+ *
+ * TODO:
+ * - use ectx to capture error messages and show them to
+ * the user properly
+ * - additional autodetections (IP, etc)
+ * - share helper functions with mconf.c (refactoring)
*/
#include <dialog.h>
@@ -36,634 +43,580 @@
#include "mconf.h"
#ifndef MINGW
+#include <termios.h>
#include <grp.h>
#endif
+static struct GE_Context * ectx;
+static struct GC_Configuration * cfg;
-static struct dialog_list_item **nic_items;
-static int nic_item_count = 0;
+static int last;
-void showCursErr(const char *prefix,
- const char *error) {
- char *err;
+static const char * cfg_fn;
+
+static void showCursErr(const char * prefix,
+ const char * error) {
+ char * err;
- err = malloc(strlen(prefix) + strlen(error) + 2);
+ err = MALLOC(strlen(prefix) + strlen(error) + 2);
sprintf(err,
"%s %s",
prefix,
error);
dialog_msgbox(_("Error"),
err,
- rows,
- cols - 5,
+ 70,
+ 15,
1);
- free(err);
+ FREE(err);
}
-void insert_nic_curs(const char *name,
- int defaultNIC,
- void * cls)
-{
- struct dialog_list_item *item;
+static void show_help(const char * helptext) {
+ dialog_vars.help_button = 0;
+ dialog_msgbox(_("Help"),
+ helptext,
+ 20,
+ 70,
+ TRUE);
+}
- /* Copy NIC data */
- nic_items = (nic_item_count++) ?
- realloc(nic_items, nic_item_count * sizeof(struct
dialog_list_item *)) :
- malloc(sizeof(struct dialog_list_item *));
-
- item = malloc(sizeof(struct dialog_list_item));
- memset(item, 0, sizeof(struct dialog_list_item));
- nic_items[nic_item_count-1] = item;
- item->name = STRDUP(name);
- item->namelen = strlen(name);
- item->selected = wiz_is_nic_default(name, defaultNIC);
+static void show_error(const char * msg) {
+ dialog_vars.help_button = 0;
+ dialog_msgbox(_("Error!"),
+ msg,
+ 20,
+ 70,
+ TRUE);
}
-int wizard_curs_main_ncurses(int argc,
- const char **argv,
- struct PluginHandle * self,
- struct GE_Context * ectx,
- struct GC_Configuration * cfg,
- struct GNS_Context * gns,
- const char * filename,
- int is_daemon)
- void *active_ptr = NULL;
- int idx, ret, autostart = 0, adv = 0;
- struct symbol *sym;
- char *defval;
- char * user_name = NULL;
- char * group_name = NULL;
- char *confFile;
- char * filename;
- char *defuser;
- const char *confUser;
- char *defgroup;
- const char *confGroup;
+static int query_yesno(const char * title,
+ const char * question,
+ const char * help,
+ const char * section,
+ const char * option) {
+ int ret;
- filename = getConfigurationString("GNUNET-SETUP",
- "FILENAME");
- conf_read(filename);
- FREE(filename);
-
- sym = sym_find("EXPERIMENTAL", "Meta");
- sym_set_tristate_value(sym, yes);
- sym = sym_find("ADVANCED", "Meta");
- sym_set_tristate_value(sym, yes);
- sym = sym_find("RARE", "Meta");
- sym_set_tristate_value(sym, yes);
-
- init_dialog();
- init_wsize();
- dialog_clear();
-
- if (dialog_msgbox(_("GNUnet configuration"),
- _("Welcome to GNUnet!\n\nThis assistant will ask you a few
basic questions "
- "in order to configure GNUnet.\n\nPlease visit our
homepage at\n\t"
- "http://gnunet.org/\nand join our community at\n\t"
- "http://gnunet.org/drupal/\n\nHave a lot of fun,\n\nthe
GNUnet team"),
- rows, cols - 5, 1) == -1)
- goto end;
-
- dialog_clear();
-
- enumNetworkIfs(insert_nic_curs, NULL);
-
- /* Network interface */
- if (nic_item_count) {
- while (true) {
- ret = dialog_menu(_("GNUnet configuration"),
- _("Choose the network interface that connects your
computer to "
- "the internet from the list below."), rows, cols - 5,
10,
- 0, active_ptr, nic_item_count, nic_items);
-
- if (ret == 2) {
- /* Help */
- dialog_msgbox(_("Help"), _("The \"Network interface\" is the device "
- "that connects your computer to the
internet. This is usually a modem, "
- "an ISDN card or a network card in case you
are using DSL."), rows,
- cols - 5, 1);
- }
- else if (ret <= 1) {
- /* Select or Exit */
-#ifdef MINGW
- char nic[21];
- char *dst;
-#else
- char *nic;
-#endif
- for(idx = 0; idx < nic_item_count; idx++) {
-
- if (nic_items[idx]->selected) {
-#ifdef MINGW
- char *src = strrchr(nic_items[idx]->name, '-') + 2;
- dst = nic;
- while(*src)
- *dst++ = *src++;
- dst[-1] = 0;
-#else
- nic = nic_items[idx]->name;
-#endif
- sym = sym_lookup("INTERFACE", "NETWORK", 0);
- sym_set_string_value(sym, nic);
- sym = sym_lookup("INTERFACES", "LOAD", 0);
- sym_set_string_value(sym, nic);
- }
-
- free(nic_items[idx]->name);
- free(nic_items[idx]);
- }
- free(nic_items);
-
+ if (help == NULL)
+ dialog_vars.help_button = 0;
+ else
+ dialog_vars.help_button = 1;
+ dialog_vars.cancel_label = _("No");
+ dialog_vars.ok_label = _("Yes");
+ while (true) {
+ ret = dialog_yesno(title,
+ question,
+ 20,
+ 70);
+ switch(ret) {
+ case DLG_EXIT_OK:
+ case DLG_EXIT_CANCEL:
+ if (0 != GC_set_configuration_value_string(cfg,
+ ectx,
+ section,
+ option,
+ ret == DLG_EXIT_OK
+ ? "YES"
+ : "NO")) {
+ show_error(_("Internal error! (Choice invalid?)"));
break;
}
- }
-
- if (ret == 1 || ret == -1)
- goto end;
- }
- else {
- /* We are not root, just ask for the interface */
- while(true) {
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("What is the name of " \
- "the network interface that connects your
computer to the Internet?"),
- rows, cols - 5, "eth0");
-
- if (ret == 1) {
- /* Help */
- dialog_msgbox(_("Help"),
- _("The \"Network interface\" is the device "
- "that connects your computer to the internet. This is
usually a modem, "
- "an ISDN card or a network card in case you are using
DSL."),
- rows, cols - 5, 1);
- }
- else if (ret <= 0)
- break;
- }
-
- if (ret == -1)
- goto end;
-
- sym = sym_lookup("INTERFACE", "NETWORK", 0);
- sym_set_string_value(sym, dialog_input_result);
- sym = sym_lookup("INTERFACES", "LOAD", 0);
- sym_set_string_value(sym, dialog_input_result);
- }
-
- dialog_clear();
-
- /* IP address */
- if ((sym = sym_find("IP", "NETWORK"))) {
- sym_calc_value_ext(sym, 1);
- defval = (char *) sym_get_string_value(sym);
- }
- else
- defval = NULL;
-
- while(true) {
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("What is this computer's "
- "public IP address or hostname?\n\nIf in doubt,
leave this empty."),
- rows, cols - 5, defval ? defval : "");
-
- if (ret == 1) {
- /* Help */
- dialog_msgbox(_("Help"),
- _("If your provider always assigns the same "
- "IP-Address to you (a \"static\" IP-Address), enter it
into the "
- "\"IP-Address\" field. If your IP-Address changes every
now and then "
- "(\"dynamic\" IP-Address) but there's a hostname that
always points "
- "to your actual IP-Address (\"Dynamic DNS\"), you can
also enter it "
- "here.\nIf in doubt, leave the field empty. GNUnet will
then try to "
- "determine your IP-Address."), rows, cols - 5, 1);
- }
- else if (ret <= 0)
+ return 1; /* advance */
+ case DLG_EXIT_ESC:
+ return 0; /* abort */
+ case DLG_EXIT_HELP:
+ show_help(help);
break;
- }
-
- if (ret == -1)
- goto end;
-
- sym_set_string_value(sym, dialog_input_result);
-
- dialog_clear();
-
- /* NAT? */
- sym = sym_find("LIMITED", "NAT");
- while(true) {
- ret = dialog_yesno(_("GNUnet configuration"),
- _("Is this machine behind "
- "NAT?\n\nIf you are connected to the internet through
another computer "
- "doing SNAT, a router or a \"hardware firewall\" and
other computers "
- "on the internet cannot connect to this computer, say
\"yes\" here. "
- "Answer \"no\" on direct connections through modems,
ISDN cards and "
- "DNAT (also known as \"port forwarding\")."), rows,
cols - 5);
-
- if (ret != -2)
+ case DLG_EXIT_EXTRA:
+ return -1; /* back */
+ default:
+ GE_BREAK(ectx, 0);
break;
- }
-
- if (ret == -1)
- goto end;
- else
- sym_set_tristate_value(sym, !ret); /* ret is inverted */
-
- /* Upstream */
- if ((sym = sym_find("MAXNETUPBPSTOTAL", "LOAD"))) {
- sym_calc_value_ext(sym, 1);
- defval = (char *) sym_get_string_value(sym);
- }
- else
- defval = NULL;
-
- while(true) {
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("How much upstream "
- "(Bytes/s) may be used?"), rows, cols - 5, defval ?
defval : "");
-
- if (ret == 1) {
- /* Help */
- dialog_msgbox(_("Help"), _("You can limit GNUnet's resource usage "
- "here.\n\nThe \"upstream\" is the data channel
through which data "
- "is *sent* to the internet. The limit is
either the total maximum "
- "for this computer or how much GNUnet itself
is allowed to use. You "
- "can specify that later. If you have a
flatrate, you can set it to "
- "the maximum speed of your internet
connection."), rows, cols - 5, 1);
}
- else if (ret <= 0)
- break;
}
+}
- if (ret == -1)
- goto end;
+static int query_string(const char * title,
+ const char * question,
+ const char * help,
+ const char * section,
+ const char * option,
+ const char * def) {
+ int ret;
+ int msel;
+ DIALOG_FORMITEM fitem;
- sym_set_string_value(sym, dialog_input_result);
-
- dialog_clear();
-
- /* Downstram */
- if ((sym = sym_find("MAXNETDOWNBPSTOTAL", "LOAD"))) {
- sym_calc_value_ext(sym, 1);
- defval = (char *) sym_get_string_value(sym);
- }
+ if (help == NULL)
+ dialog_vars.help_button = 0;
else
- defval = NULL;
+ dialog_vars.help_button = 1;
+ dialog_vars.cancel_label = _("Abort");
+ dialog_vars.ok_label = _("Ok");
+ fitem.type = 0;
+ fitem.name = STRDUP(question);
+ fitem.name_len = strlen(question);
+ fitem.name_y = 3;
+ fitem.name_x = 5;
+ fitem.name_free = 0;
+ fitem.text_y = 5;
+ fitem.text_x = 5;
+ fitem.text_flen = 55;
+ fitem.text_ilen = 63;
+ fitem.text_free = 0;
+ fitem.help_free = 0;
+ fitem.text = MALLOC(65536);
+ strcpy(fitem.text,
+ def);
+ fitem.text_len = strlen(fitem.text);
+ fitem.help = STRDUP(help);
+ msel = 0;
- while(true) {
- ret = dialog_inputbox(_("GNUnet configuration"), _("How much downstream "
- "(Bytes/s) may be
used?"), rows, cols - 5, defval ? defval : "");
-
- if (ret == 1) {
- /* Help */
- dialog_msgbox(_("Help"),
- _("You can limit GNUnet's resource usage "
- "here.\n\nThe \"downstream\" is the data channel through
which data "
- "is *received* from the internet. The limit is either the
total maximum "
- "for this computer or how much GNUnet itself is allowed
to use. You "
- "can specify that later. If you have a flatrate you can
set it to "
- "the maximum speed of your internet connection."), rows,
cols - 5, 1);
- }
- else if (ret <= 0)
+ ret = 2;
+ while (ret == 2) {
+ ret = dlg_form(title,
+ "",
+ 20,
+ 70,
+ 15,
+ 1,
+ &fitem,
+ &msel);
+ switch(ret) {
+ case DLG_EXIT_OK:
+ if (0 != GC_set_configuration_value_string(cfg,
+ ectx,
+ section,
+ option,
+ fitem.text)) {
+ show_error(_("Internal error! (Choice invalid?)"));
+ ret = 2;
+ } else {
+ ret = 1; /* advance */
+ }
break;
- }
-
- if (ret == -1)
- goto end;
-
- sym_set_string_value(sym, dialog_input_result);
-
- dialog_clear();
-
- /* Bandwidth allocation */
- sym = sym_find("BASICLIMITING", "LOAD");
- while (true) {
- ret = dialog_yesno(_("GNUnet configuration"),
- _("Share denoted bandwidth "
- "with other applications?\n\nSay \"yes\" here, if you
don't want other "
- "network traffic to interfere with GNUnet's operation,
but still wish to "
- "constrain GNUnet's bandwidth usage to values entered
in the previous "
- "steps, or if you can't reliably measure the maximum
capabilities "
- "of your connection. \"No\" can be very useful if
other applications "
- "are causing a lot of traffic on your LAN. In this
case, you do not "
- "want to limit the traffic that GNUnet can inflict on
your internet "
- "connection whenever your high-speed LAN gets used
(e.g. by NFS)."),
- rows, cols - 5);
-
- if (ret != -2)
+ case DLG_EXIT_CANCEL:
+ case DLG_EXIT_ESC:
+ ret = 0; /* abort */
break;
- }
-
- if (ret == -1)
- goto end;
- else
- sym_set_tristate_value(sym, !ret); /* ret is inverted */
-
- dialog_clear();
-
- /* Max CPU */
- if ((sym = sym_find("MAXCPULOAD", "LOAD"))) {
- sym_calc_value_ext(sym, 1);
- defval = (char *) sym_get_string_value(sym);
- }
- else
- defval = NULL;
-
- while(true) {
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("How much CPU (in %) may "
- "be used?"), rows, cols - 5, defval ? defval : "");
-
- if (ret == 1) {
- /* Help */
- dialog_msgbox(_("Help"),
- _("You can limit GNUnet's resource usage "
- "here.\n\nThis is the percentage of processor time GNUnet
is allowed "
- "to use."), rows, cols - 5, 1);
- }
- else if (ret <= 0)
+ case DLG_EXIT_HELP:
+ show_help(help);
+ ret = 2;
break;
- }
-
- if (ret == -1)
- goto end;
-
- sym_set_string_value(sym, dialog_input_result);
-
- dialog_clear();
-
- /* Migration */
- sym = sym_find("ACTIVEMIGRATION", "FS");
- while(true) {
- ret = dialog_yesno(_("GNUnet configuration"),
- _("Store migrated content?"
- "\n\nGNUnet is able to store data from other peers in
your datastore. "
- "This is useful if an adversary has access to your
inserted content and "
- "you need to deny that the content is yours. With
\"content migration\" "
- "on, the content could have \"migrated\" over the
internet to your node"
- " without your knowledge.\nIt also helps to spread
popular content over "
- "different peers to enhance availability."), rows,
cols - 5);
-
- if (ret != -2)
+ case DLG_EXIT_EXTRA:
+ ret = -1; /* back */
break;
- }
-
- if (ret == -1)
- goto end;
- else
- sym_set_tristate_value(sym, !ret); /* ret is inverted */
-
- dialog_clear();
-
- /* Quota */
- if ((sym = sym_find("QUOTA", "FS"))) {
- sym_calc_value_ext(sym, 1);
- defval = (char *) sym_get_string_value(sym);
- }
- else
- defval = NULL;
-
- while(true) {
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("What's the maximum "
- "datastore size in MB?\n\nThe GNUnet datastore
contains all data that "
- "GNUnet generates (index data, inserted and
migrated content)."),
- rows, cols - 5, defval ? defval : "");
-
- if (ret == 1) {
- /* Help - not available */
- }
- else if (ret <= 0)
+ default:
+ GE_BREAK(ectx, 0);
+ ret = 0;
break;
+ }
}
+ FREE(fitem.name);
+ FREE(fitem.text);
+ FREE(fitem.help);
+ return ret;
+}
- if (ret == -1)
- goto end;
+static int welcome() {
+ dialog_vars.help_button = 0;
+ dialog_msgbox(_("GNUnet configuration"),
+ _("Welcome to GNUnet!\n\nThis assistant will ask you a few
basic questions "
+ "in order to configure GNUnet.\n\nPlease visit our homepage
at\n\t"
+ "http://gnunet.org/\nand join our community at\n\t"
+ "http://gnunet.org/drupal/\n\nHave a lot of fun,\n\nthe
GNUnet team"),
+ 20,
+ 70,
+ TRUE);
+ return 1;
+}
- sym_set_string_value(sym, dialog_input_result);
+#define MAX_NIC 64
- dialog_clear();
+static int insert_nic_curs(const char * name,
+ int defaultNIC,
+ void * cls) {
+ DIALOG_LISTITEM * nic_items = cls;
+ DIALOG_LISTITEM * item;
+ unsigned int pos;
- /* Autostart */
- if (isOSAutostartCapable()) {
- while(true) {
- ret = dialog_yesno(_("GNUnet configuration"),
- _("Do you want to launch "
- "GNUnet as a system service?"
- "\n\nIf you say \"yes\" here, the GNUnet background
process will be "
- "automatically started when you turn on your
computer. If you say \"no\""
- " here, you have to launch GNUnet yourself each time
you want to use it."),
- rows, cols - 5);
+ pos = 0;
+ while ( (pos < MAX_NIC) &&
+ (nic_items[pos].text != NULL) )
+ pos++;
+ if (pos == MAX_NIC)
+ return SYSERR;
+ item = &nic_items[pos];
+ item->name = "";
+ item->text = STRDUP(name);
+ item->help = "";
+ item->state = defaultNIC;
+ return OK;
+}
- if (ret != -2)
- break;
- }
+static int network_interface() {
+ DIALOG_LISTITEM nic_items[MAX_NIC];
+ unsigned int total;
+ int ret;
+ int msel;
+ DIALOG_FORMITEM fitem;
- if (ret == -1)
- goto end;
- else
- autostart = !ret; /* ret is inverted */
-
- dialog_clear();
+ fitem.type = 0;
+ fitem.name = "";
+ fitem.name_len = strlen(fitem.name);
+ fitem.name_y = 3;
+ fitem.name_x = 5;
+ fitem.name_free = 0;
+ fitem.text_y = 5;
+ fitem.text_x = 5;
+ fitem.text_flen = 55;
+ fitem.text_ilen = 63;
+ fitem.text_free = 0;
+ fitem.help_free = 0;
+ memset(nic_items,
+ 0,
+ sizeof(DIALOG_LISTITEM) * MAX_NIC);
+ os_list_network_interfaces(NULL,
+ &insert_nic_curs,
+ nic_items);
+ total = 0;
+ while ( (total < MAX_NIC) &&
+ (nic_items[total].text != NULL) ) {
+ if (nic_items[total].state)
+ msel = total;
+ total++;
}
-
- /* User */
- if (isOSUserAddCapable()) {
- while(true) {
-
- sym = sym_find("USER", "GNUNETD");
- if (sym)
- {
- sym_calc_value_ext(sym, 1);
- confUser = sym_get_string_value(sym);
+ if (total > 0) {
+ while (true) {
+ ret = dlg_menu(_("GNUnet configuration"),
+ _("Choose the network interface that connects your
computer to "
+ "the internet from the list below."),
+ 20,
+ 70,
+ 10,
+ total,
+ nic_items,
+ &msel,
+ NULL);
+ switch (ret) {
+ case DLG_EXIT_OK:
+ if (0 != GC_set_configuration_value_choice(cfg,
+ ectx,
+ "NETWORK",
+ "INTERFACE",
+ nic_items[msel].name)) {
+ show_error(_("Internal error! (Choice invalid?)"));
+ break;
}
- else
- confUser = NULL;
-
-#ifndef MINGW
- if ((NULL == confUser) || (strlen(confUser) == 0))
- {
- if((geteuid() == 0) || (NULL != getpwnam("gnunet")))
- defuser = STRDUP("gnunet");
- else {
- confUser = getenv("USER");
- if (confUser != NULL)
- defuser = STRDUP(confUser);
- else
- defuser = NULL;
- }
- }
- else
- defuser = STRDUP(confUser);
-#else
- if (NULL == confUser || strlen(confUser) == 0)
- defuser = STRDUP("");
- else
- defuser = STRDUP(confUser);
-#endif
-
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("Define the user owning the GNUnet service.\n\n"
- "For security reasons, it is a good idea to let
this setup create "
- "a new user account under which the GNUnet
service is started "
- "at system startup.\n\n"
- "However, GNUnet may not be able to access files
other than its own. "
- "This includes files you want to publish in
GNUnet. You'll have to "
- "grant read permissions to the user specified
below.\n\n"
- "Leave the fields empty to run GNUnet with system
privileges.\n\n"
- "GNUnet user:"), rows, cols - 5, defuser);
- FREE(defuser);
-
- if (ret == 1) {
- /* Help */
- } else if (ret <= 0) {
- user_name = STRDUP(dialog_input_result);
+ return 1;
+ case DLG_EXIT_HELP:
+ show_help(_("The \"Network interface\" is the device "
+ "that connects your computer to the internet. This is
usually a modem, "
+ "an ISDN card or a network card in case you are using
DSL."));
break;
+ case DLG_EXIT_ESC:
+ case DLG_EXIT_ERROR:
+ case DLG_EXIT_CANCEL:
+ return 0;
}
}
-
- if (ret == -1)
- goto end;
-
- dialog_clear();
-
- /* Group */
- if (isOSGroupAddCapable()) {
- while(true) {
- sym = sym_find("GROUP", "GNUNETD");
- if (sym)
- {
- sym_calc_value_ext(sym, 1);
- confGroup = sym_get_string_value(sym);
- }
- else
- confGroup = NULL;
-
-#ifndef MINGW
- if((NULL == confGroup) || (strlen(confGroup) == 0))
- {
- if((geteuid() == 0) || (NULL != getgrnam("gnunet")))
- defgroup = STRDUP("gnunet");
- else {
- struct group * grp;
- grp = getgrgid(getegid());
- if ( (grp != NULL) &&
- (grp->gr_name != NULL) )
- defgroup = STRDUP(grp->gr_name);
- else
- defgroup = NULL;
- }
- }
- else
- defgroup = STRDUP(confGroup);
-#else
- if ( (NULL == confGroup) ||
- (strlen(confGroup) == 0) )
- defgroup = STRDUP("");
- else
- defgroup = STRDUP(defgroup);
-#endif
-
- ret = dialog_inputbox(_("GNUnet configuration"),
- _("Define the group owning the GNUnet
service.\n\n"
- "For security reasons, it is a good idea to let
this setup create "
- "a new group for the chosen user account.\n\n"
- "You can also specify a already existant group
here.\n\n"
- "Only members of this group will be allowed to
start and stop the "
- "the GNUnet server and have access to GNUnet
server data.\n\n"
- "GNUnet group:"),
- rows, cols - 5, defgroup);
- FREE(defgroup);
-
- if (ret == 1) {
- /* Help */
- }
- else if (ret <= 0) {
- group_name = STRDUP(dialog_input_result);
- break;
- }
- }
-
- if (ret == -1)
- goto end;
-
- dialog_clear();
- }
}
+ return query_string(_("Network configuration: interface"),
+ _("What is the name of the network interface that
connects your computer to the Internet?"),
+ _("The \"Network interface\" is the device "
+ "that connects your computer to the internet. This is
usually a modem, "
+ "an ISDN card or a network card in case you are using
DSL."),
+ "NETWORK",
+ "INTERFACE",
+ "eth0");
+}
- dialog_clear();
+static int nat_limited() {
+ /* TODO: try autodetect! */
+ return query_yesno(_("Network configuration: NAT"),
+ _("Is this machine behind "
+ "NAT?\n\nIf you are connected to the internet through
another computer "
+ "doing SNAT, a router or a \"hardware firewall\" and
other computers "
+ "on the internet cannot connect to this computer, say
\"yes\" here. "
+ "Answer \"no\" on direct connections through modems,
ISDN cards and "
+ "DNAT (also known as \"port forwarding\")."),
+ NULL,
+ "NAT",
+ "LIMITED");
+}
- /* Advanced */
- while(true) {
- ret = dialog_yesno(_("GNUnet configuration"),
- _("If you are an experienced "
- "user, you may want to tweak your GNUnet installation
using the enhanced "
- "configurator.\n\nDo you want to start it after saving
your configuration?"),
- rows, cols - 5);
+static int ip_address() {
+ /* TODO: try autodetect! */
+ return query_string(_("Network configuration: IP"),
+ _("What is this computer's public IP address or
hostname?"),
+ _("If your provider always assigns the same "
+ "IP-Address to you (a \"static\" IP-Address), enter it
into the "
+ "\"IP-Address\" field. If your IP-Address changes every
now and then "
+ "(\"dynamic\" IP-Address) but there's a hostname that
always points "
+ "to your actual IP-Address (\"Dynamic DNS\"), you can
also enter it "
+ "here.\n"
+ "If left empty, GNUnet will try to automatically detect
the IP.\n"
+ "You can specify a hostname, GNUnet will then use DNS
to resolve it.\n"
+ "If in doubt, leave this empty."),
+ "NETWORK",
+ "IP",
+ "");
+}
- if (ret != -2)
- break;
- }
+static int network_load_up() {
+ return query_string(_("Bandwidth configuration: upload"),
+ _("How much upstream bandwidth (in bytes/s) may be
used?"),
+ _("You can limit GNUnet's resource usage "
+ "here.\n\nThe \"upstream\" is the data channel through
which data "
+ "is *sent* to the internet. The limit is the maximum
amount"
+ "which GNUnet is allowed to use. If you have a
flatrate, you can set it to "
+ "the maximum speed of your internet connection. You
should not use a value "
+ "that is higher than what your actual connection
allows."),
+ "LOAD",
+ "MAXNETUPBPSTOTAL",
+ "50000");
+}
- if (ret == -1)
- goto end;
- else
- adv = !ret;
+static int network_load_down() {
+ return query_string(_("Bandwidth configuration: download"),
+ _("How much downstream bandwidth (in bytes/s) may be
used?"),
+ _("You can limit GNUnet's resource usage "
+ "here.\n\nThe \"downstream\" is the data channel
through which data "
+ "is *received* from the internet. The limit is the
maximum amount"
+ "which GNUnet is allowed to use. If you have a
flatrate, you can set it to "
+ "the maximum speed of your internet connection. You
should not use a value "
+ "that is higher than what your actual connection
allows."),
+ "LOAD",
+ "MAXNETDOWNBPSTOTAL",
+ "50000");
+}
- dialog_clear();
- end_dialog();
+static int disk_quota() {
+ return query_string(_("Quota configuration"),
+ _("What is the maximum size of the datastore in MB?"),
+ _("The GNUnet datastore contains all content that "
+ "GNUnet needs to store (indexed, inserted and migrated
content)."),
+ "FS",
+ "QUOTA",
+ "1024");
+}
- /* Save config */
- if ( (user_name != NULL) &&
- (strlen(user_name) > 0) )
- if (!wiz_createGroupUser(group_name, user_name))
- showCursErr(_("Unable to create user account:"), STRERROR(errno));
+static int user() {
+ if (YES != os_modify_user(YES,
+ YES,
+ "gnunet",
+ "gnunet"))
+ return last; /* ignore option */
+ return query_string(_("Daemon configuration: user account"),
+ _("As which user should gnunetd be run?"),
+ _("For security reasons, it is a good idea to let this
setup create "
+ "a new user account under which the GNUnet service is
started "
+ "at system startup.\n\n"
+ "However, GNUnet may not be able to access files other
than its own. "
+ "This includes files you want to publish in GNUnet.
You'll have to "
+ "grant read permissions to the user specified
below.\n\n"
+ "Leave the field empty to run GNUnet with system
privileges.\n"),
+ "GNUNETD",
+ "USER",
+ "gnunet");
+}
- if (!wiz_autostartService(autostart, user_name, group_name))
- showCursErr(_("Unable to change startup process:"), STRERROR(errno));
+static int group() {
+ if (YES != os_modify_user(YES,
+ YES,
+ "gnunet",
+ "gnunet"))
+ return last; /* ignore option */
+ return query_string(_("Daemon configuration: group account"),
+ _("As which group should gnunetd be run?"),
+ _("For security reasons, it is a good idea to let this
setup create "
+ "a new group for the chosen user account.\n\n"
+ "You can also specify a already existant group
here.\n\n"
+ "Only members of this group will be allowed to start
and stop the "
+ "the GNUnet server and have access to GNUnet server
data.\n"),
+ "GNUNETD",
+ "GROUP",
+ "gnunet");
+}
- init_dialog();
- dialog_clear();
- while(true) {
- confFile = getConfigurationString("GNUNET-SETUP",
- "FILENAME");
- if (conf_write(confFile) != 0) {
- char * err;
- const char * prefix;
- const char * strerr;
+static int autostart() {
+ return query_yesno(_("GNUnet configuration"),
+ _("Do you want to automatically launch GNUnet as a system
service?"),
+ _("If you say \"yes\" here, the GNUnet background process
will be "
+ "automatically started when you turn on your computer.
If you say \"no\""
+ " here, you have to launch GNUnet yourself each time you
want to use it."),
+ "GNUNETD",
+ "AUTOSTART");
+}
- prefix = _("Unable to save configuration file %s: %s.\n\nTry again?");
- strerr = STRERROR(errno);
+/**
+ * Save configuration, setup username, group and autostart.
+ */
+static int finish() {
+ const char * prefix;
+ char * err;
+ int ret;
+ char * user_name;
+ char * group_name;
- err = malloc(strlen(confFile) + strlen(prefix) + strlen(strerr) + 1);
- sprintf(err, prefix, confFile, strerr);
+ ret = OK;
+
+ if ( (0 != GC_test_dirty(cfg)) &&
+ (0 != GC_write_configuration(cfg, cfg_fn)) ) {
+ prefix = _("Unable to save configuration file `%s':");
+ err = MALLOC(strlen(cfg_fn) + strlen(prefix) + 1);
+ sprintf(err, prefix, cfg_fn);
+ showCursErr(err, STRERROR(errno));
+ ret = SYSERR;
+ }
+ user_name = NULL;
+ GC_get_configuration_value_string(cfg,
+ "GNUNETD",
+ "USER",
+ "",
+ &user_name);
+ GC_get_configuration_value_string(cfg,
+ "GNUNETD",
+ "GROUP",
+ "",
+ &group_name);
+ if ( ( (strlen(user_name) > 0) ||
+ (strlen(group_name) > 0) ) &&
+ (OK == os_modify_user(YES,
+ YES,
+ user_name,
+ group_name)) &&
+ (OK != os_modify_user(NO,
+ YES,
+ user_name,
+ group_name)) ) {
+ showCursErr(_("Unable to create user account for daemon."),
+ "");
+ ret = SYSERR;
+ }
+ if ( (YES == GC_get_configuration_value_yesno(cfg,
+ "GNUNETD",
+ "AUTOSTART",
+ NO)) &&
+ (YES != os_modify_autostart(ectx,
+ NO,
+ YES,
+ "gnunetd", /* specify full path? */
+ user_name,
+ group_name)) ) {
+ showCursErr(_("Unable to setup autostart for daemon."),
+ "");
+ ret = SYSERR;
+ }
+ FREE(user_name);
+ FREE(group_name);
+ return ret;
+}
- ret = dialog_yesno(_("GNUnet configuration"),
- err,
- rows,
- cols - 5);
+static int save_config() {
+ int ret;
- free(err);
- }
- else
- ret = 1;
-
- if (ret == 1 || ret == -1)
- break;
+ /* TODO: check configuration changed! */
+ dialog_vars.help_button = 0;
+ ret = dialog_yesno(_("Save configuration?"),
+ _("Save configuration now?"),
+ 5,
+ 60);
+ switch(ret) {
+ case DLG_EXIT_OK:
+ if (OK != finish())
+ return 0; /* error */
+ return 1;
+ case DLG_EXIT_CANCEL:
+ return 1; /* advance */
+ case DLG_EXIT_ESC:
+ return 0; /* abort */
+ case DLG_EXIT_EXTRA:
+ return -1; /* back */
+ default:
+ GE_BREAK(ectx, 0);
+ break;
}
+ return 1;
+}
-end:
- end_dialog();
+int wizard_curs_mainsetup_curses(int argc,
+ const char **argv,
+ struct PluginHandle * self,
+ struct GE_Context * e,
+ struct GC_Configuration * c,
+ struct GNS_Context * gns,
+ const char * filename,
+ int is_daemon) {
+ struct termios ios_org;
+ unsigned int phase;
+ int ret;
+ int dir;
- FREENONNULL(user_name);
- FREENONNULL(group_name);
+ ectx = e;
+ cfg = c;
+ cfg_fn = filename;
+#ifndef MINGW
+ tcgetattr(1, &ios_org);
+#endif
+ dialog_vars.backtitle = _("GNUnet Configuration");
+ dialog_vars.item_help = 1;
+ dialog_vars.help_button = 1;
+ dialog_vars.extra_button = 1;
+ dialog_vars.extra_label = _("Back");
+ init_dialog(stdin, stderr);
- if (adv) {
- mconf_main(argc, argv);
- }
-
- return 0;
+ phase = 0;
+ ret = NO;
+ while (ret == NO) {
+ switch(phase) {
+ case 0:
+ dir = welcome();
+ break;
+ case 1:
+ dir = network_interface();
+ break;
+ case 2:
+ dir = nat_limited();
+ break;
+ case 3:
+ dir = ip_address();
+ break;
+ case 4:
+ dir = network_load_up();
+ break;
+ case 5:
+ dir = network_load_down();
+ break;
+ case 6:
+ dir = disk_quota();
+ break;
+ case 7:
+ dir = user();
+ break;
+ case 8:
+ dir = group();
+ break;
+ case 9:
+ dir = autostart();
+ break;
+ case 10:
+ dir = save_config();
+ break;
+ case 11:
+ ret = OK;
+ break;
+ }
+ phase += dir;
+ last = dir;
+ if (dir == 0)
+ ret = SYSERR;
+ }
+ end_dialog();
+#ifndef MINGW
+ tcsetattr(1, TCSAFLUSH, &ios_org);
+#endif
+ return ret;
}
/* end of wizard_curs.c */
Modified: GNUnet/src/setup/ncurses/wizard_curs.h
===================================================================
--- GNUnet/src/setup/ncurses/wizard_curs.h 2006-12-11 21:09:18 UTC (rev
3920)
+++ GNUnet/src/setup/ncurses/wizard_curs.h 2006-12-12 03:27:03 UTC (rev
3921)
@@ -28,13 +28,13 @@
#ifndef WIZARD_CURS_H
#define WIZARD_CURS_H
-int wizard_curs_main_ncurses(int argc,
- const char **argv,
- struct PluginHandle * self,
- struct GE_Context * ectx,
- struct GC_Configuration * cfg,
- struct GNS_Context * gns,
- const char * filename,
- int is_daemon);
+int wizard_curs_mainsetup_curses(int argc,
+ const char **argv,
+ struct PluginHandle * self,
+ struct GE_Context * ectx,
+ struct GC_Configuration * cfg,
+ struct GNS_Context * gns,
+ const char * filename,
+ int is_daemon);
#endif
Modified: GNUnet/src/util/os/user.c
===================================================================
--- GNUnet/src/util/os/user.c 2006-12-11 21:09:18 UTC (rev 3920)
+++ GNUnet/src/util/os/user.c 2006-12-12 03:27:03 UTC (rev 3921)
@@ -82,7 +82,7 @@
char * cmd;
haveGroup = group_name && strlen(group_name) > 0;
- cmd = MALLOC(haveGroup ? strlen(group_name) : 0 + strlen(user_name) + 64);
+ cmd = MALLOC(256 + (haveGroup ? strlen(group_name) : 0) +
strlen(user_name));
if (haveGroup) {
sprintf(cmd,
Modified: GNUnet/src/util/string/xmalloc.c
===================================================================
--- GNUnet/src/util/string/xmalloc.c 2006-12-11 21:09:18 UTC (rev 3920)
+++ GNUnet/src/util/string/xmalloc.c 2006-12-12 03:27:03 UTC (rev 3921)
@@ -27,7 +27,6 @@
#include "gnunet_util_string.h"
#include "gnunet_util_error.h"
#include "platform.h"
-#include "dlmalloc.h"
#ifndef INT_MAX
#define INT_MAX 0x7FFFFFFF
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-12-11 21:09:18 UTC (rev 3920)
+++ GNUnet/todo 2006-12-12 03:27:03 UTC (rev 3921)
@@ -13,8 +13,6 @@
0.7.1 [12'06] (aka "stabilization")
-- finish util refactoring:
- * gnunet-setup ncurses wizard [RCpre2]
- more testcases: [RCpre3]
* ecrs_core
* gap (incl. economy)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3921 - in GNUnet: . src/setup src/setup/gtk src/setup/ncurses src/util/os src/util/string,
grothoff <=