im trying to purge single url on cloudflare ,
this is my bash script
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: $0 http://your.domain.com/url"
exit 0
fi
#get this from Account section in Cloudflare
TOKEN="SECRETTOKEN"
EMAIL="EMAIL"
DOMAIN="DOMAIN"
curl -s https://www.cloudflare.com/api_json.html \
-d "a=zone_file_purge" \
-d "tkn=$TOKEN" \
-d "email=$EMAIL" \
-d "z=$DOMAIN" \
-d "url=$1" >> test.log #output to check if this script work
and my php script
<?php
$domain = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
$actual_link = $_SERVER[HTTP_REFERER];
exec("/bin/bash /path/to/bkl.sh $actual_link");
echo "Success";
header('Refresh: 5; URL=' . $_SERVER['HTTP_REFERER']);
?>
method : i put a button on my website , so when user click on that button it will execute bash script on the server and purge the post url on cloudflare , and after that visitor will be redirect back to the post.
when i manually test bash script in my ssh it work perfectly and the test.log has result "SUCCESS"
but when i run php script on my website the test.log does not generate any output which mean its fail.
thank you hope someone can give me a better solution.
Related
I am deliberately trying to write a simple script which permanently checks a Website for a certain string and sends an Email as soon as the page gets updated and contains the string.
I managed most of the task so far, only it doesn't work on my intended website. (Works on simple ones though).
I figured it might have to do with Cookies or JavaScript.
Heres my Code:
#!/bin/bash
USERNAME="username"
PASSWORD="passwd"
URL="https://tickets.fcbayern.com/internetverkauf/EventList.aspx"
#!/bin/bash
echo "before"
for (( ; ; ));
do
count=`curl -s "https://tickets.fcbayern.com/internetverkauf/EventList.aspx" | grep -c "Ausverkauft"`
if [ "$count" != "0" ]
then
echo "Found Text"
sendEmail -f $USERNAME -s smtp.gmail.com:587 \
-xu $USERNAME -xp $PASSWORD -t $USERNAME \
-o tls=yes -u "Web page changed" \
-m "Visit it at $URL"
sleep 5
fi
echo "ende"
done
The intention is to check if
the site contains "Ausverkauft" or "sold out" (english version)
then send an email
if not repeat check after 5 seconds
Would be amazing if you could help me.
Testing the script on simple sites worked fine!
Thanks a lot!
I have a bash script on a cronjob.
do
curl -d "test=working" https:/mysite.com/test
echo "done"
done
Right now, it just makes a post request on my site.
But now I want to make a post request in a members only area 2 times
So how can I login keep the session, and post 2 times?
I can't test this as I'm on my phone for a while but it's been bugging me.
do
curl -d "uname=a&pass=b" https:/mysite.com/login
for run in {1..2}
do
curl -d "test=working" https:/mysite.com/memberarea
echo "done"
done
Would this work?
you can use the cookies:
curl -b cookies.txt -c cookies.txt -e website.com -d 'xx=yy' http://website.com/path/to/resource
The -b(--cookie) means use the cookie from cookies.txt,
and the -c(--cokie-jar) means dumps the cookie to cookies.txt.
so always add the two option when use curl in your script and so that you can keep the session.
FYI:
do
curl -b cookies.txt -c cookies.txt -e mysite.com -d "uname=a&pass=b" https:/mysite.com/login
for run in {1..2}
do
curl -b cookies.txt -c cookies.txt -e mysite.com -d "test=working" https:/mysite.com/memberarea
echo "done"
done
If your website uses cookie for keeping authenticated session, you can use --cookie name=data to pass the authentication username and password and use --cookie-jar <filename> to store the cookie.
I have a PHP script that starts a detached screen through SSH:
$ssh->exec("screen -m -d -S ".$user);
I now need to execute a command in that screen without being in that screen. I have the code that does that, which I have tested through a SSH client, but when I try to use it with the phpseclib exec command, it does not work. This is the code that works:
screen -S ".$user." -X stuff "cd minecraft/servers/".$user."/;sh start.sh $(printf '\r')"
And this is it in the PHP script:
$ssh->exec("screen -S ".$user." -X stuff \"cd minecraft/servers/".$user."/;sh start.sh $(printf '\r')\"");
I attempted to escape the extra double quotes in the code.
Is there anything I can do to make this work through PHP? Thanks
Hmmm...
create please two bash script, first: create screen with user parameter with name f.e. run_screen, second: tester for SSH client with user parameter with name f.e. run_test.
Run first script:
$ssh->exec('[full_path]/run_screen ' . $user);
and second:
$ssh->exec('[full_path]/run_test ' . $user);
bash syntax is here bash syntax
Sure that the user of server (f.e. Apache) has permissions to run scripts.
I am trying to setup a web-based portal through which we can checkout different branches of our Git repository through a simple click on a back-end panel.
So currently, I have /var/www/devportal which contains index.php, status.sh and checkout.sh
In index.php I do the following:
$repo = $_GET['repo'];
$command = 'sh status.sh ' . $repo;
$output = exec($command);
echo "<pre>$output</pre>";
The contents of status.sh are:
#!/bin/bash -e
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` <repo name>"
exit 1
fi
cd /var/www/$1
git status
And this works just fine. The output echoed in PHP shows me the status of the current branch within /var/www/proj.
Now when I try to do the same thing (passing 2 parms this time with the second one being the name of the branch to checkout) with checkout.sh, who'se contents are:
#!/bin/bash -e
if [ $# -ne 2 ]
then
echo "Usage: `basename $0` <repo name> <branch name>"
exit 1
fi
cd /var/www/$1
git checkout $2
It doesn't work. Not only does it not work, I don't get diddly squat for an error message. There is no output. I know that the checkout.sh script works fine because when I echo the command that is being sent via PHP's exec command, copy that exact thing and run it via terminal logged in as root, it works just fine, does the checkout and returns the name of the newly activated branch.
Any tips on this would be greatly appreciated. My box is pretty standard, Ubuntu 10.04 and running Apache2.
Thanks!
exec fills $output with your command standart output, to show error (if any) add "2>&1" at the end of your command.
exec can also tell you the return value, try:
$output = exec($command, $array_output, $ret_val);
var_dump($ret_val);
echo "<pre>$output</pre>";
$repo = $_GET['repo'];
$command = 'sh status.sh ' . $repo;
$output = exec($command);
Oh jesus man. Don't do this. escapeshellarg exists for a reason
I have a little script that I'm trying to run but it dies at exec()
<pre><?php
ini_set("display_errors", 1);
$command = "wget --save-cookies cookies.txt \
--post-data '***' \
--keep-session-cookies \
http://site.com/ac_login.php;
wget --load-cookies cookies.txt \
--keep-session-cookies \
-p http://site.com/ac_landing.php;";
exec($command, $output) or die('fail');
foreach ($output as $num => $line) {
echo $num + 1 . ": " . $line . "\n";
}
?></pre>
If I remove the \ at the end of each line I get a response of
1: wget: missing URL
2: Usage: wget [OPTION]... [URL]...
3:
4: Try `wget --help' for more options.
5: wget: missing URL
6: Usage: wget [OPTION]... [URL]...
7:
8: Try `wget --help' for more options.
I tried moving all the commands to one line but then it dies again. What am I doing wrong? How can I retrieve the error in this script? Adding in a 3rd param for result in exec returns empty.
I'm using this for reference https://stackoverflow.com/a/1432161/763468
The commands work in an SSH console.
First off, I don't think you need that semi-colon after the file name
-p http://site.com/ac_landing.php;
to
-p http://site.com/ac_landing.php
Did you try one command per exec call?
exec("wget --save-cookies cookies.txt --post-data '***' --keep-session-cookies http://site.com/ac_login.php");
exec("wget --load-cookies cookies.txt --keep-session-cookies -p http://site.com/ac_landing.php");