Exemplo n.º 1
0
 private void ItmAuthenticateRevoke_Click(object sender, EventArgs e)
 {
     try
     {
         //test authentication
         var testLogin = ArcLogin.TestLogin();
         if (!testLogin)
         {
             UiMessages.Warning(@"Revocation failed: login not yet initiated");
         }
         else if (Global.InitToken != null)
         {
             var logoutSuccess = Global.InitToken.Revoke();
             if (logoutSuccess)
             {
                 UpdateUIAuthenticate();
                 Global.InitToken = null;
                 UiMessages.Info(@"Successfully logged user out");
             }
             else
             {
                 UiMessages.Warning(@"Revocation failed: logout was unsuccessful");
             }
         }
         else
         {
             UiMessages.Warning(@"Revocation failed: login data not yet initiated");
         }
     }
     catch (Exception ex)
     {
         UiMessages.Error(ex.ToString());
     }
 }
Exemplo n.º 2
0
        private void DoTextSearch(SearchContext cxt)
        {
            var startIndex = 0;
            var foundMatch = false;

            while (startIndex < txtMain.TextLength)
            {
                var wordStartIndex = txtMain.Find(cxt.SearchTerm, startIndex, RichTextBoxFinds.None);
                if (wordStartIndex > -1)
                {
                    foundMatch = true;

                    txtMain.SelectionStart     = wordStartIndex;
                    txtMain.SelectionLength    = cxt.SearchTerm.Length;
                    txtMain.SelectionBackColor = Color.Yellow;
                }
                else
                {
                    break;
                }

                startIndex += wordStartIndex + cxt.SearchTerm.Length;
            }

            if (!foundMatch)
            {
                UiMessages.Warning($"Nothing found for '{cxt.SearchTerm}'", @"No Results");
                CancelSearch();
            }
            else
            {
                itmSearch.Text = @"Cancel Search";
            }
        }
Exemplo n.º 3
0
 private void ItmAuthenticateGrant_Click(object sender, EventArgs e)
 {
     try
     {
         //test authentication
         var testLogin = ArcLogin.TestLogin();
         if (testLogin)
         {
             UiMessages.Warning(@"Authentication failed: user is already authenticated");
         }
         else if (Global.InitToken == null)
         {
             var loginSuccess = LoginForm.ShowLogin();
             if (loginSuccess)
             {
                 UpdateUIAuthenticate(true);
                 UiMessages.Info(@"Successfully authenticated user");
             }
             else
             {
                 UiMessages.Warning(@"Authentication failed: login was unsuccessful");
             }
         }
         else
         {
             UiMessages.Warning(@"Authentication failed: login data already initialised");
         }
     }
     catch (Exception ex)
     {
         UiMessages.Error(ex.ToString());
     }
 }
