diff --git a/contrib/init.debian b/contrib/init.debian index 012adf1..6b328f0 100755 --- a/contrib/init.debian +++ b/contrib/init.debian @@ -26,6 +26,7 @@ MPD_PORT=6600 WEB_PORT=8080 DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a #DIGEST=--digest /path/to/htdigest +#LOCALPORT=8080 # Exit if the package is not installed @@ -37,7 +38,7 @@ DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a # Load the VERBOSE setting and other rcS variables [ -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() { diff --git a/contrib/ympd.default b/contrib/ympd.default index 27e9ebb..6496a11 100644 --- a/contrib/ympd.default +++ b/contrib/ympd.default @@ -5,3 +5,4 @@ WEB_PORT=8080 YMPD_USER=nobody DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a #DIGEST=--digest /path/to/htdigest +#LOCALPORT=8080 diff --git a/contrib/ympd.service b/contrib/ympd.service index f450b97..43a9e1a 100644 --- a/contrib/ympd.service +++ b/contrib/ympd.service @@ -10,8 +10,9 @@ Environment=WEB_PORT=8080 Environment=YMPD_USER=nobody Environment=DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a Environment=DIGEST= +Environment=LOCALPORT= 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 [Install] diff --git a/src/mpd_client.h b/src/mpd_client.h index 447dd56..7598aa4 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -84,8 +84,10 @@ enum mpd_conn_states { struct t_mpd { int port; + int local_port; char host[128]; char *password; + char *gpass; struct mpd_connection *conn; enum mpd_conn_states conn_state; diff --git a/src/ympd.c b/src/ympd.c index 53f59bc..81e28b0 100644 --- a/src/ympd.c +++ b/src/ympd.c @@ -38,8 +38,6 @@ void bye() force_exit = 1; } -char *gpass = NULL; - static int server_callback(struct mg_connection *c, enum mg_event ev) { int result = MG_FALSE; FILE *fp = NULL; @@ -63,10 +61,10 @@ static int server_callback(struct mg_connection *c, enum mg_event ev) { #endif case MG_AUTH: // 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; else { - if ( (fp = fopen(gpass, "r")) != NULL ) { + if ( (fp = fopen(mpd.gpass, "r")) != NULL ) { result = mg_authorize_digest(c, fp); fclose(fp); } @@ -93,6 +91,8 @@ int main(int argc, char **argv) mg_set_option(server, "auth_domain", "ympd"); mpd.port = 6600; + mpd.local_port = 0; + mpd.gpass = NULL; strcpy(mpd.host, "127.0.0.1"); strcpy(dirble_api_token, "2e223c9909593b94fc6577361a"); @@ -101,6 +101,7 @@ int main(int argc, char **argv) {"digest", required_argument, 0, 'D'}, {"host", required_argument, 0, 'h'}, {"port", required_argument, 0, 'p'}, + {"localport", required_argument, 0, 'l'}, {"webport", required_argument, 0, 'w'}, {"dirbletoken", required_argument, 0, 'd'}, {"user", required_argument, 0, 'u'}, @@ -110,11 +111,11 @@ int main(int argc, char **argv) {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) { switch (n) { case 'D': - gpass = strdup(optarg); + mpd.gpass = strdup(optarg); break; case 'h': strncpy(mpd.host, optarg, sizeof(mpd.host)); @@ -122,6 +123,9 @@ int main(int argc, char **argv) case 'p': mpd.port = atoi(optarg); break; + case 'l': + mpd.local_port = atoi(optarg); + break; case 'w': webport = strdup(optarg); break; @@ -148,6 +152,7 @@ int main(int argc, char **argv) " \t(realm ympd) [no authorization]\n" " -h, --host \t\tconnect to mpd at host [localhost]\n" " -p, --port \t\tconnect to mpd at port [6600]\n" + " -l, --localport \t\tskip authorization for local port\n" " -w, --webport [ip:]\tlisten interface/port for webserver [8080]\n" " -u, --user \t\tdrop priviliges to user after socket bind\n" " -d, --dirbletoken \tDirble API token\n"