Beispiel #1
0
/* ================================================================== *
 * Function: web_input
 * Description: Static callback function to handle input to the server
 * Parameters: See Webduino documentation
 *             obj is a pointer to the instance of Server that added the callback
 * ================================================================== */
void web_input(WebServer &server, WebServer::ConnectionType type, char * c, bool b, void * obj) {
    if (type == WebServer::POST) {
        Server * s = (Server *) obj;
        bool repeat;
        char name[16], value[16];
        do {
            // Read all POST params, returns false when no more params
            repeat = server.readPOSTparam(name, 16, value, 16);

            if (strcmp(name, "visualizer") == 0) {
                int type = strtol(value, NULL, 10);
                // Ensure type is valid, default to VISUALIZER_BARS
                switch (type) {
                    case VISUALIZER_BARS:
                    case VISUALIZER_BARS_MIDDLE:
                    case VISUALIZER_PULSE:
                    case VISUALIZER_PLASMA:
                    case VISUALIZER_RAINBOW:
                    case VISUALIZER_WHEEL:
                        s->set_visualizer(type); break;
                    default:
                        s->set_visualizer(VISUALIZER_BARS); break;
                }
            } else if (strcmp(name, "other") == 0) {
                int type = strtol(value, NULL, 10);
                // Ensure type is valid, default to BOUNCING_LINES
                switch (type) {
                    case BOUNCING_LINES:
                    case BAR_TEST:
                    case PIXEL_TEST:
                    case AMBIENT_LIGHTING:
                        s->set_visualizer(type); break;
                    default:
                        s->set_visualizer(BOUNCING_LINES); break;
                }
            } else if (strcmp(name, "power") == 0) {
                s->set_power(strtol(value, NULL, 10));
            }
        } while (repeat);
            // after procesing the POST data, tell the web browser to reload
            // the page using a GET method.
            server.httpSeeOther("/web_input");
            return;
        }

        /* for a GET or HEAD, send the standard "it's all OK headers" */
        server.httpSuccess();

        /* we don't output the body for a HEAD request */
        if (type == WebServer::GET) {
            server.printP(control_panel);
        }
}
bool IsValidLogin(WebServer &rServer)
{
  const int nMaxParameterBuffer = 20;
  char achName[nMaxParameterBuffer];
  char achValue[nMaxParameterBuffer];

  // Check if there is a recent password & we are still within grace period. 
  if (PasswordManager.HasValidPassword())
    return true;

  // Work through all the parameters supplied until we find the one with the
  // password in it. Then check to see if the password is valid. 
  while (rServer.readPOSTparam(achName, sizeof(achName), achValue, sizeof(achValue)))
    if (strcmp(achName, "message") == 0) // we have the password parameter. 
      return PasswordManager.IsPasswordValid(achValue, false);

  return false; // didn't find the password parameter. 
}