コード例 #1
0
ファイル: WebEvent.cs プロジェクト: smosgin/labofthings
        /// <summary>
        /// Raises the <see cref="WebEventReceived"/> event.
        /// </summary>
        /// <param name="responder">Contains request data sent by the the client and functionality to respond to the request.</param>
        /// <param name="method">The incoming http method. </param>
        /// <param name="path">The path of the requested resource.</param>
        internal virtual void OnWebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            if (onWebEventReceived == null) onWebEventReceived = new ReceivedWebEventHandler(OnWebEventReceived);

            if (_WebEventReceived == null || noHandlerSet)
            {
                responder.SendResponse();
            }
            else if (Program.CheckAndInvoke(_WebEventReceived, onWebEventReceived, path, method, responder))
            {
                _WebEventReceived(path, method, responder);
            }
        }
コード例 #2
0
 // secure reception of wifi credentials over wifi network - secured by receiving secret 
 void CredentialsWebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
 {
     if (responder.UrlParameters == null || !responder.UrlParameters.Contains("ssid") || !responder.UrlParameters.Contains("setupauthcode"))
     {
         responder.Respond("ERROR::Syntax: " + path + "?ssid=SSID&setupauthcode=SETUPAUTHCODE[&key=WIFIKEY]");
         return;
     }
     if (((string)responder.UrlParameters["setupauthcode"]) != SetupAuthCode)
     {
         responder.Respond("ERROR::Incorrect setupauthcode");
         return;
     }
     var ssid = responder.UrlParameters["ssid"] as string;
     if (ssid == null || ssid == "")
     {
         responder.Respond("ERROR::Invalid SSID");
         return;
     }
     var key = "";
     if (responder.UrlParameters.Contains("key"))
     {
         key = responder.UrlParameters["key"] as string;
     }
     Debug.Print("Received (via web event) credentials for network " + ssid);
     bool newcreds = ReceivedCredentials(ssid, key);
     if (newcreds)
     {
         responder.Respond("OK::Got new credentials");
         SaveData();
         Thread.Sleep(10);
         WebServer.StopLocalServer();
         currentAP = null;
         SetLed();
         SetScreen();
         wifi.Interface.Disconnect();
     }
     else
     {
         responder.Respond("OK::Already had those");
     }
 }