From: Jaroslav Kysela Date: Mon, 8 Feb 2016 13:41:06 +0000 (+0100) Subject: wizard: fix the username/password handling, last page X-Git-Tag: v4.2.1~1063 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e1672be677321477c019c3f6574ed3f893f1d11;p=thirdparty%2Ftvheadend.git wizard: fix the username/password handling, last page --- diff --git a/src/access.c b/src/access.c index e70bee755..b1acbecea 100644 --- a/src/access.c +++ b/src/access.c @@ -2048,7 +2048,7 @@ access_init(int createdefault, int noacl) ae = access_entry_create(NULL, NULL); free(ae->ae_comment); - ae->ae_comment = strdup("Default access entry"); + ae->ae_comment = strdup(ACCESS_DEFAULT_COMMENT); ae->ae_enabled = 1; ae->ae_streaming = 1; diff --git a/src/access.h b/src/access.h index c4e94dcd1..8b5f6a8ff 100644 --- a/src/access.h +++ b/src/access.h @@ -22,6 +22,8 @@ #include "idnode.h" #include "htsmsg.h" +#define ACCESS_DEFAULT_COMMENT "Default access entry" + struct profile; struct dvr_config; struct channel_tag; diff --git a/src/idnode.c b/src/idnode.c index 73634fa51..08e4a4b1f 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -1109,7 +1109,7 @@ idnode_write0 ( idnode_t *self, htsmsg_t *c, int optmask, int dosave ) int save = 0; const idclass_t *idc = self->in_class; save = idnode_class_write_values(self, idc, c, optmask); - if (save && dosave) + if ((idc->ic_flags & IDCLASS_ALWAYS_SAVE) != 0 || (save && dosave)) idnode_savefn(self); if (dosave) idnode_notify_changed(self); diff --git a/src/idnode.h b/src/idnode.h index e47dd5918..49fb42be8 100644 --- a/src/idnode.h +++ b/src/idnode.h @@ -54,6 +54,8 @@ typedef struct property_group /* * Class definition */ +#define IDCLASS_ALWAYS_SAVE (1<<0) ///< Always call the save callback + typedef struct idclass idclass_t; struct idclass { const struct idclass *ic_super; ///< Parent class @@ -64,6 +66,7 @@ struct idclass { const property_t *ic_properties; ///< Property list const char *ic_event; ///< Events to fire on add/delete/title uint32_t ic_perm_def; ///< Default permissions + uint32_t ic_flags; ///< Extra flags idnode_t *ic_snode; ///< Simple node /* Callbacks */ diff --git a/src/webui/comet.c b/src/webui/comet.c index 6b9de24c3..fded6f566 100644 --- a/src/webui/comet.c +++ b/src/webui/comet.c @@ -147,12 +147,14 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb) extern int access_noacl; htsmsg_t *m = htsmsg_create_map(); - const char *username = hc->hc_access ? (hc->hc_access->aa_username ?: "") : ""; + const char *username; int64_t bfree, bused, btotal; int dvr = !http_access_verify(hc, ACCESS_RECORDER); int admin = !http_access_verify(hc, ACCESS_ADMIN); const char *s; + username = hc->hc_access ? (hc->hc_access->aa_username ?: "") : ""; + htsmsg_add_str(m, "notificationClass", "accessUpdate"); switch (hc->hc_access->aa_uilevel) { diff --git a/src/webui/static/app/idnode.js b/src/webui/static/app/idnode.js index 04b719a01..f68f68d2f 100644 --- a/src/webui/static/app/idnode.js +++ b/src/webui/static/app/idnode.js @@ -1090,6 +1090,8 @@ tvheadend.idnode_editor = function(_uilevel, item, conf) var node = null; if (form.isDirty() || conf.alwaysDirty) { node = values(form); + if (conf.presave) + conf.presave(conf, node); tvheadend.Ajax({ url: conf.saveURL || 'api/idnode/save', params: { diff --git a/src/webui/static/app/wizard.js b/src/webui/static/app/wizard.js index e11a0c7ea..a78499307 100644 --- a/src/webui/static/app/wizard.js +++ b/src/webui/static/app/wizard.js @@ -16,10 +16,12 @@ tvheadend.wizard_start = function(page) { channels: 'channels' } - function cancel(conf) { - tvheadend.Ajax({ - url: 'api/wizard/cancel' - }); + function cancel(conf, noajax) { + if (!noajax) { + tvheadend.Ajax({ + url: 'api/wizard/cancel' + }); + } tvheadend.wizard = null; if (conf.win) conf.win.close(); @@ -135,6 +137,14 @@ tvheadend.wizard_start = function(page) { comet: m.events, noApply: true, noUIlevel: true, + alwaysDirty: last, + presave: function(conf, data) { + if (last) { + tvheadend.Ajax({ + url: 'api/wizard/cancel' + }); + } + }, postsave: function(conf, data) { if (data) { if (('ui_lang' in data) && data['ui_lang'] != tvh_locale_lang) { @@ -142,10 +152,12 @@ tvheadend.wizard_start = function(page) { return; } } - if (!last) + if (!last) { newpage(conf, 'page_next_'); - else - cancel(conf); + } else { + cancel(conf, 1); + window.location.reload(); + } }, buildbtn: buildbtn, labelWidth: 250, diff --git a/src/wizard.c b/src/wizard.c index be4186efd..affcf717a 100644 --- a/src/wizard.c +++ b/src/wizard.c @@ -292,7 +292,6 @@ static void login_save(idnode_t *in) htsmsg_add_bool(conf, "enabled", 1); htsmsg_add_str(conf, "prefix", w->network); htsmsg_add_str(conf, "username", s); - htsmsg_add_str(conf, "password", w->admin_password); htsmsg_add_bool(conf, "streaming", 1); htsmsg_add_bool(conf, "adv_streaming", 1); htsmsg_add_bool(conf, "htsp_streaming", 1); @@ -323,9 +322,14 @@ static void login_save(idnode_t *in) if (w->username[0]) { s = w->username[0] ? w->username : "*"; conf = htsmsg_create_map(); + htsmsg_add_bool(conf, "enabled", 1); htsmsg_add_str(conf, "prefix", w->network); htsmsg_add_str(conf, "username", s); - htsmsg_add_str(conf, "password", w->password); + htsmsg_add_bool(conf, "streaming", 1); + htsmsg_add_bool(conf, "htsp_streaming", 1); + htsmsg_add_bool(conf, "dvr", 1); + htsmsg_add_bool(conf, "htsp_dvr", 1); + htsmsg_add_bool(conf, "webui", 1); ae = access_entry_create(NULL, conf); if (ae) { ae->ae_wizard = 1; @@ -1094,7 +1098,6 @@ wizard_page_t *wizard_mapping(const char *lang) DESCRIPTION(mapping), PREV_BUTTON(status), NEXT_BUTTON(channels), - LAST_BUTTON(), {} }; wizard_page_t *page = page_init("mapping", "wizard_mapping", N_("Service mapping")); @@ -1112,11 +1115,36 @@ wizard_page_t *wizard_mapping(const char *lang) * Discovered channels */ +static void channels_save(idnode_t *in) +{ + access_entry_t *ae, *ae_next; + + /* check, if we have another admin account */ + TAILQ_FOREACH(ae, &access_entries, ae_link) + if (ae->ae_admin && ae->ae_wizard) break; + if (ae == NULL) + return; + /* remove the default access entry */ + for (ae = TAILQ_FIRST(&access_entries); ae; ae = ae_next) { + ae_next = TAILQ_NEXT(ae, ae_link); + if (strcmp(ae->ae_comment, ACCESS_DEFAULT_COMMENT) == 0) { + access_entry_destroy(ae, 1); + break; + } + } +} + DESCRIPTION_FCN(channels, N_("\ You are finished now.\n\ -You may further customize your settings by editing channel numbers etc.\ +You may further customize your settings by editing channel numbers etc.\n\ +If you confirm this dialog, the default administrator account will be\ +removed! Please, use credentals you defined through this wizard!\ ")) +DESCRIPTION_FCN(channels2, N_("\ +You are finished now.\n\ +You may further customize your settings by editing channel numbers etc.\ +")) wizard_page_t *wizard_channels(const char *lang) { @@ -1127,8 +1155,24 @@ wizard_page_t *wizard_channels(const char *lang) LAST_BUTTON(), {} }; - wizard_page_t *page = page_init("channels", "wizard_channels", N_("Service mapping")); + static const property_t props2[] = { + ICON(), + DESCRIPTION(channels2), + PREV_BUTTON(mapping), + LAST_BUTTON(), + {} + }; + wizard_page_t *page = page_init("channels", "wizard_channels", N_("Channels")); idclass_t *ic = (idclass_t *)page->idnode.in_class; + access_entry_t *ae; + ic->ic_properties = props; + ic->ic_flags |= IDCLASS_ALWAYS_SAVE; + ic->ic_save = channels_save; + /* do we have an admin created by wizard? */ + TAILQ_FOREACH(ae, &access_entries, ae_link) + if (ae->ae_admin && ae->ae_wizard) break; + if (ae == NULL) + ic->ic_properties = props2; return page; }