+ desired_mode = CONTROL_START;
+ } else if (!strcmp(action, "pause")) {
+ desired_mode = CONTROL_PAUSE;
+ } else if (!strcmp(action, "resume")) {
+ desired_mode = CONTROL_RESUME;
+ } else if (!strcmp(action, "stop")) {
+ desired_mode = CONTROL_STOP;
+ } else {
+ FCGI_RejectJSON(context, "Unknown action specified.");
+ return;
+ }
+
+ if (*g_controls.user_name != '\0' && strcmp(g_controls.user_name,context->user_name) != 0)
+ {
+ if (context->user_type != USER_ADMIN)
+ {
+ FCGI_RejectJSON(context, "Another user has an experiment in progress.");
+ return;
+ }
+
+ if (!force)
+ {
+ Log(LOGERR, "User %s is currently running an experiment!", g_controls.user_name);
+ FCGI_RejectJSON(context, "Pass \"force\" to take control over another user's experiment");
+ return;
+ }
+ }
+
+
+
+ //HACK
+ chdir(context->user_name);
+
+ void *arg = NULL;
+ if (desired_mode == CONTROL_START) {
+ if (PathExists(name) && !force) {
+ FCGI_RejectJSON(context, "An experiment with that name already exists.");
+ chdir(g_options.root_dir); // REVERSE HACK
+ return;
+ }
+ char * c = (char*)name;
+ for (c = (char*)name; *c != '\0' && *c != '.'; ++c);
+ if (*c == '.')
+ {
+ FCGI_RejectJSON(context, "Can't include '.' characters in experiment names (at this point we don't care anymore, go find someone who does).");
+ chdir(g_options.root_dir); // REVERSE HACK
+ return;
+ }
+ arg = (void*)name;
+ }
+
+
+
+ const char *ret;
+ if ((ret = Control_SetMode(desired_mode, arg)) != NULL)
+ {
+ FCGI_RejectJSON(context, ret);
+ }
+ else
+ {
+ if (desired_mode == CONTROL_STOP)
+ g_controls.user_name[0] = '\0';
+ else
+ {
+ snprintf(g_controls.user_name, sizeof(g_controls.user_name), context->user_name);
+ }