Пример #1
0
        private static void OpenClientEvent(object sender, EventArgs e)
        {
            var ip       = NetworkUtilities.GetIPv4Address();
            var httpPort = HttpServer.GlobalPort;

            Process.Start($"http://{ip}:{httpPort}");
        }
        /* Private methods */

        /// <summary>
        /// Private constructor that prevents initialisation
        /// of an instance of UCServer by using the default
        /// constructor.
        /// </summary>
        private UCServer(int port, int maxConn)
        {
            serverSocket = NetworkUtilities.InitSocketServer(
                NetworkUtilities.GetIPv4Address(),
                port);

            clients = new Socket[maxConn];
        }
Пример #3
0
    /// <summary>
    /// Confirm the IP address retrieved isn't the
    /// loopback address.
    /// </summary>
    public void GetIpAddressTest()
    {
        const string localhost = "127.0.0.1";
        string       ip;

        Assert.AreNotEqual(localhost, ip = NetworkUtilities.GetIPv4Address());
        DebugUtilities.Log(TAG + ip);
    }
Пример #4
0
        public void ProcessFile(string path, string password, long totalSize)
        {
            var webPath = Settings.Get("WebServer").WebFilePath.ToString();

            var file = new FileInfo(path);

            file.Directory?.Create(); // If the directory already exists, this method does nothing.


            var fileName = Path.GetFileName(path);

            var ip       = NetworkUtilities.GetIPv4Address();
            var httpPort = HttpServer.GlobalPort;
            var data     = File.ReadAllBytes(path);

            var encryptedFile = _serializator.SerializeFile(_client, password, data);

            try
            {
                if (encryptedFile != null)
                {
                    var tempPath = Path.Combine(webPath + "temp\\", fileName);
                    File.WriteAllBytes(tempPath, encryptedFile);
                    var tempWebPath  = $"http://{ip}:{httpPort}/temp/{fileName}";
                    var downloadData = new
                    {
                        tempWebPath,
                        totalSize
                    };
                    _serializator.Serialize(_client, _packet.Endpoint, _packet.SyncKey, downloadData);
                }
                else
                {
                    var errorData = new
                    {
                        error   = true,
                        message = "Unable to encrypt file"
                    };
                    _serializator.Serialize(_client, _packet.Endpoint, _packet.SyncKey, errorData);
                }
            }
            catch (
                Exception e)
            {
                var exceptionData = new
                {
                    error   = true,
                    message = e.Message
                };

                _serializator.Serialize(_client, _packet.Endpoint, _packet.SyncKey, exceptionData);
            }
        }
        public static void Start()
        {
            AllClients     = new ConcurrentDictionary <string, AuthClient>();
            ApiControllers = new ConcurrentDictionary <string, ApiController>();
            var settings     = new Settings();
            var port         = settings.Read("TaskServer", "TaskServerPort", 8387);
            var cancellation = new CancellationTokenSource();
            var endpoint     = new IPEndPoint(IPAddress.Parse(NetworkUtilities.GetIPv4Address()), port);
            var server       = new WebSocketEventListener(endpoint);

            server.OnConnect    += HandleConnect;
            server.OnDisconnect += HandleDisconnect;
            server.OnMessage    += HandleMessage;
            server.OnError      += HandleError;
            server.Start();
            Log("Task TServer started at " + endpoint);
        }
Пример #6
0
        public static void Start()
        {
            var logger   = new Log4NetLogger();
            var sysinfo  = new SystemInfo();
            var endpoint = new IPEndPoint(IPAddress.Parse(/*NetworkUtilities.GetIPv4Address()*/ "0.0.0.0"), 22008);


            var server  = new WebSocketQueueServer(endpoint, sysinfo, logger);
            var manager = new ConnectionManager(server, logger, sysinfo);

            var cliFactories = new ICliSessionFactory[]
            {
                // creates cmd.exe sessions
                new CommandSessionFactory(logger),

                // creates powershell sessions
                new PowerShellFactory(logger)
            };

            server.Queue.SubscribeInstance(new CreateTerminalRequestHandler(manager, cliFactories, logger, sysinfo));
            server.Queue.SubscribeInstance(new CloseTerminalRequestHandler(manager, logger));
            server.Queue.SubscribeInstance(new InputTerminalRequestHandler(manager, logger));
            server.Queue.SubscribeInstance(new AesHandshakeRequestHandler(manager, logger));


            try
            {
                server.StartAsync();
                Console.WriteLine("Terminal Server bound to " + NetworkUtilities.GetIPv4Address() + ":" + 22008);
                Console.ReadKey(true);
                server.Dispose();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                Console.ResetColor();
            }

            Console.WriteLine("End.");
            Console.ReadKey(true);
        }