/**
*
*/
-static void
-access_entry_destroy(access_entry_t *ae)
+void
+access_entry_destroy(access_entry_t *ae, int delconf)
{
access_ipmask_t *ai;
+ char ubuf[UUID_HEX_SIZE];
+
+ if (delconf)
+ hts_settings_remove("accesscontrol/%s", idnode_uuid_as_str(&ae->ae_id, ubuf));
TAILQ_REMOVE(&access_entries, ae, ae_link);
idnode_unlink(&ae->ae_id);
access_entry_class_delete(idnode_t *self)
{
access_entry_t *ae = (access_entry_t *)self;
- char ubuf[UUID_HEX_SIZE];
-
- hts_settings_remove("accesscontrol/%s", idnode_uuid_as_str(&ae->ae_id, ubuf));
- access_entry_destroy(ae);
+ access_entry_destroy(ae, 1);
}
static void
.name = N_("Comment"),
.off = offsetof(access_entry_t, ae_comment),
},
+ {
+ .type = PT_BOOL,
+ .id = "wizard",
+ .name = N_("Wizard"),
+ .off = offsetof(access_entry_t, ae_wizard),
+ .opts = PO_NOUI
+ },
{}
}
};
return pw;
}
-static void
-passwd_entry_destroy(passwd_entry_t *pw)
+void
+passwd_entry_destroy(passwd_entry_t *pw, int delconf)
{
+ char ubuf[UUID_HEX_SIZE];
+
if (pw == NULL)
return;
+
+ if (delconf)
+ hts_settings_remove("passwd/%s", idnode_uuid_as_str(&pw->pw_id, ubuf));
TAILQ_REMOVE(&passwd_entries, pw, pw_link);
idnode_unlink(&pw->pw_id);
free(pw->pw_username);
passwd_entry_class_delete(idnode_t *self)
{
passwd_entry_t *pw = (passwd_entry_t *)self;
- char ubuf[UUID_HEX_SIZE];
-
- hts_settings_remove("passwd/%s", idnode_uuid_as_str(&pw->pw_id, ubuf));
- passwd_entry_destroy(pw);
+ passwd_entry_destroy(pw, 1);
}
static const char *
.name = N_("Comment"),
.off = offsetof(passwd_entry_t, pw_comment),
},
+ {
+ .type = PT_BOOL,
+ .id = "wizard",
+ .name = N_("Wizard"),
+ .off = offsetof(passwd_entry_t, pw_wizard),
+ .opts = PO_NOUI
+ },
{}
}
};
pthread_mutex_lock(&global_lock);
while ((ae = TAILQ_FIRST(&access_entries)) != NULL)
- access_entry_destroy(ae);
+ access_entry_destroy(ae, 0);
while ((at = TAILQ_FIRST(&access_tickets)) != NULL)
access_ticket_destroy(at);
while ((pw = TAILQ_FIRST(&passwd_entries)) != NULL)
- passwd_entry_destroy(pw);
+ passwd_entry_destroy(pw, 0);
while ((ib = TAILQ_FIRST(&ipblock_entries)) != NULL)
ipblock_entry_destroy(ib);
free((void *)superuser_username);
return &t; \
}
+#define BASIC_STR_OPS(stru, field) \
+static const void *wizard_get_value_##field(void *o) \
+{ \
+ wizard_page_t *p = o; \
+ stru *w = p->aux; \
+ snprintf(prop_sbuf, PROP_SBUF_LEN, "%s", w->field); \
+ return &prop_sbuf_ptr; \
+} \
+static int wizard_set_value_##field(void *o, const void *v) \
+{ \
+ wizard_page_t *p = o; \
+ stru *w = p->aux; \
+ snprintf(w->field, sizeof(w->field), v); \
+ return 1; \
+}
+
/*
*
*/
* Hello
*/
+typedef struct wizard_hello {
+ char network[256];
+ char admin_username[32];
+ char admin_password[32];
+ char username[32];
+ char password[32];
+} wizard_hello_t;
+
+
+static void hello_save(idnode_t *in)
+{
+ wizard_page_t *p = (wizard_page_t *)in;
+ wizard_hello_t *w = p->aux;
+ access_entry_t *ae, *ae_next;
+ passwd_entry_t *pw, *pw_next;
+ htsmsg_t *conf;
+ const char *s;
+
+ for (ae = TAILQ_FIRST(&access_entries); ae; ae = ae_next) {
+ ae_next = TAILQ_NEXT(ae, ae_link);
+ if (ae->ae_wizard)
+ access_entry_destroy(ae, 1);
+ }
+
+ for (pw = TAILQ_FIRST(&passwd_entries); pw; pw = pw_next) {
+ pw_next = TAILQ_NEXT(pw, pw_link);
+ if (pw->pw_wizard)
+ passwd_entry_destroy(pw, 1);
+ }
+
+ s = w->admin_username[0] ? w->admin_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->admin_password);
+ htsmsg_add_bool(conf, "streaming", 1);
+ htsmsg_add_bool(conf, "adv_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);
+ htsmsg_add_bool(conf, "admin", 1);
+ ae = access_entry_create(NULL, conf);
+ if (ae) {
+ ae->ae_wizard = 1;
+ access_entry_save(ae);
+ }
+ htsmsg_destroy(conf);
+
+ if (s && s[0] != '*' && w->admin_password[0]) {
+ conf = htsmsg_create_map();
+ htsmsg_add_bool(conf, "enabled", 1);
+ htsmsg_add_str(conf, "username", s);
+ htsmsg_add_str(conf, "password", w->admin_password);
+ pw = passwd_entry_create(NULL, conf);
+ if (pw) {
+ pw->pw_wizard = 1;
+ passwd_entry_save(pw);
+ }
+ }
+
+ if (w->username[0]) {
+ s = w->username && w->username[0] ? w->username : "*";
+ conf = htsmsg_create_map();
+ htsmsg_add_str(conf, "prefix", w->network);
+ htsmsg_add_str(conf, "username", s);
+ htsmsg_add_str(conf, "password", w->password);
+ ae = access_entry_create(NULL, conf);
+ if (ae) {
+ ae->ae_wizard = 1;
+ access_entry_save(ae);
+ }
+ htsmsg_destroy(conf);
+
+ if (s && s[0] != '*' && w->password && w->password[0]) {
+ conf = htsmsg_create_map();
+ htsmsg_add_bool(conf, "enabled", 1);
+ htsmsg_add_str(conf, "username", s);
+ htsmsg_add_str(conf, "password", w->password);
+ pw = passwd_entry_create(NULL, conf);
+ if (pw) {
+ pw->pw_wizard = 1;
+ passwd_entry_save(pw);
+ }
+ }
+ }
+}
+
+BASIC_STR_OPS(wizard_hello_t, network)
+BASIC_STR_OPS(wizard_hello_t, admin_username)
+BASIC_STR_OPS(wizard_hello_t, admin_password)
+BASIC_STR_OPS(wizard_hello_t, username)
+BASIC_STR_OPS(wizard_hello_t, password)
+
static const void *hello_get_network(void *o)
{
strcpy(prop_sbuf, "Test123");
.type = PT_STR,
.id = "network",
.name = N_("Allowed network"),
- .get = hello_get_network,
- .set = hello_set_network,
+ .get = wizard_get_value_network,
+ .set = wizard_set_value_network,
.group = 1
},
{
.type = PT_STR,
.id = "admin_username",
.name = N_("Admin username"),
- .get = hello_get_network,
- .set = hello_set_network,
+ .get = wizard_get_value_admin_username,
+ .set = wizard_set_value_admin_username,
.group = 2
},
{
.type = PT_STR,
.id = "admin_password",
.name = N_("Admin password"),
- .get = hello_get_network,
- .set = hello_set_network,
+ .get = wizard_get_value_admin_password,
+ .set = wizard_set_value_admin_password,
.group = 2
},
{
.type = PT_STR,
.id = "username",
.name = N_("Username"),
- .get = hello_get_network,
- .set = hello_set_network,
+ .get = wizard_get_value_username,
+ .set = wizard_set_value_username,
.group = 3
},
{
.type = PT_STR,
.id = "password",
.name = N_("Password"),
- .get = hello_get_network,
- .set = hello_set_network,
+ .get = wizard_get_value_password,
+ .set = wizard_set_value_password,
.group = 3
},
ICON(),
page_init("wizard_hello",
N_("Welcome - Tvheadend - your TV streaming server and video recorder"));
idclass_t *ic = (idclass_t *)page->idnode.in_class;
+ wizard_hello_t *w;
+ access_entry_t *ae;
+ passwd_entry_t *pw;
+
ic->ic_properties = props;
ic->ic_groups = groups;
+ ic->ic_save = hello_save;
+ page->aux = w = calloc(1, sizeof(wizard_hello_t));
+
+ TAILQ_FOREACH(ae, &access_entries, ae_link) {
+ if (!ae->ae_wizard)
+ continue;
+ if (ae->ae_admin) {
+ htsmsg_t *c = htsmsg_create_map();
+ idnode_save(&ae->ae_id, c);
+ snprintf(w->admin_username, sizeof(w->admin_username), "%s", ae->ae_username);
+ snprintf(w->network, sizeof(w->network), "%s", htsmsg_get_str(c, "prefix") ?: "");
+ htsmsg_destroy(c);
+ } else {
+ snprintf(w->username, sizeof(w->username), "%s", ae->ae_username);
+ }
+ }
+
+ TAILQ_FOREACH(pw, &passwd_entries, pw_link) {
+ if (!pw->pw_wizard || !pw->pw_username)
+ continue;
+ if (w->admin_username[0] &&
+ strcmp(w->admin_username, pw->pw_username) == 0) {
+ snprintf(w->admin_password, sizeof(w->admin_password), "%s", pw->pw_password);
+ } else if (w->username[0] && strcmp(w->username, pw->pw_username) == 0) {
+ snprintf(w->password, sizeof(w->password), "%s", pw->pw_password);
+ }
+ }
+
return page;
}
.id = "network" STRINGIFY(num), \
.name = nameval, \
.get = network_get_value##num, \
- .set = hello_set_network, \
+ .set = network_set_value##num, \
.list = network_get_list, \
}
wizard_network_t *w = p->aux; \
snprintf(prop_sbuf, PROP_SBUF_LEN, "%s", w->network_type##num); \
return &prop_sbuf_ptr; \
+} \
+static int network_set_value##num(void *o, const void *v) \
+{ \
+ wizard_page_t *p = o; \
+ wizard_network_t *w = p->aux; \
+ snprintf(w->network_type##num, sizeof(w->network_type##num), v); \
+ return 1; \
}
NETWORK_FCN(1)
NETWORK_FCN(4)
DESCRIPTION_FCN(network, N_("\
-Create networks.\
+Create networks. The T means terresterial, C is cable and S is satellite.\
"))
static htsmsg_t *network_get_list(void *o, const char *lang)