Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add user interface level (HTTP API/WEBUI)
  • Loading branch information
perexg committed Dec 1, 2015
1 parent b4ce047 commit 257f19d
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 34 deletions.
90 changes: 56 additions & 34 deletions src/access.c
Expand Up @@ -407,7 +407,7 @@ access_dump_a(access_t *a)
int first;

tvh_strlcatf(buf, sizeof(buf), l,
"%s:%s [%c%c%c%c%c%c%c%c%c%c], conn=%u:s%u:r%u%s",
"%s:%s [%c%c%c%c%c%c%c%c%c%c], conn=%u:s%u:r%u:l%u%s",
a->aa_representative ?: "<no-id>",
a->aa_username ?: "<no-user>",
a->aa_rights & ACCESS_STREAMING ? 'S' : ' ',
Expand All @@ -423,6 +423,7 @@ access_dump_a(access_t *a)
a->aa_conn_limit,
a->aa_conn_limit_streaming,
a->aa_conn_limit_dvr,
a->aa_uilevel,
a->aa_match ? ", matched" : "");

if (a->aa_profiles) {
Expand Down Expand Up @@ -486,7 +487,19 @@ access_dump_a(access_t *a)
*/
static access_t *access_alloc(void)
{
return calloc(1, sizeof(access_t));
access_t *a = calloc(1, sizeof(access_t));
a->aa_uilevel = -1;
return a;
}

/*
*
*/
static access_t *access_full(access_t *a)
{
a->aa_rights = ACCESS_FULL;
a->aa_uilevel = UILEVEL_EXPERT;
return a;
}

/*
Expand All @@ -513,6 +526,9 @@ access_update(access_t *a, access_entry_t *ae)
break;
}

if(ae->ae_uilevel > a->aa_uilevel)
a->aa_uilevel = ae->ae_uilevel;

if(ae->ae_chmin || ae->ae_chmax) {
uint64_t *p = realloc(a->aa_chrange, (a->aa_chrange_count + 2) * sizeof(uint64_t));
if (p) {
Expand Down Expand Up @@ -592,6 +608,8 @@ access_set_lang_ui(access_t *a)
if (a->aa_lang)
a->aa_lang_ui = strdup(a->aa_lang);
}
if (a->aa_uilevel < 0)
a->aa_uilevel = config.uilevel;
}

/**
Expand All @@ -611,25 +629,19 @@ access_get(const char *username, const char *password, struct sockaddr *src)
a->aa_username = strdup(username);
a->aa_representative = strdup(username);
if(!passwd_verify2(username, password,
superuser_username, superuser_password)) {
a->aa_rights = ACCESS_FULL;
return a;
}
superuser_username, superuser_password))
return access_full(a);
} else {
a->aa_representative = malloc(50);
tcp_get_str_from_ip((struct sockaddr*)src, a->aa_representative, 50);
if(!passwd_verify2(username, password,
superuser_username, superuser_password)) {
a->aa_rights = ACCESS_FULL;
return a;
}
superuser_username, superuser_password))
return access_full(a);
username = NULL;
}

if (access_noacl) {
a->aa_rights = ACCESS_FULL;
return a;
}
if (access_noacl)
return access_full(a);

TAILQ_FOREACH(ae, &access_entries, ae_link) {

Expand Down Expand Up @@ -684,25 +696,19 @@ access_get_hashed(const char *username, const uint8_t digest[20],
a->aa_username = strdup(username);
a->aa_representative = strdup(username);
if(!passwd_verify_digest2(username, digest, challenge,
superuser_username, superuser_password)) {
a->aa_rights = ACCESS_FULL;
return a;
}
superuser_username, superuser_password))
return access_full(a);
} else {
a->aa_representative = malloc(50);
tcp_get_str_from_ip((struct sockaddr*)src, a->aa_representative, 50);
if(!passwd_verify_digest2(username, digest, challenge,
superuser_username, superuser_password)) {
a->aa_rights = ACCESS_FULL;
return a;
}
superuser_username, superuser_password))
return access_full(a);
username = NULL;
}

if(access_noacl) {
a->aa_rights = ACCESS_FULL;
return a;
}
if(access_noacl)
return access_full(a);

TAILQ_FOREACH(ae, &access_entries, ae_link) {

Expand Down Expand Up @@ -750,10 +756,8 @@ access_get_by_username(const char *username)
a->aa_username = strdup(username);
a->aa_representative = strdup(username);

if(access_noacl) {
a->aa_rights = ACCESS_FULL;
return a;
}
if(access_noacl)
return access_full(a);

if (username[0] == '\0')
return a;
Expand Down Expand Up @@ -786,10 +790,8 @@ access_get_by_addr(struct sockaddr *src)
a->aa_representative = malloc(50);
tcp_get_str_from_ip(src, a->aa_representative, 50);

if(access_noacl) {
a->aa_rights = ACCESS_FULL;
return a;
}
if(access_noacl)
return access_full(a);

if (access_ip_blocked(src))
return a;
Expand Down Expand Up @@ -1356,6 +1358,18 @@ user_get_userlist ( void *obj, const char *lang )
return m;
}

static htsmsg_t *
uilevel_get_list ( void *o, const char *lang )
{
static const struct strtab tab[] = {
{ N_("Default"), UILEVEL_DEFAULT },
{ N_("Basic"), UILEVEL_BASIC },
{ N_("Advanced"), UILEVEL_ADVANCED },
{ N_("Expert"), UILEVEL_EXPERT },
};
return strtab2htsmsg(tab, 1, lang);
}

const idclass_t access_entry_class = {
.ic_class = "access",
.ic_caption = N_("Access"),
Expand Down Expand Up @@ -1393,6 +1407,14 @@ const idclass_t access_entry_class = {
.set = access_entry_class_prefix_set,
.get = access_entry_class_prefix_get,
},
{
.type = PT_INT,
.id = "uilevel",
.name = N_("User interface level"),
.off = offsetof(access_entry_t, ae_uilevel),
.list = uilevel_get_list,
.opts = PO_HIDDEN
},
{
.type = PT_STR,
.id = "lang",
Expand Down
2 changes: 2 additions & 0 deletions src/access.h
Expand Up @@ -98,6 +98,7 @@ typedef struct access_entry {

int ae_index;
int ae_enabled;
int ae_uilevel;

int ae_streaming;
int ae_adv_streaming;
Expand Down Expand Up @@ -149,6 +150,7 @@ typedef struct access {
uint32_t aa_conn_limit_dvr;
uint32_t aa_conn_streaming;
uint32_t aa_conn_dvr;
int aa_uilevel;
} access_t;

TAILQ_HEAD(access_ticket_queue, access_ticket);
Expand Down
19 changes: 19 additions & 0 deletions src/config.c
Expand Up @@ -1897,6 +1897,17 @@ config_class_dscp_list ( void *o, const char *lang )
return strtab2htsmsg(tab, 1, lang);
}

static htsmsg_t *
config_class_uilevel ( void *o, const char *lang )
{
static const struct strtab tab[] = {
{ N_("Basic"), UILEVEL_BASIC },
{ N_("Advanced"), UILEVEL_ADVANCED },
{ N_("Expert"), UILEVEL_EXPERT },
};
return strtab2htsmsg(tab, 1, lang);
}

const idclass_t config_class = {
.ic_snode = &config.idnode,
.ic_class = "config",
Expand Down Expand Up @@ -1955,6 +1966,14 @@ const idclass_t config_class = {
.off = offsetof(config_t, server_name),
.group = 1
},
{
.type = PT_INT,
.id = "uilevel",
.name = N_("User interface level"),
.off = offsetof(config_t, uilevel),
.list = config_class_uilevel,
.group = 1
},
{
.type = PT_U32,
.id = "cookie_expires",
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Expand Up @@ -30,6 +30,7 @@
typedef struct config {
idnode_t idnode;
uint32_t version;
int uilevel;
char *full_version;
char *server_name;
char *language;
Expand Down
8 changes: 8 additions & 0 deletions src/tvheadend.h
Expand Up @@ -134,6 +134,14 @@ typedef enum {
} th_commercial_advice_t;


/*
*
*/
#define UILEVEL_DEFAULT (-1)
#define UILEVEL_BASIC 0
#define UILEVEL_ADVANCED 1
#define UILEVEL_EXPERT 2

/*
* global timer
*/
Expand Down
9 changes: 9 additions & 0 deletions src/webui/comet.c
Expand Up @@ -150,9 +150,18 @@ comet_access_update(http_connection_t *hc, comet_mailbox_t *cmb)
const char *username = hc->hc_access ? (hc->hc_access->aa_username ?: "") : "";
int64_t bfree, btotal;
int dvr = !http_access_verify(hc, ACCESS_RECORDER);
const char *s;

htsmsg_add_str(m, "notificationClass", "accessUpdate");

switch (hc->hc_access->aa_uilevel) {
case UILEVEL_BASIC: s = "basic"; break;
case UILEVEL_ADVANCED: s = "advanced"; break;
case UILEVEL_EXPERT: s = "expert"; break;
default: s = NULL; break;
}
if (s)
htsmsg_add_str(m, "uilevel", s);
if (!access_noacl)
htsmsg_add_str(m, "username", username);
if (hc->hc_peer_ipstr)
Expand Down

0 comments on commit 257f19d

Please sign in to comment.