public void StartRemoteCLI() { if (_client.Connected) { using (DataStringPacket _packet = new DataStringPacket(_stream)) { _packet.data = Convert.ToString(Console.BufferWidth); _packet.SendPacket(_aes); _packet.ReceivePacket(_aes); CLIOutput.WriteToConsole(_packet.data + "\n"); } using (CLIPacket _cliP = new CLIPacket(_stream)) { _cliP.serverAnswer = ""; while (true) { // write cursor Console.ForegroundColor = ConsoleColor.Cyan; Console.Write(cursor); Console.ForegroundColor = ConsoleColor.White; // read input _cliInput = CLIInput.ReadInput(cursor.Length); if (_cliInput != "") { _cliP.consoleWidth = Console.BufferWidth; _cliP.cliInput = _cliInput; _cliP.SendPacket(_aes); _cliP.ReceivePacket(_aes); if (_cliP.serverAnswer == "EXIT_CLI") { break; } CLIOutput.WriteToConsole(_cliP.serverAnswer + "\n"); } } } } else { throw new Exception("Not connected!"); } }
public void Start() { CLIOutput.WriteToConsole(GetBanner(Console.BufferWidth) + "\n"); while (true) { Command _command = null; Console.ForegroundColor = _cursorColor; Console.Write(_cursor); Console.ForegroundColor = _inputColor; string _cliInput = CLIInput.ReadInput(Console.CursorLeft); string _response; // This is the old method to read input from cli. //string _cliInput = Console.ReadLine(); _cliInput = _cliInput.Trim(); if (_cliInput != "") { _response = CLIInterpreter(ref _command, _cliInput); if (_response == "VALID_PARAMETERS") { try { _response = _command.Execute(Console.BufferWidth); if (_response == "EXIT_CLI") { break; } } catch (Exception e) { _response = "<color><red>" + e.Message; } } CLIOutput.WriteToConsole(_response + "\n"); } } }
static int Main(string[] args) { IPAddress _serverIp = null; int _serverPort = 0; string _aesPass = null; if (args.Length != 0) { Program.CONFIG_FILE = args[0]; } try { if (File.Exists(Program.CONFIG_FILE)) { ConfigReader.ReadConfig(Program.CONFIG_FILE, out _serverIp, out _serverPort, out _aesPass); } else { ConfigReader.CreateConfig(Program.CONFIG_FILE); CLIOutput.WriteToConsole("<color><white>No config found.\n"); CLIOutput.WriteToConsole("<color><white>Creating default config at '" + Program.CONFIG_FILE + "'.\n"); CLIOutput.WriteToConsole("<color><white>Edit file as needed and start client ... \n"); CLIOutput.WriteToConsole("<color><gray>Press any key to close ...\n"); Console.ReadKey(false); return(0); } } catch (Exception e) { CLIOutput.WriteToConsole("<color><red>(ERROR) " + e.Message + "\n" + e.StackTrace); return(0); } CLIOutput.WriteToConsole("<color><yellow>" + "".PadLeft(Console.BufferWidth, '_') + "\n"); CLIOutput.WriteToConsole("<color><yellow>Address: <color><white>" + _serverIp.ToString() + "\n"); CLIOutput.WriteToConsole("<color><yellow>Port: <color><white>" + _serverPort + "\n"); CLIOutput.WriteToConsole("<color><yellow>Pass: <color><white>" + "".PadLeft(_aesPass.Length, '*') + "\n"); CLIOutput.WriteToConsole("<color><yellow>" + "".PadLeft(Console.BufferWidth, '_') + "\n"); CLIClient _client = new CLIClient(new IPEndPoint(_serverIp, _serverPort), _aesPass); try { _client.Connect(); _client.GetServerInfo(); CLIOutput.WriteToConsole("<color><yellow>SERVER-HEADER: <color><white>" + _client.serverHeader + "\n"); CLIOutput.WriteToConsole("<color><yellow>SERVER-VERSION: <color><white>" + _client.serverVersion + "\n"); CLIOutput.WriteToConsole("<color><yellow>" + "".PadLeft(Console.BufferWidth, '_') + "\n"); _client.StartRemoteCLI(); } catch (System.Security.Cryptography.CryptographicException) { CLIOutput.WriteToConsole("<color><red>(ERROR) Password wrong!\n"); } catch (Exception e) { CLIOutput.WriteToConsole("<color><red>(ERROR) " + e.Message + "\n"); } CLIOutput.WriteToConsole("<color><gray>\nPress any key to close ..."); Console.ReadKey(); return(0); }