X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Ffastcgi.c;h=75863c1fb04b2f4449b427a096f2ffb1fd8d88b5;hb=edb6df04611c10dca29799a1e08096bd4ca28303;hp=f68bc4fe2ba1f56713230f3e118e9f190b410350;hpb=8c5bba9863ed029b83766d8b4de1195aa38b1f5d;p=matches%2FMCTX3420.git diff --git a/server/fastcgi.c b/server/fastcgi.c index f68bc4f..75863c1 100644 --- a/server/fastcgi.c +++ b/server/fastcgi.c @@ -46,8 +46,7 @@ static void IdentifyHandler(FCGIContext *context, char *params) FCGI_BeginJSON(context, STATUS_OK); FCGI_JSONPair("description", "MCTX3420 Server API (2013)"); FCGI_JSONPair("build_date", __DATE__ " " __TIME__); - struct timespec t; - t.tv_sec = 0; t.tv_nsec = 0; + struct timespec t = {0}; clock_getres(CLOCK_MONOTONIC, &t); FCGI_JSONDouble("clock_getres", TIMEVAL_TO_DOUBLE(t)); FCGI_JSONLong("api_version", API_VERSION); @@ -65,7 +64,9 @@ static void IdentifyHandler(FCGIContext *context, char *params) if (i > 0) { FCGI_JSONValue(",\n\t\t"); } - FCGI_JSONValue("\"%d\" : \"%s\"", i, Sensor_GetName(i)); + DataPoint d = Sensor_LastData(i); + FCGI_JSONValue("\"%d\" : {\"name\" : \"%s\", \"value\" : [%f,%f] }", + i, Sensor_GetName(i), d.time_stamp, d.value); } FCGI_JSONValue("\n\t}"); } @@ -76,7 +77,9 @@ static void IdentifyHandler(FCGIContext *context, char *params) if (i > 0) { FCGI_JSONValue(",\n\t\t"); } - FCGI_JSONValue("\"%d\" : \"%s\"", i, Actuator_GetName(i)); + + DataPoint d = Sensor_LastData(i); + FCGI_JSONValue("\"%d\" : {\"name\" : \"%s\", \"value\" : [%f, %f] }", i, Actuator_GetName(i), d.time_stamp, d.value); } FCGI_JSONValue("\n\t}"); } @@ -197,18 +200,17 @@ void FCGI_GetControlCookie(char buffer[CONTROL_KEY_BUFSIZ]) const char *cookies = getenv("COOKIE_STRING"); const char *start = strstr(cookies, "mctxkey="); + *buffer = 0; //Clear the buffer if (start != NULL) { - const char *end; - size_t limit = CONTROL_KEY_BUFSIZ; - start += 8; //Ah, magic numbers (the length of mctxkey= - 1) - end = strchr(start, ';'); - if (end != NULL && (end-start) < CONTROL_KEY_BUFSIZ) { - limit = (end-start) + 1; + int i; + start += 8; //length of mctxkey= + for (i = 0; i < CONTROL_KEY_BUFSIZ; i++) { + if (*start == 0 || *start == ';') { + break; + } + buffer[i] = *start++; } - snprintf(buffer, limit, "%s", start); - Log(LOGDEBUG, "buf: %s", buffer); - } else { - *buffer = 0; + buffer[i] = 0; } } @@ -597,8 +599,17 @@ void * FCGI_RequestLoop (void *data) { if (!FCGI_HasControl(&context)) { - FCGI_RejectJSON(&context, "Please login. Invalid control key."); - continue; + if (g_options.auth_method == AUTH_NONE) + { //:( + Log(LOGWARN, "Locking control (no auth!)"); + FCGI_LockControl(&context, NOAUTH_USERNAME, USER_ADMIN); + FCGI_SendControlCookie(&context, true); + } + else + { + FCGI_RejectJSON(&context, "Please login. Invalid control key."); + continue; + } } //Escape all special characters.