Exemplo n.º 4
0
        public Station[] GrabDevicesObject()
        {
            try
            {
                var jsonRaw = GrabJSON();

                if (!string.IsNullOrEmpty(jsonRaw))
                {
                    if (jsonRaw == @"404")
                    {
                        UiMessages.Warning(@"Modem reported inaccessible (404 result)");
                    }
                    else
                    {
                        return(JsonConvert.DeserializeObject <StationList>(jsonRaw, GenericJsonSettings.Settings)?.Stations);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"TopologyGrab error:\n\n{ex}");
            }

            //default
            return(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Polls the modem to find out whether authentication is needed (new login request)
        /// </summary>
        /// <param name="waitWindow"></param>
        /// <param name="warningMode"></param>
        /// <returns></returns>
        public static bool TestLogin(bool waitWindow = true, bool warningMode = false)
        {
            if (waitWindow)
            {
                return((bool)ArcWaitWindow.ArcWaitWindow.Show(TestLogin, @"Testing authentication...", warningMode));
            }

            try
            {
                //for some reason, the modem will retain login information
                //even when you quit the app; making it authorise logins
                //if you don't provide credentials.
                var dummyAuth = new ArcCredential(@"", @"");

                //attempt dummy login if the session token is empty
                return(Global.InitToken != null || DoLogin(dummyAuth, false, warningMode, true));
            }
            catch (Exception ex)
            {
                if (!warningMode)
                {
                    UiMessages.Error($"Login test error\n\n{ex}");
                }
                else
                {
                    UiMessages.Warning("We couldn't verify your authentication status; this will affect your " +
                                       "ability to connect to the modem's CGI pages. Please verify if the modem is reachable.");
                }
            }

            //default
            return(false);
        }
Exemplo n.º 6
0
        private void LoadLog(LogType type)
        {
            try
            {
                //download data from modem
                var handler = new CgiSystemLog(type);
                var table   = handler.GrabTable();

                //validate
                if (table != null)
                {
                    if (table.Rows.Count > 0)
                    {
                        //apply log to grid (and global)
                        SetDataSource(table, true);

                        //adjust 'Current Log File' label
                        lblCurrentLogFileValue.Text = type.ToString();
                    }
                    else
                    {
                        UiMessages.Warning(@"Modem returned 0 log entries; operation failed.");
                    }
                }
                else
                {
                    UiMessages.Warning(@"Modem returned a null result; operation failed.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error($"Error whilst loading the log:\n\n{ex}");
            }
        }
Exemplo n.º 7
0
        private void DoGridSearch(SearchContext cxt)
        {
            var query         = $"`{cxt.SearchColumn}` LIKE '%{cxt.SearchTerm}%'";
            var table         = OriginalData.Copy();
            var filteredTable = table.Select(query);

            if (filteredTable.Length > 0)
            {
                dgvMain.DataSource = filteredTable.CopyToDataTable();
                itmSearch.Text     = @"Cancel Search";
            }
            else
            {
                UiMessages.Warning($"Nothing found for '{cxt.SearchTerm}'", @"No Results");
                CancelSearch();
            }
        }
Exemplo n.º 8
0
        private void ItmFetchFromModem_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var success = ArcLogin.IsAuthenticated();

                if (success)
                {
                    var cfg  = new CgiConfigFile();
                    var file = cfg.GrabFile();

                    if (file != null)
                    {
                        if (file.Length > 0)
                        {
                            ArcArchive.ProcessConfigArchive(file);

                            //update UI
                            LoadTreeView(ArcArchive.ExtractDir);
                        }
                        else
                        {
                            UiMessages.Warning(@"Configuration file from modem returned 0 bytes; operation failed.",
                                               @"Data Error");
                        }
                    }
                    else
                    {
                        UiMessages.Warning(@"Configuration file from modem returned null bytes; operation failed.",
                                           @"Data Error");
                    }
                }
                else
                {
                    UiMessages.Warning(@"Authentication required; please authenticate first.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 9
0
        private void ItmConnectedDevicesList_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var success = ArcLogin.IsAuthenticated();

                if (success)
                {
                    var init = new CgiStations();
                    var dt   = init.GrabTable();

                    if (dt != null)
                    {
                        if (dt.Rows.Count > 0)
                        {
                            ConnectedDevices.ShowConnectedDevices(dt);
                        }
                        else
                        {
                            UiMessages.Warning(
                                @"Topology info from modem returned 0 devices connected; operation failed.",
                                @"Data Error");
                        }
                    }
                    else
                    {
                        UiMessages.Warning("Topology info from modem returned nothing useful. " +
                                           "Please note that this is rate-limited, and the modem will reject too many requests within an undefined time-frame.",
                                           @"Data Error");
                    }
                }
                else
                {
                    UiMessages.Warning(@"Authentication required; please authenticate first.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 10
0
        private void Home_Load(object sender, EventArgs e)
        {
            //updates the position of text field 'Copy' label relative to the form sizing
            CopyLabelPosition();

            //the application will only continue loading if the modem is found to be the Arcadyan LH1000
            var validModem = ArcModem.IsArcadyanModem();

            if (validModem)
            {
                //update menu to reflect auth status
                //this retains the status after the program is closed
                UIAuthUpdate();
            }
            else
            {
                UiMessages.Warning(@"Your modem isn't an Arcadyan LH1000. Please use a different application to suit your device.");
                Process.GetCurrentProcess().Kill();
            }
        }
Exemplo n.º 11
0
        private void ItmJsonScript_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var success = ArcLogin.IsAuthenticated();

                if (success)
                {
                    ScriptExecute.ShowScriptExecute();
                }
                else
                {
                    UiMessages.Warning(@"Authentication required; please authenticate first.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 12
0
        private void ItmFirmwareVersion_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var success = ArcLogin.IsAuthenticated();

                if (success)
                {
                    FirmwareVersion.ShowVersionInfo();
                }
                else
                {
                    UiMessages.Warning(@"Authentication required; please authenticate first.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 13
0
        private void ItmFetchSystemLogs_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var success = ArcLogin.IsAuthenticated();

                if (success)
                {
                    SystemLogs.ShowSystemLogViewer();
                }
                else
                {
                    UiMessages.Warning(@"Authentication required; please authenticate first.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 14
0
        private void ItmCallLog_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var success = ArcLogin.IsAuthenticated();

                if (success)
                {
                    var log   = new CgiCallLog();
                    var table = log.GrabTable();

                    if (table != null)
                    {
                        if (table.Rows.Count > 0)
                        {
                            PhoneLog.LoadLog(table);
                        }
                        else
                        {
                            UiMessages.Warning(@"Call log from modem returned 0 rows; operation failed.", @"Data Error");
                        }
                    }
                    else
                    {
                        UiMessages.Warning(@"Call log from modem returned null bytes; operation failed.", @"Data Error");
                    }
                }
                else
                {
                    UiMessages.Warning(@"Authentication required; please authenticate first.");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 15
0
        private void ItmTryDefault_Click(object sender, EventArgs e)
        {
            try
            {
                //test authentication
                var testLogin = ArcLogin.TestLogin();
                if (testLogin)
                {
                    UiMessages.Warning(@"Authentication failed: user is already authenticated");
                }
                else if (Global.InitToken == null)
                {
                    //LH1000 default is admin:Telstra
                    var defaultLogin = new ArcCredential(@"admin", @"Telstra");

                    //login with default credentials
                    var loginSuccess = ArcLogin.DoLogin(defaultLogin);
                    if (loginSuccess)
                    {
                        UpdateUIAuthenticate(true);
                        UiMessages.Info(@"Successfully authenticated user");
                    }
                    else
                    {
                        UiMessages.Warning(@"Authentication failed: login was unsuccessful");
                    }
                }
                else
                {
                    UiMessages.Warning(@"Authentication failed: login data already initialised");
                }
            }
            catch (Exception ex)
            {
                UiMessages.Error(ex.ToString());
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Perform a new CGI login request which will emulate a user logging into the web portal
        /// </summary>
        /// <param name="auth"></param>
        /// <param name="waitWindow"></param>
        /// <param name="warningMode"></param>
        /// <param name="silent"></param>
        /// <returns></returns>
        public static bool DoLogin(ArcCredential auth = null, bool waitWindow = true, bool warningMode = false, bool silent = false)
        {
            //waitwindow activation
            if (waitWindow && !silent)
            {
                //offloads to another thread and returns the result once it's done
                return((bool)ArcWaitWindow.ArcWaitWindow.Show(DoLogin, @"Authenticating...", auth, warningMode));
            }

            try
            {
                //this will trigger a secondary request
                var arcToken = new ArcToken();

                //verify authentication token
                if (!string.IsNullOrWhiteSpace(arcToken.Token))
                {
                    //authentication credentials (they get hashed when loaded into the Credential object)
                    var unEncoded = auth?.Username;
                    var pwEncoded = auth?.Password;

                    //data to send alongside request
                    var requestBody =
                        new FormUrlEncodedContent(
                            new Dictionary <string, string>
                    {
                        { @"httoken", arcToken.Token },
                        { @"usr", unEncoded },
                        { @"pws", pwEncoded }
                    });

                    //request handler
                    Global.GlobalHandler = new HttpClientHandler
                    {
                        AutomaticDecompression = ~DecompressionMethods.None,
                        AllowAutoRedirect      = false,
                        CookieContainer        = new CookieContainer()
                    };

                    //request client
                    Global.GlobalClient = new HttpClient(Global.GlobalHandler)
                    {
                        Timeout = TimeSpan.FromMilliseconds(Global.RequestTimeout)
                    };

                    //add request credentials
                    var request = new HttpRequestMessage(new HttpMethod(@"POST"), Endpoints.LoginCgi)
                    {
                        Content = requestBody
                    };

                    //create the needed headers
                    request.Headers.TryAddWithoutValidation(@"Accept",
                                                            @"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
                    request.Headers.TryAddWithoutValidation(@"Accept-Language", @"en-US,en;q=0.5");
                    request.Headers.TryAddWithoutValidation(@"Connection", @"keep-alive");
                    request.Headers.TryAddWithoutValidation(@"Upgrade-Insecure-Requests", @"1");
                    request.Headers.TryAddWithoutValidation(@"Cookie", @"disableLogout=0");
                    request.Headers.TryAddWithoutValidation(@"User-Agent", Global.UserAgent);
                    request.Headers.TryAddWithoutValidation(@"Referer", Endpoints.LoginHtm);
                    request.Headers.TryAddWithoutValidation(@"Host", Endpoints.GatewayAddress);
                    request.Headers.TryAddWithoutValidation(@"Origin", Endpoints.Origin);

                    //receive and format response
                    var response       = Global.GlobalClient.SendAsync(request).Result;
                    var locationHeader =
                        response.Headers.Location != null
                            ? response.Headers.Location.ToString()
                            : @"";

                    //null validation
                    if (string.IsNullOrWhiteSpace(locationHeader))
                    {
                        return(false);
                    }

                    //header return page validation
                    if (locationHeader.StartsWith(@"/login.htm"))
                    {
                        //figure out what the error code was
                        var parameters = ParametersFromUrl(locationHeader);

                        //null validation
                        if (parameters != null)
                        {
                            //convert NameValueCollection to generic IDictionary
                            var dict = parameters.AllKeys.ToDictionary(t => t, t => parameters[t]);

                            //verify if the 'err' (error code) parameter exists
                            if (dict.ContainsKey(@"err"))
                            {
                                //parse out error code
                                var err = dict[@"err"];

                                //ensure we can display error messages
                                if (!silent)
                                {
                                    //figure out what error message to display via a switch-case
                                    switch (err)
                                    {
                                    case @"4":
                                        UiMessages.Error("Modem login error:\n\nYou are not allowed to login device's GUI now,\nsince the user number had reached its limit.");
                                        break;

                                    case @"3":
                                        UiMessages.Error("Modem login error:\n\nYour session has timed out or login status has changed.\nPlease sign in again.");
                                        break;

                                    case @"2":
                                        UiMessages.Error("Modem login error:\n\nAnother user has already login.");
                                        break;

                                    case @"1":
                                        UiMessages.Error("Modem login error:\n\nInvalid Username/Password.");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else if (locationHeader == @"/index.htm")
                    {
                        //download home page
                        var homeGrab = ResourceGrab.GrabString(Endpoints.HomeHtm, Endpoints.IndexHtm);

                        //make sure we didn't get redirected to the login page
                        var success = !homeGrab.Contains(@"Telstra Login") && !homeGrab.Contains(@"login.htm");

                        //apply global token if successful
                        if (success)
                        {
                            Global.InitToken = arcToken;
                        }

                        //report status
                        return(success);
                    }
                }
                else
                {
                    UiMessages.Warning(@"Authentication error; CSRF token was invalid.");
                }
            }
            catch (Exception ex)
            {
                if (!silent)
                {
                    if (!warningMode)
                    {
                        UiMessages.Error($"Login error\n\n{ex}");
                    }
                    else
                    {
                        UiMessages.Warning("We couldn't authenticate the application; this will affect your " +
                                           "ability to connect to the modem's CGI pages. Please verify if the modem is reachable.");
                    }
                }
            }

            //default
            return(false);
        }