mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-15 16:48:22 -04:00
[httpd] Expose function for authenticating admin requests
This commit is contained in:
parent
1d49413070
commit
9275f7a938
60
src/httpd.c
60
src/httpd.c
@ -930,12 +930,44 @@ redirect_to_index(struct evhttp_request *req, char *uri)
|
|||||||
httpd_send_reply(req, HTTP_MOVETEMP, "Moved", NULL, HTTPD_SEND_NO_GZIP);
|
httpd_send_reply(req, HTTP_MOVETEMP, "Moved", NULL, HTTPD_SEND_NO_GZIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
httpd_admin_check_auth(struct evhttp_request *req)
|
||||||
|
{
|
||||||
|
const char *host;
|
||||||
|
const char *passwd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
passwd = cfg_getstr(cfg_getsec(cfg, "general"), "admin_password");
|
||||||
|
if (passwd)
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_HTTPD, "Checking web interface authentication\n");
|
||||||
|
|
||||||
|
ret = httpd_basic_auth(req, "admin", passwd, PACKAGE " web interface");
|
||||||
|
if (ret != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DPRINTF(E_DBG, L_HTTPD, "Authentication successful\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
host = evhttp_request_get_host(req);
|
||||||
|
if ((strcmp(host, "::1") != 0)
|
||||||
|
&& (strcmp(host, "127.0.0.1") != 0))
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_HTTPD, "Remote web interface request denied; no password set\n");
|
||||||
|
|
||||||
|
httpd_send_error(req, 403, "Forbidden");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Thread: httpd */
|
/* Thread: httpd */
|
||||||
static void
|
static void
|
||||||
serve_file(struct evhttp_request *req, char *uri)
|
serve_file(struct evhttp_request *req, char *uri)
|
||||||
{
|
{
|
||||||
const char *host;
|
|
||||||
const char *passwd;
|
|
||||||
char *ext;
|
char *ext;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char *deref;
|
char *deref;
|
||||||
@ -949,28 +981,10 @@ serve_file(struct evhttp_request *req, char *uri)
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check authentication */
|
/* Check authentication */
|
||||||
passwd = cfg_getstr(cfg_getsec(cfg, "general"), "admin_password");
|
if (!httpd_admin_check_auth(req))
|
||||||
if (passwd)
|
|
||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_HTTPD, "Checking web interface authentication\n");
|
DPRINTF(E_DBG, L_HTTPD, "Remote web interface request denied;\n");
|
||||||
|
return;
|
||||||
ret = httpd_basic_auth(req, "admin", passwd, PACKAGE " web interface");
|
|
||||||
if (ret != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DPRINTF(E_DBG, L_HTTPD, "Authentication successful\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
host = evhttp_request_get_host(req);
|
|
||||||
if ((strcmp(host, "::1") != 0)
|
|
||||||
&& (strcmp(host, "127.0.0.1") != 0))
|
|
||||||
{
|
|
||||||
DPRINTF(E_LOG, L_HTTPD, "Remote web interface request denied; no password set\n");
|
|
||||||
|
|
||||||
httpd_send_error(req, 403, "Forbidden");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(uri, "/oauth", strlen("/oauth")) == 0)
|
if (strncmp(uri, "/oauth", strlen("/oauth")) == 0)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <event2/http.h>
|
#include <event2/http.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
enum httpd_send_flags
|
enum httpd_send_flags
|
||||||
{
|
{
|
||||||
@ -58,6 +59,9 @@ httpd_fixup_uri(struct evhttp_request *req);
|
|||||||
int
|
int
|
||||||
httpd_basic_auth(struct evhttp_request *req, const char *user, const char *passwd, const char *realm);
|
httpd_basic_auth(struct evhttp_request *req, const char *user, const char *passwd, const char *realm);
|
||||||
|
|
||||||
|
bool
|
||||||
|
httpd_admin_check_auth(struct evhttp_request *req);
|
||||||
|
|
||||||
int
|
int
|
||||||
httpd_init(void);
|
httpd_init(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user