Exemple #1
0
        protected void Publish(string uid)
        {
            string url = URL + "/publish?a=" + _address + "&f=" + _fingerprint +
                         "&u=" + uid;

            SocialUtils.Request(url);
        }
Exemple #2
0
        public static string GetInfo()
        {
            Dictionary <string, string> parameters =
                new Dictionary <string, string>();

            parameters["m"] = "getstate";
            return(Print(SocialUtils.Request(_url, parameters)));
        }
Exemple #3
0
        public static string Logout(string network)
        {
            Dictionary <string, string> parameters =
                new Dictionary <string, string>();

            parameters["m"] = "logout";
            parameters["n"] = network;
            return(Print(SocialUtils.Request(_url, parameters)));
        }
Exemple #4
0
        public static string Unblock(string address)
        {
            Dictionary <string, string> parameters =
                new Dictionary <string, string>();

            parameters["m"] = "unblock";
            parameters["a"] = address;
            return(Print(SocialUtils.Request(_url, parameters)));
        }
Exemple #5
0
 public SocialUser(string certificate, string ip, string status) : this()
 {
     byte[] certBytes = Convert.FromBase64String(certificate);
     _certificate = certificate;
     _cert        = new Certificate(certBytes);
     _fingerprint = SocialUtils.GetSHA1HashString(certBytes);
     _pic         = PICPREFIX + SocialUtils.GetMD5HashString(Uid) + PICSUFFIX;
     _ip          = ip;
     _status      = status;
 }
Exemple #6
0
        public static string Login(string network, string user, string pass)
        {
            Dictionary <string, string> parameters =
                new Dictionary <string, string>();

            parameters["m"] = "login";
            parameters["n"] = network;
            parameters["u"] = user;
            parameters["p"] = pass;
            return(Print(SocialUtils.Request(_url, parameters)));
        }
        protected string GetState(List <DnsMapping> tmappings, bool write)
        {
            DnsState state = new DnsState();

            state.Mappings = new DnsMapping[_mappings.Count];
            _mappings.Values.CopyTo(state.Mappings, 0);
            Array.Sort(state.Mappings, new MappingComparer());
            state.TmpMappings = tmappings.ToArray();

            if (write)
            {
                Utils.WriteConfig(STATEPATH, state);
            }

            return(SocialUtils.ObjectToXml <DnsState>(state));
        }
