Community discussions

 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

PHP SSH Script that works in v2.9 fails on v3

Tue Mar 25, 2008 10:56 am

I have this script that connects fine to version 2.9x router:
function routeros_Connect($host, $username, $password) {
    if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");    
    $methods = array ( 'kex' => 'diffie-hellman-group1-sha1' );
    $shell = ssh2_connect($host, 22, $methods);
    ssh2_auth_password($shell, $username, $password);
    return $shell;
}
But it fails on version 3.x. without any errors.

Any advice?
The Snowball Effect
Superior Internet Solutions
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5699
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: PHP SSH Script that works in v2.9 fails on v3

Tue Mar 25, 2008 11:19 am

try +ct options during login.
 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

Re: PHP SSH Script that works in v2.9 fails on v3

Tue Mar 25, 2008 4:22 pm

try +ct options during login.
Thank you for your reply.

I searched "man ssh" and all the documentation I could find on the PHP ssh2_connect function and cannot find any mention of a "+ct" option. What exactly is "+ct"?

Incidentally the problem appears not the connection, it's connecting fine and there are no errors, it's just that any commands I subsequently run with:
function routeros_SendCommand($shell, $command) {
    $stream = ssh2_exec($shell, $command);
    stream_set_blocking( $stream, true );
    $data = "";
    while( $buffer = fread($stream, 4096) ) {
    	$data .= $buffer;
    }
    fclose($stream);
    return $data;
}
does not work. However as I said this works perfectly fine with version 2.9.
The Snowball Effect
Superior Internet Solutions
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5699
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: PHP SSH Script that works in v2.9 fails on v3

Tue Mar 25, 2008 5:12 pm

when you log in add +ct to username.
For example if username is "admin" then log in with name "admin+ct" this will disable console colors and terminal detection.
 
galaxynet
Long time Member
Long time Member
Posts: 643
Joined: Fri Dec 17, 2004 2:52 pm
Contact:

Re: PHP SSH Script that works in v2.9 fails on v3

Tue Mar 25, 2008 7:13 pm

eugenevdm -
What mrz means is for you add " +ct " to your login name in your linux script.

If the commands you are trying to run are not working via the output of your script - I suggest that you try the commands in terminal mode on your MT router and see what is not working. There are a few command differences in ROS v3.x over ROS v2.9.xx ........

R/
Thom Lawless
General Manager
RapidWiFi, LLC
thom.lawless [at] rapidwifi.com
 
User avatar
eugenevdm
Member Candidate
Member Candidate
Topic Author
Posts: 208
Joined: Tue Jun 01, 2004 12:23 pm
Location: Stellenbosch, South Africa
Contact:

Re: PHP SSH Script that works in v2.9 fails on v3

Wed Mar 26, 2008 8:46 am

Thank you for your responses.

It appears the problem was syntax related. The reason why I couldn't see the syntax error is because Mikrotik is not reporting anything in it's logs when you log on programmatically using SSH.

On version 2.9 you can see the user logging in by observing the log file.
On version 3.x you cannot see the user logging in even though the user is logged in. When you cause an error nothing shows (in the log).

The syntax error is:

In version 2.9 you can do this:
/interface wireless access-list set [find mac-address=\"$client_mac_address\"] comment = \"$comment\"";

In version 3.x you have to do remove the "=":
/interface wireless access-list set [find mac-address=\"$client_mac_address\"] comment \"$comment\"";

Luckily the version 3.x syntax is backwards compatible with the version 2.9 syntax.
The Snowball Effect
Superior Internet Solutions
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5699
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: PHP SSH Script that works in v2.9 fails on v3

Wed Mar 26, 2008 10:36 am

It seems that in v3 comment="comment" is valid syntax, but comment = "comment" is not.

Who is online

Users browsing this forum: No registered users and 2 guests