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:
SuperBFG7 2018-03-25 13:45:16 +02:00
parent 5e834e56ff
commit 26b2ca3408
5 changed files with 18 additions and 8 deletions

View File

@ -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()
{

View File

@ -5,3 +5,4 @@ WEB_PORT=8080
YMPD_USER=nobody
DIRBLE_API_TOKEN=2e223c9909593b94fc6577361a
#DIGEST=--digest /path/to/htdigest
#LOCALPORT=8080

View File

@ -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]

View File

@ -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;

View File

@ -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 <host>\t\tconnect to mpd at host [localhost]\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"
" -u, --user <username>\t\tdrop priviliges to user after socket bind\n"
" -d, --dirbletoken <apitoken>\tDirble API token\n"