This project is read-only.

Fortigate 1500D CLI issue

Oct 2, 2015 at 12:48 PM
Hi,

i try to run command on our fortigate 1500D firewall CLI environment ( somethin about web rating overrides)

string command = ssh.CreateCommand("config webfilter ftgd-local-rating").Execute();
first command return correct result from CLI it says:
                             #(ftgd-local-rating)
after that i want to run this command but , it loose shell handle or smt else, i think
                command += ssh.CreateCommand("edit \"http:somesite\").Execute();
it return "unknown action". i think, it creates a new shell handle.

how can i fix this. tamir's sharp thing achieve this. but most of system algorithm doesn't support anymore.


Thanks in advance.
Oct 9, 2015 at 12:17 PM
use shell stream and works

https://sshnet.codeplex.com/discussions/348421
            using (var client = new SshClient("xx.xx.xx.xx", "user", "password"))
            {
                client.Connect();

                using (var stream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024))
                {
                    var reader = new StreamReader(stream);
                    var writer = new StreamWriter(stream);
                    writer.AutoFlush = true;

                    while (stream.Length == 0)
                    {
                        Thread.Sleep(500);
                    }
                    ReadStream(reader);

                    WriteStream("config webfilter ftgd-local-rating", writer, stream);
                    ReadStream(reader);

                    WriteStream("edit \"" + Request.QueryString["p"].ToString() + "\"", writer, stream);
                    ReadStream(reader);

                    WriteStream("set rating 123", writer, stream); -->rating number is sample form.
                    ReadStream(reader);

                    WriteStream("next", writer, stream);
                    ReadStream(reader);

                    WriteStream("end", writer, stream);
                    ReadStream(reader);

                    WriteStream("end", writer, stream);
                    ReadStream(reader);

                    WriteStream("exit", writer, stream);
                    ReadStream(reader);
                }
                client.Disconnect();                    
            }

private void ReadStream(StreamReader reader)
    {
        string line = reader.ReadLine();
        while (line != null)
        {
            Console.WriteLine(line);
            line = reader.ReadLine();
        }
    }

    private  void WriteStream(string cmd, StreamWriter writer, ShellStream stream)
    {
        writer.WriteLine(cmd);
        while (stream.Length == 0)
        {
            Thread.Sleep(500);
        }
    }