Exemple #8
0
        protected void Retreive()
        {
            string url    = URL + "/";
            string result = SocialUtils.Request(url);

            int counter = 0;

            string[] lines = result.Split('\n');
            foreach (string line in lines)
            {
                if (line.Length < 10)
                {
                    continue;
                }
                string[] parts = line.Split(' ');
                _fingerprints = _fingerprints.InsertIntoNew(parts[0], parts[1]);
                _addresses    = _addresses.InsertIntoNew(parts[0], parts[2]);
                counter++;
            }

            _message = " >> Found " + counter + " test server(s)";
        }
        protected string Process(Dictionary <string, string> request)
        {
            EventHandler process_event = ProcessEvent;
            string       response      = String.Empty;

            if (process_event != null)
            {
                try {
                    process_event(request, EventArgs.Empty);
                    response = request["response"];
                } catch (Exception e) {
                    response = SocialUtils.ObjectToXml <string>(e.Message);
                }
            }

            if (request.ContainsKey("html"))
            {
                response = "<html><head><meta HTTP-EQUIV=\"REFRESH\" " +
                           "content=\"0;url=html\" /></head></html>";
            }

            return(response);
        }
        public string GetState(bool write)
        {
#if SVPN_NUNIT
            return(String.Empty);
#else
            FileState   fstate = new FileState();
            SocialState state  = new SocialState();

            if (_node.LocalUser != null)
            {
                state.LocalUser = _node.LocalUser;
                fstate.Uid      = state.LocalUser.Uid;
                fstate.PCID     = state.LocalUser.PCID;
            }

            state.Friends  = new SocialUser[_node.Friends.Values.Count];
            state.Networks = new NetworkState[_networks.Values.Count];
            state.Pending  = new string[_pending.Count];
            fstate.Friends = new FriendState[_node.Friends.Values.Count];

            _pending.CopyTo(state.Pending, 0);

            int i = 0;
            foreach (KeyValuePair <string, ISocialNetwork> kvp
                     in _networks)
            {
                state.Networks[i]         = new NetworkState();
                state.Networks[i].Name    = kvp.Key;
                state.Networks[i].Message = kvp.Value.Message;
                i++;
            }

            i = 0;
            foreach (SocialUser user in _node.Friends.Values)
            {
                string status;

                if (_node.IsAllowed(user.Address))
                {
                    if (IsOffline(user.Address))
                    {
                        status = StatusTypes.Offline.ToString();
                    }
                    else
                    {
                        status = StatusTypes.Online.ToString();
                    }
                }
                else
                {
                    status = StatusTypes.Blocked.ToString();
                }
                state.Friends[i] = new SocialUser(user.Certificate, user.IP,
                                                  status);

                FriendState friend = new FriendState();
                friend.Certificate = user.Certificate;
                friend.IP          = user.IP;
                friend.Status      = status;
                fstate.Friends[i]  = friend;
                i++;
            }

            if (write)
            {
                Utils.WriteConfig(STATEPATH, fstate);
            }

            return(SocialUtils.ObjectToXml <SocialState>(state));
#endif
        }
        protected void Run()
        {
            while (_running)
            {
                HttpListenerContext context = null;

                try {
                    context = _listener.GetContext();
                } catch (Exception e) {
                    Console.WriteLine(e);
                    ProtocolLog.WriteIf(SocialLog.SVPNLog,
                                        String.Format("SVPN Exception: {0}", e));
                }

                HttpListenerRequest  request  = context.Request;
                HttpListenerResponse response = context.Response;

                string responseString;
                response.ContentType = "text/xml";

                if (request.RawUrl.StartsWith("/state.xml?"))
                {
                    string getData = request.RawUrl.Substring(11);
                    try {
                        responseString = Process(SocialUtils.DecodeUrl(getData));
                    } catch (Exception e) {
                        responseString = e.Message;
                    }
                }
                else if (request.RawUrl == "/state.xml")
                {
                    StreamReader reader = new StreamReader(request.InputStream,
                                                           request.ContentEncoding);

                    string postData = reader.ReadToEnd();
                    request.InputStream.Close();
                    reader.Close();
                    try {
                        responseString = Process(SocialUtils.DecodeUrl(postData));
                    } catch (Exception e) {
                        responseString = e.Message;
                    }
                }
                else if (request.RawUrl == "/socialvpn.js")
                {
                    using (StreamReader text = new StreamReader("socialvpn.js")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/javascript";
                }
                else if (request.RawUrl == "/socialvpn.css")
                {
                    using (StreamReader text = new StreamReader("socialvpn.css")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/css";
                }
                else if (request.RawUrl == "/socialdns.js")
                {
                    using (StreamReader text = new StreamReader("socialdns.js")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/javascript";
                }
                else if (request.RawUrl == "/socialdns.css")
                {
                    using (StreamReader text = new StreamReader("socialdns.css")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/css";
                }
                else if (request.RawUrl == "/jquery-ui.css")
                {
                    using (StreamReader text = new StreamReader("jquery-ui.css")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/css";
                }
                else if (request.RawUrl == "/jquery.js")
                {
                    using (StreamReader text = new StreamReader("jquery.js")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/javascript";
                }
                else if (request.RawUrl == "/jquery-ui.js")
                {
                    using (StreamReader text = new StreamReader("jquery-ui.js")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/javascript";
                }
                else if (request.RawUrl == "/sdns")
                {
                    using (StreamReader text = new StreamReader("socialdns.html")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/html";
                }
                else
                {
                    using (StreamReader text = new StreamReader("socialvpn.html")) {
                        responseString = text.ReadToEnd();
                    }
                    response.ContentType = "text/html";
                }

                if (responseString.StartsWith("<html>"))
                {
                    response.ContentType = "text.html";
                }

                byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
                response.ContentLength64 = buffer.Length;
                response.AddHeader("Cache-Control", "No-cache");
                System.IO.Stream output = response.OutputStream;
                try {
                    output.Write(buffer, 0, buffer.Length);
                    output.Close();
                } catch (Exception e) {
                    Console.WriteLine(e);
                    ProtocolLog.WriteIf(SocialLog.SVPNLog,
                                        String.Format("SVPN Exception: {0}", e));
                }
            }
        }
Exemple #12
0
        public static new SocialNode CreateNode()
        {
            SocialConfig             social_config;
            NodeConfig               node_config;
            IpopConfig               ipop_config;
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            if (File.Exists(CONFIGPATH))
            {
                social_config = Utils.ReadConfig <SocialConfig>(CONFIGPATH);
            }
            else
            {
                social_config = SocialUtils.CreateConfig();
            }

            node_config = Utils.ReadConfig <NodeConfig>(social_config.BrunetConfig);
            ipop_config = Utils.ReadConfig <IpopConfig>(social_config.IpopConfig);

            if (!File.Exists(node_config.Security.KeyPath) ||
                node_config.NodeAddress == null)
            {
                node_config.NodeAddress = Utils.GenerateAHAddress().ToString();
                Utils.WriteConfig(social_config.BrunetConfig, node_config);

                SocialUtils.WriteToFile(rsa.ExportCspBlob(true),
                                        node_config.Security.KeyPath);
            }
            else if (File.Exists(node_config.Security.KeyPath))
            {
                rsa.ImportCspBlob(SocialUtils.ReadFileBytes(
                                      node_config.Security.KeyPath));
            }

            SocialNode node = new SocialNode(node_config, ipop_config, rsa);

#if !SVPN_NUNIT
            SocialDnsManager   sdm = new SocialDnsManager(node);
            SocialStatsManager ssm = new SocialStatsManager(node);

            SocialConnectionManager manager = new SocialConnectionManager(node,
                                                                          node.AppNode.Node.Rpc, sdm, ssm, social_config);

            JabberNetwork jabber = new JabberNetwork(social_config.JabberID,
                                                     social_config.JabberPass, social_config.JabberHost,
                                                     social_config.JabberPort);

            TestNetwork test = new TestNetwork();

            manager.Register("jabber", jabber);
            manager.Register("test", test);

            if (social_config.AutoLogin)
            {
                manager.Login("jabber", social_config.JabberID,
                              social_config.JabberPass);
            }

            HttpInterface http = new HttpInterface(social_config.HttpPort);
            http.ProcessEvent += manager.ProcessHandler;

            node._marad.Resolver  = sdm;
            node.Shutdown.OnExit += jabber.Logout;
            node.Shutdown.OnExit += http.Stop;
            http.Start();
#endif

            return(node);
        }