Exemplo n.º 1
0
                public void getChallenge()
                {
                    //update challenge and return if we are loggin or not

                    string JsonResponse = HTTP_Request.HTTP_GET("/api/v3/login", null);

                    requests.response response = JsonConvert.DeserializeObject <requests.response>(JsonResponse);
                    if (response.success == "true")
                    {
                        challenge = response.result.challenge;
                        System.Diagnostics.Debug.WriteLine("Challenge : " + challenge);
                        if (response.result.logged_in == "true")
                        {
                            loggedIn = true;
                            Console.WriteLine("You are now logged in");
                        }
                        else if (response.result.logged_in == "false")
                        {
                            loggedIn = false;
                        }
                        else
                        {
                            throw new LoginFailedException("an error append in getting the loggin");
                        }
                    }
                    else
                    {
                        throw new LoginFailedException();
                    }
                }
Exemplo n.º 2
0
                public requests.configuration.lan_browser.LanHostObject getListLanHostObject()
                {
                    string JsonResponse = HTTP_Request.HTTP_GET("/api/v3/lan/browser/pub", null);

                    requests.configuration.lan_browser.LanHostObject response = JsonConvert.DeserializeObject <requests.configuration.lan_browser.LanHostObject>(JsonResponse);
                    if (response.success == "true")
                    {
                        return(response);
                    }
                    return(null);
                }
Exemplo n.º 3
0
                public requests.configuration.lan_browser.LanInterfaces getLanInterfaces()
                {
                    string JsonResponse = HTTP_Request.HTTP_GET("/api/v3/lan/browser/interfaces", null);

                    requests.configuration.lan_browser.LanInterfaces response = JsonConvert.DeserializeObject <requests.configuration.lan_browser.LanInterfaces>(JsonResponse);

                    if (response.success == "true")
                    {
                        return(response);
                    }
                    return(null);
                }
Exemplo n.º 4
0
            public bool getWifiInfo()
            {
                string JsonResponse = HTTP_Request.HTTP_GET("/api/v2/wifi/config/", null);

                requests.response response = JsonConvert.DeserializeObject <requests.response>(JsonResponse);
                if (response.success == "true")
                {
                    if (response.result.enabled == "true")
                    {
                        return(true);
                    }
                }
                return(false);
            }
Exemplo n.º 5
0
            public bool setWifi(bool enabled)
            {
                requests.wifi.globalConfig.wifi authorisationRequest = new requests.wifi.globalConfig.wifi();
                authorisationRequest.enabled = enabled;

                //serializing
                string content      = JsonConvert.SerializeObject(authorisationRequest);
                string JsonResponse = HTTP_Request.HTTP_PUT("/api/v2/wifi/config/", content);

                Console.WriteLine(JsonResponse);
                requests.response response = JsonConvert.DeserializeObject <requests.response>(JsonResponse);
                if (response.success == "true")
                {
                    if (response.result.enabled == "true")
                    {
                        return(true);
                    }
                }
                return(false);
            }
Exemplo n.º 6
0
                public bool getSessionToken()
                {
                    if (app_token == null || app_token == "")
                    {
                        throw new TokenNull();
                    }
                    if (challenge == "" || challenge == null)
                    {
                        getChallenge();
                    }
                    //password
                    string password = Crypt.Encode(challenge, app_token);

                    //string password = Encode(app_token, challenge);
                    requests.login.session.Request sessionRequest = new requests.login.session.Request();
                    sessionRequest.app_id   = app_id;
                    sessionRequest.password = password;


                    // json conversion
                    string sessReq = JsonConvert.SerializeObject(sessionRequest);
                    // post request
                    string JsonResponse = HTTP_Request.HTTP_POST("/api/v3/login/session/", sessReq);

                    requests.response response = JsonConvert.DeserializeObject <requests.response>(JsonResponse);
                    if (response.success == "true")
                    {
                        session_token = response.result.session_token;
                        challenge     = response.result.challenge;
                        requests.permission appPermissions = response.result.permissions;
                        HTTP_Request.Fbx_Header = session_token;
                        getChallenge();
                        return(true);
                    }
                    throw new LoginFailedException();
                }
