]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
wizard: fix the username/password handling, last page
authorJaroslav Kysela <perex@perex.cz>
Mon, 8 Feb 2016 13:41:06 +0000 (14:41 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 8 Feb 2016 13:41:06 +0000 (14:41 +0100)
src/access.c
src/access.h
src/idnode.c
src/idnode.h
src/webui/comet.c
src/webui/static/app/idnode.js
src/webui/static/app/wizard.js
src/wizard.c

index e70bee7559a52240ca7060a3588299bd77558cd2..b1acbecea8a9b27cc50bedba5a54ab4f900c8eb9 100644 (file)
@@ -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;
index c4e94dcd1b1df0b21dbf49732e13d6df349050b9..8b5f6a8ff65a214fa51b38141f4cb76fbd83b9fc 100644 (file)
@@ -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;
index 73634fa5158f9c355da72e42565bed881e73e638..08e4a4b1f390c42634a562e3453377e81dfb3830 100644 (file)
@@ -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);
index e47dd591800d6f6d9aba64d6d192c6186327026d..49fb42be827fe7662c39115996b0c3500c79961f 100644 (file)
@@ -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 */
index 6b9de24c38c1c953a9beb3d8ca2985f566641451..fded6f566c2b671f407b48355cf53d24fd5571f9 100644 (file)
@@ -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) {
index 04b719a0112ab8f3abe62ca3e042aa9d97e7aa68..f68f68d2f5b8bfd2af93e427996b058fac4737b6 100644 (file)
@@ -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: {
index e11a0c7eaac192c0369b5e26e68e9943dc301cf0..a784993078e61cc9040d10b5b582b7530bca8fda 100644 (file)
@@ -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,
index be4186efd2fc0f519228d833dcc5390fb5887585..affcf717a2ee12ff2c6cc88dce91e2c5caaf8e6f 100644 (file)
@@ -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;
 }