Пример #1
0
        private void OnRemove_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete the selected kites?", "Remove Kite", MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (!this.kitePanel.GetChecked(this.data.Kites))
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "No kites selected", true);
                    return;
                }

                List <string> kitenames = new List <string>();

                foreach (PkKite kite in this.data.Kites.Values)
                {
                    if (kite.Fly)
                    {
                        kitenames.Add(kite.Domain);
                    }
                }

                if (PkService.DeleteKites(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials, kitenames))
                {
                    foreach (string kite in kitenames)
                    {
                        this.data.Kites.Remove(kite);
                    }

                    this.kitePanel.RemoveKites();
                    this.data.Save();
                }
            }
        }
Пример #2
0
        private void Fly()
        {
            if (this.flying)
            {
                return;
            }

            if (!this.kitePanel.GetChecked(this.data.Kites))
            {
                PkLogging.Logger(PkLogging.Level.Warning, "No kites selected", true);
                return;
            }

            if (!this.controller.Start(this.data.Options, this.data.Kites))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to fly kites", true);
                return;
            }

            this.flying               = true;
            this.flyButton.Enabled    = false;
            this.groundButton.Enabled = true;
            this.removeButton.Enabled = false;
            this.addButton.Enabled    = false;
            this.kitePanel.UpdateStatus(this.flying, this.data.Kites);
            this.kitePanel.DisableControls();
            this.Notify("Kites are flying");
        }
Пример #3
0
        private string GetLog()
        {
            string log;

            try
            {
                log = this.pk.get_log();
            }
            catch (DllNotFoundException e)
            {
                PkLogging.Logger(PkLogging.Level.Error,
                                 "Could not locate libpagekite library");
                PkLogging.Logger(PkLogging.Level.Error,
                                 "Message: " + e.Message);
                log = "Unable to get log";
            }

            if (this.libLog.Equals(log))
            {
                log = null;
            }
            else
            {
                this.libLog = log;
            }

            return(log);
        }
Пример #4
0
        public PkSplashForm()
        {
            PictureBox pictureBox = new PictureBox();
            Image      logo;

            try
            {
                logo = Image.FromFile("img\\pagekite-logo-letters.png");
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Could not locate pagekite logo");
                PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
                logo = null;
            }

            if (logo != null)
            {
                pictureBox.Image  = logo;
                pictureBox.Height = logo.Height;
                pictureBox.Width  = logo.Width;
                this.Size         = new Size(logo.Width, logo.Height);
                this.Controls.Add(pictureBox);
            }

            this.StartPosition   = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.None;
        }
Пример #5
0
        public bool Stop(bool exit)
        {
            bool ok = true;

            if (!this.running)
            {
                return(true);
            }

            if (0 > this.pk.stop())
            {
                PkLogging.Logger(PkLogging.Level.Error, "Stopping libpagekite failed");
                ok = false;
            }

            if (ok)
            {
                if (exit)
                {
                    this.exited = true;
                }

                this.running = false;
// FIXME:       ok = this.StopLogListenerThread();
            }

            return(ok);
        }
Пример #6
0
        public static PkData GetAccountInfo(string accountId, string credentials)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            try
            {
                val = proxy.get_account_info(accountId, credentials, "");
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(null);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to update account information");
                return(null);
            }

            XmlRpcStruct serviceStruct = (XmlRpcStruct)val[1];

            PkData data = new PkData();

            XmlRpcStruct serviceData = (XmlRpcStruct)serviceStruct["data"];

            data.ServiceInfo.Secret   = serviceData["_ss"].ToString();
            data.ServiceInfo.DaysLeft = "unknown";
            data.ServiceInfo.MbLeft   = "unknown";

            if (serviceData.Contains("days_left"))
            {
                data.ServiceInfo.DaysLeft = serviceData["days_left"].ToString();
            }
            if (serviceData.Contains("quota_mb_left"))
            {
                data.ServiceInfo.MbLeft = serviceData["quota_mb_left"].ToString();
            }

            object[] serviceKites = (object[])serviceData["kites"];

            foreach (XmlRpcStruct serviceKite in serviceKites)
            {
                PkKite kite = new PkKite();
                kite.Domain = serviceKite["domain"].ToString();
                kite.Secret = serviceKite["ssecret"].ToString();
                data.Kites.Add(kite.Domain, kite);
            }

            return(data);
        }
