How to pass usernm/psswd to pfsense - Generating Sarg reports from Shell script



  • Hi All,

    I've already read a lot trying to figure this out, but with no Luck.
    This is what I have till now;

    I have pfsense 2.0.3 installed, I installed SARG. I'm trying to generate the daily usage report from command link to create a script that will make use of it.
    SARG is working fine from the browser

    After reading I found out that pfsense 2.0.x requires a special method to pass the username and password and it's a 2 stage, which looks something like this

    wget -q -O /dev/null –keep-session-cookies --save-cookies cookies.txt
    --post-data "login=Login&usernamefld=admin&passwordfld=mypassword"
    --no-check-certificate http://10.0.1.5/sarg_reports.php

    wget --keep-session-cookies --load-cookies cookies.txt
    http://10.0.1.5/sarg_reports.php --no-check-certificate

    After that I run

    /usr/local/bin/links -dump sarg_reports.php

    and I keep getting


    Username:
      _____________________

    Password:
      _____________________

    Enter username and password to login.

    [ Login ]
    –------------------------------------

    I tried different options with no Luck, Pls help

    Regards



  • Have you tried passing the username and password via the wget?

    –http-user=your-username --http-password=your-password



  • Yes, that didn't work either  :(



  • For those who are interested, I found the solution

    The first wget should call the main login page of pfsense not the required link, the second wget will call the required link.

    wget -q -O /dev/null –keep-session-cookies --save-cookies cookies.txt
    --post-data "login=Login&usernamefld=admin&passwordfld=mypassword"
    --no-check-certificate http://10.0.1.5

    wget --keep-session-cookies --load-cookies cookies.txt
    http://10.0.1.5/sarg_reports.php --no-check-certificate



  • I'm re-opening this topic  :(

    After I upgraded to pfsense 2.1 the above solution is not working anymore. has anything changed ???

    Now, I'm getting the following

    wget –keep-session-cookies --save-cookies cookies.txt
    --post-data 'login=Login&usernamefld=admin&passwordfld=pfsense' "http://10.0.0.5/sarg_reports.php"
    -O User_Acess_Report.dmp --no-check-certificate  --2013-10-10 14:46:49--  http://10.0.0.5

    Connecting to 10.0.0.5:80... connected.
    HTTP request sent, awaiting response... 403 Forbidden
    2013-10-10 14:46:49 ERROR 403: Forbidden.

    HELP



  • I have the same error

    
    wget --keep-session-cookies --save-cookies cookies.txt  --post-data 'login=Login&usernamefld=admin&passwordfld=#abc@123@'  --no-check-certificate http://172.30.34.254/status_dhcp_leases.php
    --2013-10-17 23:53:39--  http://172.30.34.254/status_dhcp_leases.php
    正在連接 172.30.34.254:80... 連上了。
    已送出 HTTP 要求,正在等候回應... 403 Forbidden
    2013-10-17 23:53:39 錯誤 403: Forbidden。
    
    


  • Anybody. HELP



  • X.Z. Did you find a solution???



  • Hi guys!

    Why not use plink if youre doing it from windows machine?

    Plink here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
    Example config:

    @echo off
    echo yes | C:\Tools\Putty\plink.exe -ssh -P SSH_PORTNUMBER -pw MYPASSWORD root@MYPFSENSEIPADDRESS "exit"
    C:\Tools\Putty\plink.exe -ssh -P SSH_PORTNUMBER -pw MYPASSWORD root@MYPFSENSEIPADDRESS "/usr/local/bin/php /usr/local/www/sarg.php 0"
    

    second line will auto accept host certificate, second line will execure sarg report…



  • Thanks Maverick

    But I'm using Linux not windows.



  • Hello, everyone.

    I too have noticed that version 2.1 has broken my old reconnection scripts. The login method shown in the documentation page for the config backup script apparently no longer works, and while using plink may still be a valid solution I'm not using Windows either (and if at all possible I'd like to stick to bash and wget/curl).

    So I'd like to have some help here, and it would be nice if the documentation got fixed as well.

    Thanks.


Log in to reply