Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Results of all command doesnt Shows up #103

Closed
harajukakei opened this issue Feb 3, 2020 · 6 comments
Closed

Results of all command doesnt Shows up #103

harajukakei opened this issue Feb 3, 2020 · 6 comments
Assignees
Labels

Comments

@harajukakei
Copy link

I'm having an error which all the commands entered doesnt resulting anything. If debugging the browser, i'm having this issues.

Uncaught SyntaxError: Unexpected token < in JSON at position 0 at Function.parse [as parseJSON] (<anonymous>) at Object.<anonymous> (looking-glass.js:94) at c (jquery-3.4.1.min.js:2) at Object.fireWith [as resolveWith] (jquery-3.4.1.min.js:2) at l (jquery-3.4.1.min.js:2) at XMLHttpRequest.<anonymous> (jquery-3.4.1.min.js:2)

Using FreeBSD 12.1-p1 with PHP 7.2 and Apache 2.4

@gmazoyer
Copy link
Owner

gmazoyer commented Feb 3, 2020

Please provide relevant information such as:

  • Configuration file (without passwords)
  • Logs from the HTTP server and/or PHP process when encountering the issue

@harajukakei
Copy link
Author

apache only shows this error :

[Mon Feb 03 18:23:03.023132 2020] [php7:warn] [pid 5004] [client 172.16.17.1:44015] PHP Warning: Use of undefined constant NET_SSH2_LOG_COMPLEX - assumed 'NET_SSH2_LOG_COMPLEX' (this will throw an Error in a future version of PHP) in /usr/local/www/apache24/lglass/auth/ssh.php on line 43, referer: https://xxxxxx/
this is the content of our config.php
`<?php

/*

  • Main configuration file example.
  • DO NOT EDIT NOR RENAME, please copy to 'config.php' and edit the new file!
    */

// People to contact
// Set both to null to not display any contact information
$config['contact']['name'] = '';
$config['contact']['mail'] = '';

// Frontpage configuration

// Title of the page
$config['frontpage']['title'] = 'LG';
// Logo to display (remove it to not display any logo)
$config['frontpage']['image'] = '';
// Disclaimer to inform people using the looking glass
// Set it to null to not display a disclaimer
$config['frontpage']['disclaimer'] = '';

// Things to remove from the output (PHP compatible regex)
//$config['filters']['output'][] = '/(client1|client2)/';
//$config['filters']['output'][] = '/^NotToShow/';
// Matched patterns can also replaced inline
//$config['filters']['output'][] = ['/replacethis/', 'withthis'];

// If telnet is used in combination with extreme_netiron, uncomment the following filter
//$config['filters']['output'][] = '/([^\x20-\x7E]|User|Please|Disable|telnet|^\s*$)/';

// Google reCaptcha integration
$config['recaptcha']['enabled'] = false;
$config['recaptcha']['apikey'] = 'foobar';
$config['recaptcha']['secret'] = 'foobar';

// Routers definitions

// Authentication based on SSH or Telnet with password
// The hostname or the IP address
$config['routers']['router1']['host'] = '';
// The user to use to connect to the router
$config['routers']['router1']['user'] = 'lglass';
// The password of the given user
$config['routers']['router1']['pass'] = '';
// The authentication mechanism to use (can be ssh-password or telnet)
$config['routers']['router1']['auth'] = 'ssh-password';
// The router type (can be cisco, ios, juniper or junos)
$config['routers']['router1']['type'] = 'vyatta';
// The router source interface to be used
$config['routers']['router1']['source-interface-id'] = 'lo0';
// The router description to be displayed in the router list
$config['routers']['router1']['desc'] = 'SKY-JKT-NXT RS1';

// If running on *BSD, disable '-A' which is non-existent
$config['tools']['ping_options'] = '-c 5';
// If running on *BSD, disable '-N' which is non-existent
$config['tools']['traceroute_options'] = '-A -q1 -w2 -m15';
// If running on *BSD, there is no '-4' or '-6'
$config['tools']['traceroute6'] = 'traceroute6';
$config['tools']['traceroute4'] = 'traceroute';
$config['output']['show_command'] = true;
$config['logs']['file'] = '/var/log/looking-glass.log';
$config['logs']['format'] = '[%D] [client: %R] %H > %C';
$config['logs']['auth_debug'] = true;
$config['output']['show_command'] = true;
// End of config.php
`

