Log in to cacti from shell script

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
Ramirocuei
Posts: 6
Joined: Sat Apr 06, 2019 10:08 pm

Log in to cacti from shell script

Post by Ramirocuei »

Hello.

I'm trying to log in to my cacti server from a shell script (to export graph's csv) but i cant seem to get it working..

Cacti server has built in auth enabled.
I have tried using wget with next params:

wget --posta-data 'action=login&login_username=$USER&login_password=$PASS' --keep-session-cookies --save-cookies=cookies.txt http://my.server/cacti/

wget --load-cookies=cookies.txt $CVS_URL -O myfile

all i get is the login page..

thank you in advance for any help..

Regards,
Ramiro.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Log in to cacti from shell script

Post by netniV »

The problem will be that you are posted within the CSRF token. That will prevent you from doing so to stop CSRF attacks.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Ramirocuei
Posts: 6
Joined: Sat Apr 06, 2019 10:08 pm

Re: Log in to cacti from shell script

Post by Ramirocuei »

netniV wrote:The problem will be that you are posted within the CSRF token. That will prevent you from doing so to stop CSRF attacks.
Hello @netniV, thank you for your response.

I found out that commenting lines that refer to CSRF in global.php solve the problem, but I'm sure this is not the safest way to go..

What would be the correct way to achieve this and bypass the login page? is it possible using wget or curl?

Thank you very much.

Ramiro.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Log in to cacti from shell script

Post by netniV »

If you are using Cacti 1.1.20 or later, you can utilise my tokenauth plugin which allows you to generate a daily token to be used on a GET instead of a POST. That then bypasses the CSRF check since there is no posted data.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Ramirocuei
Posts: 6
Joined: Sat Apr 06, 2019 10:08 pm

Re: Log in to cacti from shell script

Post by Ramirocuei »

netniV wrote:If you are using Cacti 1.1.20 or later, you can utilise my tokenauth plugin which allows you to generate a daily token to be used on a GET instead of a POST. That then bypasses the CSRF check since there is no posted data.
Hello netniV, my bad i havent posted my cacti version. We use version 0.8.8g.

Is there any compatible version of the plugin for this deployment?

thanks.
Ramiro.
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Log in to cacti from shell script

Post by netniV »

I have never used anything lower than 1.1 so it could probably be made to work but I wouldn't be sure how.
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
netniV
Cacti Guru User
Posts: 3441
Joined: Sun Aug 27, 2017 12:05 am

Re: Log in to cacti from shell script

Post by netniV »

There again, it may rely on hooks only available in later versions of cacti...
Cacti Developer & Release Manager
The Cacti Group

Director
BV IT Solutions Ltd

+--------------------------------------------------------------------------+

Cacti Resources:
Cacti Website (including releases)
Cacti Issues
Cacti Development Releases
Cacti Development Documentation
Ramirocuei
Posts: 6
Joined: Sat Apr 06, 2019 10:08 pm

Re: Log in to cacti from shell script

Post by Ramirocuei »

netniV wrote:There again, it may rely on hooks only available in later versions of cacti...
OK, thank you very much for all your help!

Ramiro.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest