Topic: Access FA from curl/wget

Hi

I need to add to FA some pages which I want to access not from a Web browser but from curl/wget.
Those pages are some kind of report which I probably could do in pure SQL but that would be safer to the php code from FA.
For example  I need a csv with a price list, and ideally I would go something line
   

wget www.fa.com/price_list.csv

The problem is I need to create a session or something. Is there a to "disable" session for certain page (I don't really care about security, I would even be happy to just do

php price_list.csv.php > price_list.csv

from the current on FA directory (on the localhost)

But I have still this problem of session.
So the question, how can I write a php page which can include all FA db settings, and access to its functions, without having to use session (or is there a way to emulate this session somehow)

/Elax

Re: Access FA from curl/wget

found it:

curl -F 'user_name_entry=<username>' -F 'password=<password>' -F 'company_login_name=<company number>' url

This allow to log at every request.
Too keep a session alive (easier for manual request) use, the -c and -b option of curl.

 curl -c my_session -F 'user_name_entry=<username>' -F 'password=<password>' -F 'company_login_name=<company number>' url 

for the first time
then

 curl -b my_session url

(reuse the cookie stored in my_session.

Re: Access FA from curl/wget

My mistake, is `user_name_entry_field` not `user_name_entry`.

4 (edited by apmuthu 12/13/2012 10:18:24 am)

Re: Access FA from curl/wget

Thanks #elax.

Wikiied it with source for field names taken from access/login.php.

This is a nice tute for cURL usage from the CLI !

Re: Access FA from curl/wget

Thanks apmuthu. Just be aware that price_list.csv is not part of front accounting (yet?) but it's an example of a report returning a CSV. You might be able to download that way a proper FA report by setting the appropriate parameters specific to the report, but I haven't tried it.

/Elax

Re: Access FA from curl/wget

Wiki stands updated. Thanks elax.

Re: Access FA from curl/wget

FA 2.4.x now has a few hidden fields in the login form apart from the ones listed in @elax previous post:

<input id="ui_mode" name="ui_mode" value="1" type="hidden">
..
..
<input name="_focus" value="user_name_entry_field" type="hidden">
<input name="_modified" value="0" type="hidden">
<input name="_confirmed" value="" type="hidden">
<input name="_token" value="iwyLHJUcoMkfRv8-ZpBQVwxx" type="hidden">

The _token field will come up on calling the login form and must be parsed out and submitted with the field values in cURL.

TOKENCODE=`curl -c my_session http://localhost/frontac24/ | sed -ne '/name="_token"/s/.*value="\([^"]*\)".*/\1/p'`

The following would log you in where your admin user's password is "secret":

curl -c my_session \
      -F 'user_name_entry_field=admin' \
      -F 'password=secret' \
      -F 'company_login_name=1' \
      -F 'ui_mode=1' \
      -F 'modified=0' \
      -F 'confirmed=1' \
      -F "_token=${TOKENCODE}" \
      -F '_focus=user_name_entry_field'  \
      http://localhost/frontac24/ > logged_in_page.txt

The file "logged_in_page.txt" will contain the html code for the FA's logged in page.

To study the parameters required for the Sales Summary Report:

curl -b my_session \
     -F 'Class=0' \
     -F 'REP_ID=114' \
     http://localhost/frontac24/reporting/reports_main.php > report_form.txt

To get the Sales Summary Report:

curl -b my_session \
     -F 'REP_ID=114' \
     -F 'PARAM_0=01/01/2015' \
     -F 'PARAM_1=10/31/2017' \
     -F 'PARAM_2=0' \
     -F 'PARAM_3=AutoSalesSummaryReport' \
     -F 'PARAM_4=0' \
     -F 'PARAM_5=0' \
     -F 'Class=0' \
     http://localhost/frontac24/reporting/rep114.php > Sales_Summary_Report.pdf

Now to logout:

curl -b my_session http://localhost/frontac24/access/logout.php? > logged_out_page.txt

The "logged_out_page.txt" will contain the html code for the logged out page.