Пример #7
0
        public static bool AddKite(string accountId, string credentials, string kitename)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            try
            {
                val = proxy.add_kite(accountId, credentials, kitename, false);
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(false);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to add kite"
                                 + Environment.NewLine + ok, true);
                return(false);
            }

            PkLogging.Logger(PkLogging.Level.Info, kitename + " added.");

            return(true);
        }
Пример #8
0
        private void UpdateDaysLeft()
        {
            this.daysLeftLabel.Text = "Days left: " + this.data.ServiceInfo.DaysLeft;

            bool ok       = true;
            int  daysLeft = -1;

            try
            {
                daysLeft = Convert.ToInt32(this.data.ServiceInfo.DaysLeft);
            }
            catch (FormatException e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "days_left is not a number.");
                ok = false;
            }
            catch (OverflowException e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "days_left cannot fit in an Int32.");
                ok = false;
            }

            if (ok && daysLeft < 6)
            {
                this.daysLeftLabel.ForeColor = Color.Red;
                PkLogging.Logger(PkLogging.Level.Warning,
                                 "You only have " + daysLeft + " days left of your subscription.", true);
            }
        }
Пример #9
0
            private void OnOk_Click(object sender, EventArgs e)
            {
                string email    = this.emailTextBox.Text;
                string kiteName = this.kiteTextBox.Text;
                string password = this.passwordTextBox.Text;

                if (!this.ValidateEmail(email))
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid email address", true);
                    return;
                }
                if (string.IsNullOrEmpty(kiteName))
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid kite name", true);
                    return;
                }

                if (string.IsNullOrEmpty(password))
                {
                    if (this.agreeCheckBox.Checked)
                    {
                        if (PkService.CreateAccount(email, kiteName))
                        {
                            PkLogging.Logger(PkLogging.Level.Info, "An email containing your password and details has been sent to " + email, true);
                            return;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        PkLogging.Logger(PkLogging.Level.Warning, "You must agree to the terms of service to continue.", true);
                    }
                }
                else
                {
                    PkServiceInfo info = PkService.Login(email, password, false);

                    if (info != null)
                    {
                        PkLogging.Logger(PkLogging.Level.Info, "Successfully signed in.");

                        password = "";
                        this.passwordTextBox.Text = "";

                        this.RememberMe  = this.rememberCheckBox.Checked;
                        this.ServiceInfo = info;

                        PkLoginForm parent = (this.Parent as PkLoginForm);
                        parent.Close_Login();
                    }
                    else
                    {
                        return;
                    }
                }
            }
Пример #10
0
        public static bool CreateAccount(string email, string kitename)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            try
            {
                val = proxy.create_account("", "", email, kitename, true, true, false);
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(false);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                switch (ok)
                {
                case "email":
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid email address", true);
                    break;

                case "subdomain":
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid subdomain", true);
                    break;

                case "domain":
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid domain", true);
                    break;

                case "pleaselogin":
                    PkLogging.Logger(PkLogging.Level.Warning, "Please log in", true);
                    break;

                case "domaintaken":
                    PkLogging.Logger(PkLogging.Level.Warning, "This domain is taken", true);
                    break;

                default:
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid information" + Environment.NewLine
                                     + ok, true);
                    break;
                }

                return(false);
            }

            return(true);
        }
Пример #11
0
        private bool Poll(int timeout)
        {
            if (0 > this.pk.poll(timeout))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Polling failed");
                return(false);
            }

            return(true);
        }
Пример #12
0
        public static PkServiceInfo Login(string a, string c, bool auto)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            try
            {
                if (auto)
                {
                    val = proxy.login(a, c, c);
                }
                else
                {
                    val = proxy.login(a, c, "");
                }
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(null);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                if (auto)
                {
                    return(null);
                }
                else
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Incorrect information", true);
                    return(null);
                }
            }

            string[] data = (string[])val[1];

            PkServiceInfo info = new PkServiceInfo();

            info.AccountId   = data[0];
            info.Credentials = data[1];

            return(info);
        }
Пример #13
0
        public PkAboutForm()
        {
            Button     okButton     = new Button();
            Label      versionLabel = new Label();
            PictureBox pictureBox   = new PictureBox();
            Font       font         = new Font("Tahoma", 12);
            Image      logo;

            try
            {
                logo = Image.FromFile("img\\pagekite-logo-letters.png");
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Could not locate pagekite logo");
                PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
                logo = null;
            }

            if (logo != null)
            {
                pictureBox.Image  = logo;
                pictureBox.Height = logo.Height;
                pictureBox.Width  = logo.Width;
            }

            this.Size = new Size(380, 460);

            pictureBox.Location = new Point(this.Width / 2 - logo.Width / 2, 20);

            versionLabel.AutoSize = true;
            versionLabel.Font     = font;
            versionLabel.Text     = "Version: " + PkVersion.Version;
            versionLabel.Location = new Point(this.Width / 2 - versionLabel.Width / 2, 220);

            okButton.Size     = new Size(80, 30);
            okButton.Location = new Point(this.Width / 2 - okButton.Width / 2, 360);
            okButton.Font     = new Font("Tahoma", 10);
            okButton.Text     = "Ok";
            okButton.Click   += new EventHandler(this.OnOkButton_Click);

            this.Controls.Add(pictureBox);
            this.Controls.Add(versionLabel);
            this.Controls.Add(okButton);

            this.MaximizeBox     = false;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.StartPosition   = FormStartPosition.CenterScreen;
            this.Text            = "PageKite";
        }
Пример #14
0
        private void StartRenewLoginThread()
        {
            Thread thread = new Thread(new ThreadStart(this.RenewLogin));

            thread.IsBackground = true;

            try
            {
                thread.Start();
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to start RenewLogin thread");
                PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
            }
        }
Пример #15
0
        public static Dictionary <string, double> GetKiteStats(string accountId, string credentials)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            try
            {
                val = proxy.get_kite_stats(accountId, credentials);
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(null);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to update kites");
                return(null);
            }

            XmlRpcStruct kitesStruct = (XmlRpcStruct)val[1];

            Dictionary <string, double> kites = new Dictionary <string, double>();

            foreach (string kite in kitesStruct.Keys)
            {
                try
                {
                    kites[kite] = Convert.ToDouble(kitesStruct[kite]);
                }
                catch (Exception e)
                {
                    kites[kite] = -1;
                }
            }

            return(kites);
        }
Пример #16
0
/* FIXME:
 *      private bool StopLogListenerThread()
 *      {
 *          bool ok = true;
 *
 *          try
 *          {
 *              this.logThread.Abort(); //fixme: this is bad and doesn't work
 *          }
 *          catch (Exception e)
 *          {
 *              PkLogging.Logger(PkLogging.Level.Error, "Unable to stop logger thread");
 *              PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
 *              ok = false;
 *          }
 *
 *          return ok;
 *      }
 */
        private void LogListen()
        {
            Thread.Sleep(1200);
            while (this.running)
            {
                if (this.Poll(3600))
                {
                    Thread.Sleep(150);
                    if (!this.exited)
                    {
                        string log = this.GetLog();
                        if (log != null)
                        {
                            PkLogging.Logger(PkLogging.Level.Lib, log);
                        }
                    }
                }
            }
        }
Пример #17
0
        private void Ground()
        {
            if (!this.flying)
            {
                return;
            }

            this.controller.Stop(false);

            this.flying               = false;
            this.flyButton.Enabled    = true;
            this.groundButton.Enabled = false;
            this.removeButton.Enabled = true;
            this.addButton.Enabled    = true;
            this.kitePanel.UpdateStatus(this.flying, this.data.Kites);
            this.kitePanel.EnableControls();
            this.Notify("Kites have been grounded");

            PkLogging.GroundLib();
        }
Пример #18
0
        public static Dictionary <string, string[]> GetAvailableDomains(string accountId, string credentials)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            try
            {
                val = proxy.get_available_domains(accountId, credentials);
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(null);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to fetch available domains"
                                 + Environment.NewLine + ok, true);
                return(null);
            }

            XmlRpcStruct data = (XmlRpcStruct)val[1];

            Dictionary <string, string[]> domains = new Dictionary <string, string[]>();

            foreach (string key in data.Keys)
            {
                domains.Add(key, (string[])data[key]);
            }

            return(domains);
        }
Пример #19
0
        static public void ShowSplashScreen()
        {
            if (splashForm != null)
            {
                return;
            }

            Thread thread = new Thread(new ThreadStart(PkSplashForm.ShowForm));

            thread.IsBackground = true;

            try
            {
                thread.Start();
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to start SplashForm");
                PkLogging.Logger(PkLogging.Level.Error, e.Message);
            }
        }
Пример #20
0
        private void LogIn()
        {
            if (this.data.Options.RememberMe)
            {
                PkServiceInfo info = PkService.Login(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials, true);

                if (info != null)
                {
                    PkLogging.Logger(PkLogging.Level.Info, "Successfully logged in.");
                }
                else
                {
                    PkSplashForm.CloseSplashScreen();
                    this.ShowLoginForm();
                }
            }
            else
            {
                PkSplashForm.CloseSplashScreen();
                this.ShowLoginForm();
            }
        }
Пример #21
0
        public static bool DeleteKites(string accountId, string credentials, List <string> kitenames)
        {
            object[]   val;
            IPkService proxy = XmlRpcProxyGen.Create <IPkService>();

            string[] kites = new string[kitenames.Count];
            for (int i = 0; i < kites.Length; i++)
            {
                kites[i] = kitenames[i];
            }

            try
            {
                val = proxy.delete_kites(accountId, credentials, kites);
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to connect to the Pagekite Service"
                                 + Environment.NewLine + "Exception: " + e.Message, true);
                val = null;
            }

            if (val == null)
            {
                return(false);
            }

            string ok = val[0].ToString();

            if (!ok.Equals("ok"))
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to remove kites", true);
                return(false);
            }

            PkLogging.Logger(PkLogging.Level.Info, kitenames.Count + " kites removed.");

            return(true);
        }
Пример #22
0
        public static PkData Load()
        {
            PkData data = new PkData();

            string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            dir = Path.Combine(dir, "PageKite");
            string filepath = Path.Combine(dir, "userconfig.json");

            if (File.Exists(filepath))
            {
                try
                {
                    using (StreamReader file = File.OpenText(@filepath))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        data = (PkData)serializer.Deserialize(file, typeof(PkData));
                    }
                }
                catch (Exception e)
                {
                    PkLogging.Logger(PkLogging.Level.Error, "Unable to load settings.", true);
                    PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
                    data = new PkData();
                }
            }
            else
            {
                data = new PkData();
            }

            if (data == null)
            {
                data = new PkData();
            }

            return(data);
        }
Пример #23
0
        public void Save()
        {
            //Save settings to %AppData% where we should always have read/write access

            string dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            dir = Path.Combine(dir, "PageKite");

            if (!Directory.Exists(dir))
            {
                try
                {
                    Directory.CreateDirectory(dir);
                }
                catch (Exception e)
                {
                    PkLogging.Logger(PkLogging.Level.Error, "Unable to save settings.", true);
                    PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
                }
            }

            string filepath = Path.Combine(dir, "userconfig.json");

            try
            {
                using (StreamWriter file = File.CreateText(@filepath))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, this);
                }
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error, "Unable to save settings.", true);
                PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
            }
        }
Пример #24
0
        private bool StartLogListenerThread()
        {
            bool ok = true;

            this.running = true;
            Thread logThread = new Thread(new ThreadStart(this.LogListen));

            logThread.IsBackground = true;

            try
            {
                logThread.Start();
            }
            catch (Exception e)
            {
                PkLogging.Logger(PkLogging.Level.Error,
                                 "Unable to start logger thread");
                PkLogging.Logger(PkLogging.Level.Error,
                                 "Exception: " + e.Message);
                ok = false;
            }

            return(ok);
        }
