diff --git a/contrib/syscmds/0Reboot b/contrib/syscmds/0Reboot new file mode 100644 index 0000000..63140ae --- /dev/null +++ b/contrib/syscmds/0Reboot @@ -0,0 +1 @@ +sudo /sbin/reboot diff --git a/contrib/syscmds/1Shutdown b/contrib/syscmds/1Shutdown new file mode 100644 index 0000000..4f786ce --- /dev/null +++ b/contrib/syscmds/1Shutdown @@ -0,0 +1 @@ +sudo /sbin/halt diff --git a/src/mpd_client.c b/src/mpd_client.c index fd21990..02596b2 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -113,8 +113,8 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) { je = json_scanf(msg.p, msg.len, "{data: {cmd: %Q}}", &p_charbuf1); if (je == 1) { int_buf1 = list_get_value(&syscmds, p_charbuf1); - if (int_buf1 == 1) - n = mympd_syscmd(mpd.buf, p_charbuf1); + if (int_buf1 > -1) + n = mympd_syscmd(mpd.buf, p_charbuf1, int_buf1); free(p_charbuf1); } break; @@ -1223,14 +1223,14 @@ bool mympd_state_set(char *name, char *value) { return true; } -int mympd_syscmd(char *buffer, char *cmd) { +int mympd_syscmd(char *buffer, char *cmd, int order) { int len; char filename[400]; char *line; size_t n = 0; ssize_t read; - snprintf(filename, 400, "%s/syscmds/%s", config.etcdir, cmd); + snprintf(filename, 400, "%s/syscmds/%d%s", config.etcdir, order, cmd); FILE *fp = fopen(filename, "r"); if (fp == NULL) { len = snprintf(buffer, MAX_SIZE, "{\"type\": \"error\", \"data\": \"Can't execute cmd %s\"}", cmd); diff --git a/src/mpd_client.h b/src/mpd_client.h index 29bad98..b3f1119 100644 --- a/src/mpd_client.h +++ b/src/mpd_client.h @@ -211,7 +211,7 @@ void mympd_get_sticker(const char *uri, t_sticker *sticker); void mympd_jukebox(); bool mympd_state_get(char *name, char *value); bool mympd_state_set(char *name, char *value); -int mympd_syscmd(char *buffer, char *cmd); +int mympd_syscmd(char *buffer, char *cmd, int order); int mympd_smartpls_save(char *smartpltype, char *playlist, char *tag, char *searchstr, int maxentries, int timerange); int mympd_smartpls_put(char *buffer, char *playlist); int mympd_smartpls_update_all(); diff --git a/src/mympd.c b/src/mympd.c index 1489698..6cb019f 100644 --- a/src/mympd.c +++ b/src/mympd.c @@ -188,6 +188,8 @@ void read_syscmds() { DIR *dir; struct dirent *ent; char dirname[400]; + char *cmd; + long order; snprintf(dirname, 400, "%s/syscmds", config.etcdir); printf("Reading syscmds: %s\n", dirname); @@ -195,7 +197,9 @@ void read_syscmds() { while ((ent = readdir(dir)) != NULL) { if (strncmp(ent->d_name, ".", 1) == 0) continue; - list_push(&syscmds, ent->d_name, 1); + order = strtol(ent->d_name, &cmd, 10); + if (strcmp(cmd, "") != 0) + list_push(&syscmds, strdup(cmd), order); } closedir(dir); } @@ -398,6 +402,7 @@ int main(int argc, char **argv) { list_init(&syscmds); read_syscmds(); + list_order(&syscmds, true); list_init(&mpd_tags); list_init(&mympd_tags);