Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wizard: fix the username/password handling, last page
  • Loading branch information
perexg committed Feb 8, 2016
1 parent 866f8ff commit 5e1672b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/access.c
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/access.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/idnode.c
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/idnode.h
Expand Up @@ -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
Expand All @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion src/webui/comet.c
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/webui/static/app/idnode.js
Expand Up @@ -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: {
Expand Down
26 changes: 19 additions & 7 deletions src/webui/static/app/wizard.js
Expand Up @@ -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();
Expand Down Expand Up @@ -135,17 +137,27 @@ 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) {
window.location.reload();
return;
}
}
if (!last)
if (!last) {
newpage(conf, 'page_next_');
else
cancel(conf);
} else {
cancel(conf, 1);
window.location.reload();
}
},
buildbtn: buildbtn,
labelWidth: 250,
Expand Down
54 changes: 49 additions & 5 deletions src/wizard.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand All @@ -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)
{
Expand All @@ -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;
}

0 comments on commit 5e1672b

Please sign in to comment.