Пример #25
0
        private void OnSave_Click(object sender, EventArgs e)
        {
            this.Kite = new PkKite();

//            kite.Domain = this.domainTextBox.Text;

            this.Kite.Domain = this.domainLabel.Text;

            this.Kite.HTTP.Enabled      = this.httpCheckBox.Checked;
            this.Kite.HTTPS.Enabled     = this.httpsCheckBox.Checked;
            this.Kite.SSH.Enabled       = this.sshCheckBox.Checked;
            this.Kite.Minecraft.Enabled = this.minecraftCheckBox.Checked;

            if (this.Kite.HTTP.Enabled)
            {
                this.Kite.HTTP.Port = this.validatePort(this.httpPortTextBox.Text);

                if (this.Kite.HTTP.Port == 0)
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid port number", true);
                    return;
                }
            }

            if (this.Kite.HTTPS.Enabled)
            {
                this.Kite.HTTPS.Port = this.validatePort(this.httpsPortTextBox.Text);

                if (this.Kite.HTTPS.Port == 0)
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid port number", true);
                    return;
                }
            }

            if (this.Kite.SSH.Enabled)
            {
                this.Kite.SSH.Port = this.validatePort(this.sshPortTextBox.Text);

                if (this.Kite.SSH.Port == 0)
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid port number", true);
                    return;
                }
            }

            if (this.Kite.Minecraft.Enabled)
            {
                this.Kite.Minecraft.Port = this.validatePort(this.minecraftPortTextBox.Text);

                if (this.Kite.Minecraft.Port == 0)
                {
                    PkLogging.Logger(PkLogging.Level.Warning, "Invalid port number", true);
                    return;
                }
            }

            /*           PkKiteUpdateEventArgs args = new PkKiteUpdateEventArgs("save", kite);
             *         PkKiteUpdateHandler handler = this.KiteUpdated;
             *
             *         if(handler != null)
             *         {
             *             handler(this, args);
             *         }
             */

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #26
0
            public WelcomePanel()
            {
                this.helpButton   = new Button();
                this.notNowButton = new Button();
                this.yesButton    = new Button();

                PictureBox pictureBox = new PictureBox();
                Image      logo;

                try
                {
                    logo = Image.FromFile("img\\pagekite-logo-letters.png");
                }
                catch (Exception e)
                {
                    PkLogging.Logger(PkLogging.Level.Error, "Could not locate pagekite logo");
                    PkLogging.Logger(PkLogging.Level.Error, "Exception: " + e.Message);
                    logo = null;
                }

                Label welcomeLabel        = new Label();
                Label usePageKiteNetLabel = new Label();

                FlowLayoutPanel buttonPanel         = new FlowLayoutPanel();
                Panel           welcomePanel        = new Panel();
                Panel           usePageKiteNetPanel = new Panel();

                Font font = new Font("Tahoma", 10);

                this.Size = new Size(380, 380);

                if (logo != null)
                {
                    pictureBox.Location = new Point(this.Width / 2 - logo.Width / 2, 20);
                    pictureBox.Image    = logo;
                    pictureBox.Height   = logo.Height;
                    pictureBox.Width    = logo.Width;
                }

                welcomePanel.Location = new Point(0, 210);
                welcomePanel.Size     = new Size(this.Width, 40);

                usePageKiteNetPanel.Location = new Point(0, 270);
                usePageKiteNetPanel.Size     = new Size(this.Width, 30);

                welcomeLabel.AutoSize  = false;
                welcomeLabel.TextAlign = ContentAlignment.MiddleCenter;
                welcomeLabel.Dock      = DockStyle.Fill;
                welcomeLabel.Font      = new Font("Tahoma", 14);
                welcomeLabel.Text      = "Welcome to PageKite.";

                usePageKiteNetLabel.AutoSize  = false;
                usePageKiteNetLabel.TextAlign = ContentAlignment.MiddleCenter;
                usePageKiteNetLabel.Dock      = DockStyle.Fill;
                usePageKiteNetLabel.Font      = font;
                usePageKiteNetLabel.Text      = "Do you want to use pagekite.net as your relay?";

                buttonPanel.Location      = new Point(45, 320);
                buttonPanel.Size          = new Size(300, 50);
                buttonPanel.FlowDirection = FlowDirection.LeftToRight;

                this.helpButton.Size   = new Size(90, 30);
                this.helpButton.Font   = font;
                this.helpButton.Text   = "Help?";
                this.helpButton.Click += new EventHandler(this.OnHelp_Click);

                this.yesButton.Size   = new Size(90, 30);
                this.yesButton.Font   = font;
                this.yesButton.Text   = "Yes";
                this.yesButton.Click += new EventHandler(this.OnYes_Click);

                this.notNowButton.Size   = new Size(90, 30);
                this.notNowButton.Font   = font;
                this.notNowButton.Text   = "Not now";
                this.notNowButton.Click += new EventHandler(this.OnNotNow_Click);

                buttonPanel.Controls.Add(this.yesButton);
                buttonPanel.Controls.Add(this.notNowButton);
                buttonPanel.Controls.Add(this.helpButton);

                welcomePanel.Controls.Add(welcomeLabel);
                usePageKiteNetPanel.Controls.Add(usePageKiteNetLabel);

                this.Controls.Add(pictureBox);
                this.Controls.Add(welcomePanel);
                this.Controls.Add(usePageKiteNetPanel);
                this.Controls.Add(buttonPanel);
            }
