Exemple #1
0
        private void doWork()
        {
            try
            {
                log(MOD_NAME, "Starting process...");
                switch (System.Environment.OSVersion.Version.Major)
                {
                case 5:
                    break;

                case 6:
                    break;

                case 7:
                    break;

                default:
                    log(MOD_NAME, "This module has only been tested on Windows XP, Vista and 7!");
                    break;
                }

                ArrayList alMACs = getMacAddress();

                String macList = null;
                if (alMACs != null && alMACs.Count > 0)
                {
                    String[] strMacs = (String[])alMACs.ToArray(typeof(String));
                    macList = String.Join("|", strMacs);
                }

                // First check and see if the module is active
                //
                Boolean blLoop = false;
                if (macList != null && macList.Length > 0)
                {
                    String  strData     = null;
                    Boolean blConnectOK = false;
                    while (!blConnectOK)
                    {
                        try
                        {
                            WebClient web     = new WebClient();
                            String    strPath = strURLModuleStatus + "?mac=" + macList + "&moduleid=autologout";
                            strData     = web.DownloadString(strPath);
                            blConnectOK = true;
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, "Failed to connect to fog server!");
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            log(MOD_NAME, "Sleeping for 1 minute.");
                            try
                            {
                                System.Threading.Thread.Sleep(60000);
                            }
                            catch { }
                        }
                    }

                    strData = strData.Trim();
                    if (strData.StartsWith("#!ok", true, null))
                    {
                        log(MOD_NAME, "Module is active...");
                        blLoop = true;
                    }
                    else if (strData.StartsWith("#!db", true, null))
                    {
                        log(MOD_NAME, "Database error.");
                    }
                    else if (strData.StartsWith("#!im", true, null))
                    {
                        log(MOD_NAME, "Invalid MAC address format.");
                    }
                    else if (strData.StartsWith("#!ng", true, null))
                    {
                        log(MOD_NAME, "Module is disabled globally on the FOG Server.");
                    }
                    else if (strData.StartsWith("#!nh", true, null))
                    {
                        log(MOD_NAME, "Module is disabled on this host.");
                    }
                    else if (strData.StartsWith("#!um", true, null))
                    {
                        log(MOD_NAME, "Unknown Module ID passed to server.");
                    }
                    else
                    {
                        log(MOD_NAME, "Unknown error, module will exit.");
                    }


                    if (blLoop)
                    {
                        Boolean blLgIn = isLoggedIn();

                        try
                        {
                            WebClient wc     = new WebClient();
                            String    strRes = wc.DownloadString(strURLTimeout + "?mac=" + macList);
                            strRes = strRes.Trim();
                            if (strRes != null)
                            {
                                String strTimeout = decode64(strRes);

                                if (strTimeout != null)
                                {
                                    try
                                    {
                                        intTimeout = int.Parse(strTimeout);
                                        if (intTimeout == 0)
                                        {
                                            log(MOD_NAME, "Timeout value is Zero, disabling module.");
                                            blGo = false;
                                        }
                                        else if (intTimeout <= 1)
                                        {
                                            log(MOD_NAME, "Timeout value was either 1 minute or less, I am going to assume this is a mistake and exit.");
                                            blGo = false;
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        log(MOD_NAME, e.Message);
                                        log(MOD_NAME, e.StackTrace);
                                        blGo = false;
                                    }
                                }
                                else
                                {
                                    blGo = false;
                                    log(MOD_NAME, "Unable to determine timeout settings.");
                                }
                            }
                            else
                            {
                                blGo = false;
                                log(MOD_NAME, "Server response was null.");
                            }
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            blGo = false;
                        }

                        String strBGImage = null;

                        try
                        {
                            WebClient wc     = new WebClient();
                            String    strRes = wc.DownloadString(strURLBG);
                            strBGImage = decode64(strRes);

                            Boolean blWebBased = false;
                            if (strBGImage.StartsWith("https://", true, null) || strBGImage.StartsWith("http://", true, null) || strBGImage.StartsWith("ftp://", true, null))
                            {
                                blWebBased = true;
                            }

                            if (blWebBased)
                            {
                                WebClient webDL = new WebClient();
                                Byte[]    bImg;
                                bImg = webDL.DownloadData(strBGImage);
                                MemoryStream ms = new MemoryStream(bImg);
                                bgImage = Image.FromStream(ms);
                            }
                            else
                            {
                                bgImage = Image.FromFile(strBGImage);
                            }
                        }
                        catch (Exception exImg)
                        {
                            log(MOD_NAME, exImg.Message);
                            log(MOD_NAME, exImg.StackTrace);
                        }

                        if (blGo)
                        {
                            Thread t = new Thread(new ThreadStart(logInOutTracker));
                            t.IsBackground = true;
                            t.Start();

                            while (true)
                            {
                                log(MOD_NAME, "Creating ALO interface.");
                                frm = new ALOForm(intTimeout, bgImage, this);
                                frm.setLoggedIn(isLoggedIn());
                                frm.ShowDialog();
                                log(MOD_NAME, "ALO interface has died, will respawn in 30 seconds.");
                                try
                                {
                                    Thread.Sleep(30000);
                                }
                                catch { }
                            }
                        }
                    }
                }
                else
                {
                    log(MOD_NAME, "Unable to continue, MAC is null!");
                }
            }
            catch (Exception e)
            {
                pushMessage("FOG Auto Log Off error:\n" + e.Message);
                log(MOD_NAME, e.Message);
                log(MOD_NAME, e.StackTrace);
            }
            finally
            {
            }
            intStatus = STATUS_TASKCOMPLETE;
        }
        private void doWork()
        {
            try
            {
                log(MOD_NAME, "Starting process...");
                switch (System.Environment.OSVersion.Version.Major)
                {
                    case 5:
                        break;
                    case 6:
                        break;
                    case 7:
                        break;
                    default:
                        log(MOD_NAME, "This module has only been tested on Windows XP, Vista and 7!");
                        break;
                }

                ArrayList alMACs = getMacAddress();

                String macList = null;
                if (alMACs != null && alMACs.Count > 0)
                {
                    String[] strMacs = (String[])alMACs.ToArray(typeof(String));
                    macList = String.Join("|", strMacs);
                }

                // First check and see if the module is active
                //
                Boolean blLoop = false;
                if (macList != null && macList.Length > 0)
                {
                    String strData = null;
                    Boolean blConnectOK = false;
                    while (!blConnectOK)
                    {
                        try
                        {
                            WebClient web = new WebClient();
                            String strPath = strURLModuleStatus + "?mac=" + macList + "&moduleid=autologout";
                            strData = web.DownloadString(strPath);
                            blConnectOK = true;
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, "Failed to connect to fog server!");
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            log(MOD_NAME, "Sleeping for 1 minute.");
                            try
                            {
                                System.Threading.Thread.Sleep(60000);
                            }
                            catch { }
                        }
                    }

                    strData = strData.Trim();
                    if (strData.StartsWith("#!ok", true, null))
                    {
                        log(MOD_NAME, "Module is active...");
                        blLoop = true;
                    }
                    else if (strData.StartsWith("#!db", true, null))
                    {
                        log(MOD_NAME, "Database error.");
                    }
                    else if (strData.StartsWith("#!im", true, null))
                    {
                        log(MOD_NAME, "Invalid MAC address format.");
                    }
                    else if (strData.StartsWith("#!ng", true, null))
                    {
                        log(MOD_NAME, "Module is disabled globally on the FOG Server.");
                    }
                    else if (strData.StartsWith("#!nh", true, null))
                    {
                        log(MOD_NAME, "Module is disabled on this host.");
                    }
                    else if (strData.StartsWith("#!um", true, null))
                    {
                        log(MOD_NAME, "Unknown Module ID passed to server.");
                    }
                    else
                    {
                        log(MOD_NAME, "Unknown error, module will exit.");
                    }

                    if (blLoop)
                    {
                        Boolean blLgIn = isLoggedIn();

                        try
                        {
                            WebClient wc = new WebClient();
                            String strRes = wc.DownloadString(strURLTimeout + "?mac=" + macList);
                            strRes = strRes.Trim();
                            if (strRes != null)
                            {

                                String strTimeout = decode64(strRes);

                                if (strTimeout != null)
                                {
                                    try
                                    {
                                        intTimeout = int.Parse( strTimeout );
                                        if (intTimeout == 0)
                                        {
                                            log(MOD_NAME, "Timeout value is Zero, disabling module.");
                                            blGo = false;
                                        }
                                        else if (intTimeout <= 1)
                                        {
                                            log(MOD_NAME, "Timeout value was either 1 minute or less, I am going to assume this is a mistake and exit.");
                                            blGo = false;
                                        }

                                    }
                                    catch (Exception e)
                                    {
                                        log(MOD_NAME, e.Message);
                                        log(MOD_NAME, e.StackTrace);
                                        blGo = false;
                                    }
                                }
                                else
                                {
                                    blGo = false;
                                    log(MOD_NAME, "Unable to determine timeout settings.");
                                }
                            }
                            else
                            {
                                blGo = false;
                                log(MOD_NAME, "Server response was null.");
                            }
                        }
                        catch (Exception exp)
                        {
                            log(MOD_NAME, exp.Message);
                            log(MOD_NAME, exp.StackTrace);
                            blGo = false;
                        }

                        String strBGImage = null;

                        try
                        {
                            WebClient wc = new WebClient();
                            String strRes = wc.DownloadString(strURLBG);
                            strBGImage = decode64(strRes);

                            Boolean blWebBased = false;
                            if (strBGImage.StartsWith("https://", true, null) || strBGImage.StartsWith("http://", true, null) || strBGImage.StartsWith("ftp://", true, null))
                            {
                                blWebBased = true;
                            }

                            if (blWebBased)
                            {
                                WebClient webDL = new WebClient();
                                Byte[] bImg;
                                bImg = webDL.DownloadData(strBGImage);
                                MemoryStream ms = new MemoryStream(bImg);
                                bgImage = Image.FromStream(ms);
                            }
                            else
                            {
                                bgImage = Image.FromFile(strBGImage);
                            }

                        }
                        catch (Exception exImg)
                        {
                            log(MOD_NAME, exImg.Message);
                            log(MOD_NAME, exImg.StackTrace);
                        }

                        if (blGo)
                        {
                            Thread t = new Thread(new ThreadStart(logInOutTracker));
                            t.IsBackground = true;
                            t.Start();

                            while (true)
                            {
                                log(MOD_NAME, "Creating ALO interface.");
                                frm = new ALOForm(intTimeout, bgImage, this);
                                frm.setLoggedIn(isLoggedIn());
                                frm.ShowDialog();
                                log(MOD_NAME, "ALO interface has died, will respawn in 30 seconds.");
                                try
                                {
                                    Thread.Sleep(30000);
                                }
                                catch { }
                            }

                        }
                    }
                }
                else
                {
                    log(MOD_NAME, "Unable to continue, MAC is null!");
                }

            }
            catch (Exception e)
            {
                pushMessage("FOG Auto Log Off error:\n" + e.Message);
                log(MOD_NAME, e.Message);
                log(MOD_NAME, e.StackTrace);
            }
            finally
            {
            }
            intStatus = STATUS_TASKCOMPLETE;
        }