Exemplo n.º 7
0
        public static void setWifiOff()
        {
            HTTP_Request.setHost(host);

            Console.WriteLine("Starting...");
            //preparing login
            if (freeboxController.Authentification.exist() == false)
            {
                freeboxController.Authentification.registerApp("freebox controller", "fr.freebox.controller", appVersion);
                Console.WriteLine("Please change settings");
                Console.ReadLine();
            }
            else
            {
                freeboxController.Authentification.loginAuto();
                Console.WriteLine("Logged in");
            }
            freeboxController.Authentification.saveSettings();

            // set wifi on
            //Console.WriteLine("Wifi enabled : " + freeboxController.Wifi.setWifi(true));

            // lan browser

            /*
             * requests.configuration.lan_browser.LanInterfaces interfaces = freeboxController.Configuration.Lan_Browser.getLanInterfaces();
             * foreach (requests.configuration.lan_browser.LanInterfaces.Result te in interfaces.result)
             * {
             *  Console.WriteLine("lan interface : " + te.name + " host_count : " + te.host_count);
             * }
             * Console.WriteLine();
             *
             * requests.configuration.lan_browser.LanHostObject objects = freeboxController.Configuration.Lan_Browser.getListLanHostObject();
             * foreach (requests.configuration.lan_browser.LanHostObject.Result te in objects.result)
             * {
             *  Console.WriteLine("Device : " + te.primary_name);
             *  Console.WriteLine("ID : " + te.l2ident.id + " type : " + te.l2ident.type);
             *  Console.WriteLine("last_activity : " + te.last_activity + " last_time_reachable : " + te.last_time_reachable);
             *  Console.WriteLine("reachable : " + te.reachable);
             *  Console.WriteLine("active : " + te.active);
             *  Console.WriteLine("persistent : " + te.persistent);
             *  if (te.l3connectivies != null)
             *  {
             *      foreach (requests.configuration.lan_browser.LanHostObject.Result.L3connectivities test in te.l3connectivies)
             *      {
             *          Console.WriteLine("addr : " + test.addr + " af : " + test.af);
             *      }
             *  }
             *  else
             *  {
             *      Console.WriteLine("l3connectivities :  null");
             *  }*/
            bool enabled = true;

            while (true)
            {
                enabled = freeboxController.Wifi.getWifiInfo();
                if (enabled == true)
                {
                    Console.WriteLine("It is on !!! " + DateTime.Now.ToString());
                    enabled = freeboxController.Wifi.setWifi(false);
                    Console.WriteLine(" Now : " + enabled + Environment.NewLine);
                }
            }
        }
Exemplo n.º 8
0
                }                                      // device name like : "computer of henri"

                public bool authorizeApp()
                {
                    // filling the data in order to send them
                    requests.authorisation authorisationRequest = new requests.authorisation();
                    authorisationRequest.app_id      = app_id;
                    authorisationRequest.app_name    = app_name;
                    authorisationRequest.app_version = version;
                    authorisationRequest.device_name = deviceName;

                    //serializing
                    string authReq = JsonConvert.SerializeObject(authorisationRequest);

                    string authorisation = HTTP_Request.HTTP_POST("/api/v3/login/authorize", authReq);

                    requests.response response = JsonConvert.DeserializeObject <requests.response>(authorisation);
                    if (response.success == "true")
                    {
                        //printing advertissement
                        Console.WriteLine("Accept the binding request on the screen of your freebox revolution");

                        app_token = response.result.app_token;
                        track_id  = response.result.track_id;

                        //tracking pending ...
                        bool requestEnded = false;
                        bool printPending = false;
                        int  pendingState = 0;

                        while (requestEnded == false)
                        {
                            authorisation = HTTP_Request.HTTP_GET("/api/v3/login/authorize/" + track_id, null);
                            response      = JsonConvert.DeserializeObject <requests.response>(authorisation);
                            if (response.success == "true")
                            {
                                string status = response.result.status;
                                //if we must return to the line
                                if (status != "pending" && printPending)
                                {
                                    Console.WriteLine("");
                                }
                                //checking the status
                                if (status == "unknow")
                                {
                                    Console.WriteLine("Status unknow");
                                    return(false);
                                }
                                else if (status == "pending")
                                {
                                    string add = "";

                                    if (printPending)
                                    {
                                        // determining add :
                                        switch (pendingState)
                                        {
                                        case 0:
                                            add = "|";
                                            break;

                                        case 1:
                                            add = "/";
                                            break;

                                        case 2:
                                            add = "-";
                                            break;

                                        case 3:
                                            add = "\\";
                                            break;

                                        case 4:
                                            add = "|";
                                            break;

                                        case 5:
                                            add = "/";
                                            break;

                                        case 6:
                                            add = "-";
                                            break;

                                        case 7:
                                            add          = "\\";
                                            pendingState = -1;
                                            break;

                                        default:
                                            add          = "|";
                                            pendingState = -1;
                                            break;
                                        }
                                        pendingState++;
                                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                                        Console.Write(add);
                                    }
                                    else
                                    {
                                        Console.Write("Pending... ");
                                        printPending = true;
                                    }
                                }
                                else if (status == "timeout")
                                {
                                    Console.WriteLine("request timeout");
                                    return(false);
                                }
                                else if (status == "granted")
                                {
                                    requestEnded = true;
                                    Console.WriteLine("request ok");
                                    return(true);
                                }
                                else if (status == "denied")
                                {
                                    Console.WriteLine("request denied");
                                    return(false);
                                }
                                else
                                {
                                    Console.WriteLine("unknow request response : " + status);
                                    return(false);
                                }
                            }
                        }
                    }
                    return(false);
                }