Пример #27
0
        private bool AddKite(PkKite kite)
        {
            bool ok = true;

            if (ok && kite.HTTP.Enabled)
            {
                if (0 > this.pk.add_kite(kite.HTTP.Proto, kite.Domain, 0,
                                         kite.Secret,
                                         "localhost", kite.HTTP.Port))
                {
                    PkLogging.Logger(PkLogging.Level.Error,
                                     "Unable to add kite" +
                                     " | Domain: " + kite.Domain +
                                     " | Proto: " + kite.HTTP.Proto +
                                     " | Port: " + kite.HTTP.Port.ToString());
                    ok = false;
                }
            }

            if (ok && kite.HTTPS.Enabled)
            {
                if (0 > this.pk.add_kite(kite.HTTPS.Proto, kite.Domain, 0,
                                         kite.Secret,
                                         "localhost", kite.HTTPS.Port))
                {
                    PkLogging.Logger(PkLogging.Level.Error,
                                     "Unable to add kite" +
                                     " | Domain: " + kite.Domain +
                                     " | Proto: " + kite.HTTPS.Proto +
                                     " | Port: " + kite.HTTPS.Port.ToString());
                    ok = false;
                }
            }

            if (ok && kite.SSH.Enabled)
            {
                if (0 > this.pk.add_kite(kite.SSH.Proto, kite.Domain, 22,
                                         kite.Secret,
                                         "localhost", kite.SSH.Port))
                {
                    PkLogging.Logger(PkLogging.Level.Error,
                                     "Unable to add kite" +
                                     " | Domain: " + kite.Domain +
                                     " | Proto: " + kite.SSH.Proto +
                                     " | Port: " + kite.SSH.Port.ToString());
                    ok = false;
                }
            }

            if (ok && kite.Minecraft.Enabled)
            {
                if (0 > this.pk.add_kite(kite.Minecraft.Proto, kite.Domain, 0,
                                         kite.Secret,
                                         "localhost", kite.Minecraft.Port))
                {
                    PkLogging.Logger(PkLogging.Level.Error,
                                     "Unable to add kite" +
                                     " | Domain: " + kite.Domain +
                                     " | Proto: " + kite.Minecraft.Proto +
                                     " | Port: " + kite.Minecraft.Port.ToString());
                    ok = false;
                }
            }

            return(ok);
        }
Пример #28
0
        private void SynchronizeAccountInfo()
        {
            PkData serviceData = PkService.GetAccountInfo(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials);
            Dictionary <string, double> kiteStats = PkService.GetKiteStats(this.data.ServiceInfo.AccountId, this.data.ServiceInfo.Credentials);

            if (serviceData != null && kiteStats != null)
            {
                //Update info about account and kites if it has been manipulated outside of this program

                this.data.ServiceInfo.Secret = serviceData.ServiceInfo.Secret;

                this.data.ServiceInfo.DaysLeft = serviceData.ServiceInfo.DaysLeft;

                this.data.ServiceInfo.MbLeft = serviceData.ServiceInfo.MbLeft;

                List <string> removeDomain = new List <string>();

                //If any kites have been removed, remove them
                foreach (string domain in this.data.Kites.Keys)
                {
                    if (!serviceData.Kites.ContainsKey(domain))
                    {
                        removeDomain.Add(domain);
                    }
                }

                //If any kites are disabled, remove them
                foreach (string domain in kiteStats.Keys)
                {
                    if (kiteStats[domain] < 0)
                    {
                        removeDomain.Add(domain);
                    }
                }

                foreach (string domain in removeDomain)
                {
                    if (this.data.Kites.ContainsKey(domain))
                    {
                        this.data.Kites.Remove(domain);
                    }
                }

                foreach (string domain in serviceData.Kites.Keys)
                {
                    //If new kites have been added, add them, unless they are disabled
                    if (!this.data.Kites.ContainsKey(domain) && kiteStats[domain] > 0)
                    {
                        if (String.IsNullOrEmpty(serviceData.Kites[domain].Secret))
                        {
                            serviceData.Kites[domain].Secret = this.data.ServiceInfo.Secret;
                        }
                        this.data.Kites.Add(domain, serviceData.Kites[domain]);
                    }

                    if (this.data.Kites.ContainsKey(domain))
                    {
                        //Update kite secret if it has changed
                        if (!this.data.Kites[domain].Secret.Equals(serviceData.Kites[domain].Secret) &&
                            !String.IsNullOrEmpty(serviceData.Kites[domain].Secret))
                        {
                            this.data.Kites[domain].Secret = serviceData.Kites[domain].Secret;
                        }
                    }
                }

                PkLogging.Logger(PkLogging.Level.Info, "All kites are up to date.");
            }

            if (this.data.Options.RememberMe)
            {
                this.data.Save();
            }
        }
Пример #29
0
        public bool Start(PkOptions options, Dictionary <string, PkKite> kites)
        {
            int numKites  = 4 * (1 + kites.Count); // 4 possible protocols
            int maxConns  = 25;
            int flags     = PkLib.PK_WITH_DEFAULTS;
            int verbosity = options.Debug ? 2 : 0;

// FIXME:   if (no network connection)
//          {
//              // Report error?
//              return false;
//          }

            bool ok = true;

            try
            {
                if (!this.pk.init_pagekitenet(APPID,
                                              numKites,
                                              maxConns,
                                              flags,
                                              verbosity))
                {
                    PkLogging.Logger(PkLogging.Level.Error,
                                     "Initializing LibPageKite failed, aborting");
                    return(false);
                }
            }
            catch (DllNotFoundException e)
            {
                PkLogging.Logger(PkLogging.Level.Error,
                                 "Could not locate " + PkLib.DLL);
                PkLogging.Logger(PkLogging.Level.Error,
                                 "Message: " + e.Message);
                ok = false;
            }

            if (ok)
            {
                ok = this.StartLogListenerThread();
                if (!ok)
                {
                    this.Stop(false);
                }
            }

            foreach (PkKite kite in kites.Values)
            {
                if (ok && kite.Fly)
                {
                    if (!this.AddKite(kite))
                    {
                        PkLogging.Logger(PkLogging.Level.Error,
                                         "Adding kites failed, aborting");
                        this.Stop(false);
                        ok = false;
                    }
                }
            }

            if (ok)
            {
                int status = this.pk.start();
                if (0 > status)
                {
                    PkLogging.Logger(PkLogging.Level.Error, "Unable to start LibPageKite, aborting");
                    this.Stop(false);
                    ok = false;
                }
            }

            return(ok);
        }