Skip to content

Instantly share code, notes, and snippets.

@mohamedelhabib
Created July 6, 2014 04:41
Show Gist options
  • Select an option

  • Save mohamedelhabib/31eaacf9d3106fd9a1ae to your computer and use it in GitHub Desktop.

Select an option

Save mohamedelhabib/31eaacf9d3106fd9a1ae to your computer and use it in GitHub Desktop.
#!/bin/sh
####################### PRESTASHOP PARAM #######################
urladminsite=http://prestashop.domain.com/adminxxx/ # prestashop admin url
[email protected] # admin login
passwd=password # admin password
adminController=AdminPdf # the controller to call after login
adminControllerParam='&submitAction=generateInvoicePDF&id_order=250'
cookieFilePath=/tmp/cookie.txt # path of the cookie file that will be created
####################### IDENTIFICATION #######################
# login and get cookie
rm /tmp/login.php
rm $cookieFilePath
wget -q --save-cookies=$cookieFilePath --post-data='ajax=1&token=&redirect='$adminController'&controller=AdminLogin&submitLogin=1&passwd='$passwd'&email='$email --keep-session-cookies -O /tmp/login.php $urladminsite'ajax-tab.php'
if [ -n "$(grep 'errors' /tmp/login.php)" ]
then
error=$(grep 'errors' /tmp/login.php | sed 's/.*\["\(.*\)"\].*/\1/g')
echo 'Login KO : '$error
exit
else
echo 'Login OK ...'
token=$(grep 'redirect' /tmp/login.php | sed 's/.*token=\(.*\)".*/\1/g')
echo 'TOKEN : '$token # print token
if [ -z "$(echo $token | grep ^[a-z0-9]*)" ]
then
echo 'ERROR : no token'
exit
fi
fi
####################### Do action after login #######################
wget -q -O result.pdf --load-cookies=$cookieFilePath --keep-session-cookies $urladminsite'index.php?token='$token'&controller='$adminController$adminControllerParam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment