mirror of
https://github.com/SuperBFG7/ympd
synced 2024-11-23 13:27:18 +00:00
add option "localport" to exclude ports from auth
usefull if ympd listens on two ports: one (local) for intranet usage and one for internet usage
This commit is contained in:
parent
5e834e56ff
commit
26b2ca3408
@ -26,6 +26,7 @@ MPD_PORT=6600
|
|||||||
WEB_PORT=8080
|
WEB_PORT=8080
|
||||||
DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
||||||
#DIGEST=--digest /path/to/htdigest
|
#DIGEST=--digest /path/to/htdigest
|
||||||
|
#LOCALPORT=8080
|
||||||
|
|
||||||
|
|
||||||
# Exit if the package is not installed
|
# Exit if the package is not installed
|
||||||
@ -37,7 +38,7 @@ DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
|||||||
# Load the VERBOSE setting and other rcS variables
|
# Load the VERBOSE setting and other rcS variables
|
||||||
[ -f /etc/default/rcS ] && . /etc/default/rcS
|
[ -f /etc/default/rcS ] && . /etc/default/rcS
|
||||||
|
|
||||||
DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST"
|
DAEMON_OPT="--user $YMPD_USER --mpdpass '$MPD_PASSWORD' --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST $LOCALPORT"
|
||||||
|
|
||||||
do_start()
|
do_start()
|
||||||
{
|
{
|
||||||
|
@ -5,3 +5,4 @@ WEB_PORT=8080
|
|||||||
YMPD_USER=nobody
|
YMPD_USER=nobody
|
||||||
DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
||||||
#DIGEST=--digest /path/to/htdigest
|
#DIGEST=--digest /path/to/htdigest
|
||||||
|
#LOCALPORT=8080
|
||||||
|
@ -10,8 +10,9 @@ Environment=WEB_PORT=8080
|
|||||||
Environment=YMPD_USER=nobody
|
Environment=YMPD_USER=nobody
|
||||||
Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
|
||||||
Environment=DIGEST=
|
Environment=DIGEST=
|
||||||
|
Environment=LOCALPORT=
|
||||||
EnvironmentFile=/etc/default/ympd
|
EnvironmentFile=/etc/default/ympd
|
||||||
ExecStart=/usr/bin/ympd --user $YMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST
|
ExecStart=/usr/bin/ympd --user $YMPD_USER --webport $WEB_PORT --host $MPD_HOST --port $MPD_PORT --dirbletoken $DIRBLE_API_TOKEN $DIGEST $LOCALPORT
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
@ -84,8 +84,10 @@ enum mpd_conn_states {
|
|||||||
|
|
||||||
struct t_mpd {
|
struct t_mpd {
|
||||||
int port;
|
int port;
|
||||||
|
int local_port;
|
||||||
char host[128];
|
char host[128];
|
||||||
char *password;
|
char *password;
|
||||||
|
char *gpass;
|
||||||
|
|
||||||
struct mpd_connection *conn;
|
struct mpd_connection *conn;
|
||||||
enum mpd_conn_states conn_state;
|
enum mpd_conn_states conn_state;
|
||||||
|
17
src/ympd.c
17
src/ympd.c
@ -38,8 +38,6 @@ void bye()
|
|||||||
force_exit = 1;
|
force_exit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *gpass = NULL;
|
|
||||||
|
|
||||||
static int server_callback(struct mg_connection *c, enum mg_event ev) {
|
static int server_callback(struct mg_connection *c, enum mg_event ev) {
|
||||||
int result = MG_FALSE;
|
int result = MG_FALSE;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
@ -63,10 +61,10 @@ static int server_callback(struct mg_connection *c, enum mg_event ev) {
|
|||||||
#endif
|
#endif
|
||||||
case MG_AUTH:
|
case MG_AUTH:
|
||||||
// no auth for websockets since mobile safari does not support it
|
// no auth for websockets since mobile safari does not support it
|
||||||
if ( (gpass == NULL) || (c->is_websocket) )
|
if ( (mpd.gpass == NULL) || (c->is_websocket) || ((mpd.local_port > 0) && (c->local_port == mpd.local_port)) )
|
||||||
return MG_TRUE;
|
return MG_TRUE;
|
||||||
else {
|
else {
|
||||||
if ( (fp = fopen(gpass, "r")) != NULL ) {
|
if ( (fp = fopen(mpd.gpass, "r")) != NULL ) {
|
||||||
result = mg_authorize_digest(c, fp);
|
result = mg_authorize_digest(c, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
@ -93,6 +91,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
mg_set_option(server, "auth_domain", "ympd");
|
mg_set_option(server, "auth_domain", "ympd");
|
||||||
mpd.port = 6600;
|
mpd.port = 6600;
|
||||||
|
mpd.local_port = 0;
|
||||||
|
mpd.gpass = NULL;
|
||||||
strcpy(mpd.host, "127.0.0.1");
|
strcpy(mpd.host, "127.0.0.1");
|
||||||
|
|
||||||
strcpy(dirble_api_token, "2e223c9909593b94fc6577361a");
|
strcpy(dirble_api_token, "2e223c9909593b94fc6577361a");
|
||||||
@ -101,6 +101,7 @@ int main(int argc, char **argv)
|
|||||||
{"digest", required_argument, 0, 'D'},
|
{"digest", required_argument, 0, 'D'},
|
||||||
{"host", required_argument, 0, 'h'},
|
{"host", required_argument, 0, 'h'},
|
||||||
{"port", required_argument, 0, 'p'},
|
{"port", required_argument, 0, 'p'},
|
||||||
|
{"localport", required_argument, 0, 'l'},
|
||||||
{"webport", required_argument, 0, 'w'},
|
{"webport", required_argument, 0, 'w'},
|
||||||
{"dirbletoken", required_argument, 0, 'd'},
|
{"dirbletoken", required_argument, 0, 'd'},
|
||||||
{"user", required_argument, 0, 'u'},
|
{"user", required_argument, 0, 'u'},
|
||||||
@ -110,11 +111,11 @@ int main(int argc, char **argv)
|
|||||||
{0, 0, 0, 0 }
|
{0, 0, 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
while((n = getopt_long(argc, argv, "D:h:p:w:u:d:v:m",
|
while((n = getopt_long(argc, argv, "D:h:p:l:w:u:d:v:m",
|
||||||
long_options, &option_index)) != -1) {
|
long_options, &option_index)) != -1) {
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 'D':
|
case 'D':
|
||||||
gpass = strdup(optarg);
|
mpd.gpass = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
strncpy(mpd.host, optarg, sizeof(mpd.host));
|
strncpy(mpd.host, optarg, sizeof(mpd.host));
|
||||||
@ -122,6 +123,9 @@ int main(int argc, char **argv)
|
|||||||
case 'p':
|
case 'p':
|
||||||
mpd.port = atoi(optarg);
|
mpd.port = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'l':
|
||||||
|
mpd.local_port = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
webport = strdup(optarg);
|
webport = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
@ -148,6 +152,7 @@ int main(int argc, char **argv)
|
|||||||
" \t(realm ympd) [no authorization]\n"
|
" \t(realm ympd) [no authorization]\n"
|
||||||
" -h, --host <host>\t\tconnect to mpd at host [localhost]\n"
|
" -h, --host <host>\t\tconnect to mpd at host [localhost]\n"
|
||||||
" -p, --port <port>\t\tconnect to mpd at port [6600]\n"
|
" -p, --port <port>\t\tconnect to mpd at port [6600]\n"
|
||||||
|
" -l, --localport <port>\t\tskip authorization for local port\n"
|
||||||
" -w, --webport [ip:]<port>\tlisten interface/port for webserver [8080]\n"
|
" -w, --webport [ip:]<port>\tlisten interface/port for webserver [8080]\n"
|
||||||
" -u, --user <username>\t\tdrop priviliges to user after socket bind\n"
|
" -u, --user <username>\t\tdrop priviliges to user after socket bind\n"
|
||||||
" -d, --dirbletoken <apitoken>\tDirble API token\n"
|
" -d, --dirbletoken <apitoken>\tDirble API token\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user