@gmazoyer
Copy link
Owner

gmazoyer commented Feb 4, 2020

There is nothing wrong given what you just provided. Are you able to see the command sent to your router in the logs of it?

@rfdrake
Copy link

rfdrake commented Apr 16, 2020

I've had a couple of similar issues. One I'm still tracking down, but another I found to be a configuration problem.

In certain cases the response from execute.php isn't going to be JSON. You can see what it's returning by right-click and hitting "Inspect Element" (firefox) or right-click and hitting "Inspect" in chrome.

From there it varies how to find the information, but the basics are to click on the "Network" tab and then click the "execute.php" request, then look at the data for a "Response" object.

Here is the config error that I had:

Unknown authentication mechanism ""."
Fatal error: Uncaught Error: Call to a member function send_command() on null in /var/www/html/routers/router.php:209 Stack trace: #0 /var/www/html/execute.php(100): Router->send_command('ping', '8.8.8.8') #1 {main} thrown in /var/www/html/routers/router.php on line 209

Hope this helps you narrow it down.

@neilschelly
Copy link

If you have auth debug enabled, you'll see the error about NET_SSH2_LOG_COMPLEX being undefined because it's used here: https://github.com/respawner/looking-glass/blob/master/auth/ssh.php#L43

If you add include('libs/phpseclib-2.0.23/Net/SSH2.php'); to the top of that file, that constant will then be defined and usable. This appears not to fix the issue with the results of the command not showing up though. I don't get any more useful logging out of the SSH layer with that in place.

I think the issue with output is probably the same as #138. I'm just running the docker container with a simple configuration, and I can see the responses I get to execute.php look like:

<br />
<b>Notice</b>:  Connection closed prematurely in <b>/var/www/html/libs/phpseclib-2.0.23/Net/SSH2.php</b> on line <b>3901</b><br />
{"result":"<p><kbd>Command:  show bgp ipv4 unicast 8.8.8.8<\/kdb><\/p><pre class=\"pre-scrollable\">Load for five secs: 1%\/0%; one minute: 3%; five minutes: 3%\r\nTime source is NTP, 13:19:06.890 EDT Wed Oct 7 2020\r\nBGP routing table entry for 8.8.8.0\/24, version 239020342\r\nBGP Bestpath: deterministic-med\r\nPaths: (3 available, best #3, table default)\r\n  Advertised to update-groups:\r\n     2         \r\n  Refresh Epoch 1\r\n  58511 15169, (received-only)\r\n    163.47.50.1 from 163.47.50.1 (103.247.3.101)\r\n      Origin IGP, localpref 100, valid, external\r\n      Community: 58511:300 58511:9002\r\n      rx pathid: 0, tx pathid: 0\r\n  Refresh Epoch 2\r\n  58511 15169, (received-only)\r\n    163.47.50.101 from 163.47.50.101 (103.247.3.36)\r\n      Origin IGP, metric 0, localpref 100, valid, external\r\n      Community: 58511:300 58511:9002\r\n      rx pathid: 0, tx pathid: 0\r\n  Refresh Epoch 1\r\n  27552 15169\r\n    185.134.180.117 from 185.134.180.117 (198.160.63.172)\r\n      Origin IGP, metric 20051, localpref 100, valid, external, best\r\n      Community: 27552:57022\r\n      rx pathid: 0, tx pathid: 0x0<\/pre>"}

The UI fails to show anything as a result of the command because it tries to parse that as JSON at https://github.com/respawner/looking-glass/blob/master/js/looking-glass.js#L94. You can see it failing to parse that in the browser console. It probably should be able to catch a non-JSON response and present that as an error by itself.

I've been unable to track down why the Connection closed prematurely is cropping up yet. I suspect that's the key to resolving the actual problem. It's clear from my case at least that the software was able to quickly login to my router, run the command, etc. It has the output even that I'd expect of the command in the response above.

@neilschelly
Copy link

I found a workaround that works for me.... Since the output was showing up in the responses I got and only the PHP warning was what was breaking the JSON parser, I disabled PHP warnings from showing up in the output.

I added php_flag display_errors off to the top of .htaccess, and now it works.

@neilschelly neilschelly mentioned this issue Oct 7, 2020
@gmazoyer gmazoyer self-assigned this Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants