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!
Related
On a local linux server (Rapsberry Pi debian stretch with desktop), I am working on sending "audtool" commands to a running Audacious media player using php, exec and bash scripts. Audacious is autostarted when the server starts up with user "pi". I have apache2 and php set up and working on the server, and I can ssh to the server and run all the commands from the cli. I believe I have resolved the issues with running audtool (dbus and setting the right environment variables) and running the php on the command line works successfully. However when running the php on a webpage I get back a long string of information about apache2
I have spent several hours (getting on for a whole day) researching this on the web in order to get to this stage, so close I can almost touch it, but stuck on this last element. The example is to display the current song from a running instance of Audacious. Audtool requires a running dbus (looks for a display). Using exec or shell_exec I have no problems running bash commands such as whoami or ls.
The php page (cursong.php):
<?php
echo exec('/var/www/html/cursong.sh');
?>
The bash script (cursong.sh):
#!/bin/bash
##call current song
pid=`pidof audacious`
user=`ps -p $pid -o user=`
export `strings /proc/$pid/environ | grep DBUS_SESSION_BUS_ADDRESS`
sudo -E -su $user /usr/bin/audtool --current-song
(from here: https://redmine.audacious-media-player.org/boards/1/topics/1058?r=1059)
Output from command line:
php -f cursong.php
Artist - Song Title (for example - so this works)
Output on webpage:
declare -x APACHE_LOCK_DIR="/var/lock/apache2" declare -x
APACHE_LOG_DIR="/var/log/apache2" declare -x
APACHE_PID_FILE="/var/run/apache2/apache2.pid" declare -x
APACHE_RUN_DIR="/var/run/apache2" declare -x APACHE_RUN_GROUP="www-
data" declare -x APACHE_RUN_USER="www-data" declare -x
INVOCATION_ID="4ce76136ca8842bd9108d6b1b9a5b9ed" declare -x
JOURNAL_STREAM="8:23896" declare -x LANG="C" declare -x OLDPWD
declare -x
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
declare -x PWD="/var/www/html" declare -x SHLVL="1"
I have set www-data, the apache2 user with the following in
/etc/sudoers:
www-data ALL=NOPASSWD: ALL
and /var/www/html is rwx for anyone
Obviously, I am expecting to see "Artist - Song Title" on the webpage, but instead I get back all the apache2 info. What am i missing, or where have I gone wrong?
I hate answering my own question, makes it look like I wasn't trying hard enough! After a further five hours or so of searching around and attempting fixes, I happened upon this post on SO:
Running command-line application from PHP as specific user
which suggested putting a "sudo -u user" in the exec of the php file. I tried this with the "pi" user and it still didn't work, then I simply tried it with "sudo" and hey presto!!
The php file now looks like this:
<?php
echo shell_exec('sudo /var/www/html/cursong.sh 2>&1');
?>
Now to do some testing on how it works with the other audtool commands that don't ask for a response but require action from audacious, and to see how I can reduce scripting php files by passing a parameter to the bash script!
Just for completeness, the php and bash scripts for both a request and an action, using a parameter fed to the php url and then on to the bash script:
PHP File with Parameter
<?php
$request = $_GET["request"];
echo shell_exec("sudo /var/www/html/cursong.sh \"${request}\" 2>&1");
?>
url example:
http://192.168.1.92/cursong.php?request="--playlist-shuffle-status"
Bash Script with parameter
#!/bin/bash
##call request
pid=`pidof audacious`
user=`ps -p $pid -o user=`
export `strings /proc/$pid/environ | grep DBUS_SESSION_BUS_ADDRESS`
sudo -E -su $user /usr/bin/audtool $1
PHP file for an action
<?php
$action = $_GET["action"];
shell_exec('sudo /var/www/html/playsong.sh \"${request}\" ');
?>
url example:
http://192.168.1.92/cursong.php?action="--playback-play"
Bash script for an action
#!/bin/bash
##call action
pid=`pidof audacious`
user=`ps -p $pid -o user=`
export `strings /proc/$pid/environ | grep DBUS_SESSION_BUS_ADDRESS`
sudo -E -su $user /usr/bin/audtool $1
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.
I have created a captive portal with iptables
I use what many people seem to use : Users can request DNS, packet marked as 99. 99 means no internet else the user does have access.
When a user visits a page when visiting for example stack overflow. The user gets the disclaimer. He/she clicks on okay. What happened is that the server executes the following rules :
`sudo /sbin/iptables -t mangle -I captivePortal 1 -m mac --mac-source {$mac} -j RETURN`;
`sudo /sbin/iptables -t mangle -I captivePortal 1 -s {$_SERVER['REMOTE_ADDR']} -j RETURN`;
What i have tried:
Used sinatra stand alone with thin. Render template with erb. When the user reloads after authenticating they get the disclaimer when visiting the initial domain. When the visit another they dont get the disclaimer page.
Set up apache2 with php, rewritten all in php. added meta tags to prevent caching in the browser but same result. original domain redirects to disclaimer always but other sites are okay.
What i want to achieve
Users need to click accept on disclaimer before they can use WIFI.
Edit : Reloading apache2 does correct this problem.
Used rmtrack as described here : http://www.andybev.com/index.php/Using_iptables_and_PHP_to_create_a_captive_portal
/usr/sbin/conntrack -L \
|grep $1 \
|grep ESTAB \
|grep 'dport=80' \
|awk \
"{ system(\"conntrack -D --orig-src $1 --orig-dst \" \
substr(\$6,5) \" -p tcp --orig-port-src \" substr(\$7,7) \" \
--orig-port-dst 80\"); }"
I have searched far and wide to no avail. Perhaps I am simply daft. I have verified with Dreamhost that they have mutt installed and running on my server, but I do not have access to the error logs from cron. I am running a php page (this is actually one of many so I really need to figure this out).
I desperately tried to get this to work. Nothing. Nada. No email. But it DID create the file.
Here is what I'm running in crontab:
MAILTO="me#email.com"
15 13 * * * /usr/local/bin/setlock -n /tmp/cronlock.3783699908.000001 sh -c $'/usr/bin/curl -sS http://mywebsite.com/data_stats.php' > $(date "+/home/jborn/mywebsite.com/cronlogs/\%Y\%m\%dDATASTATS.txt") && mutt -a $(date "+/home/jborn/mywebsite.com/cronlogs/\%Y\%m\%dDATASTATS.txt") -- me#email.com
Not sure what was wrong, but the below is working to load a php page, output the contents to a log file, and email the file. Note: If I wanted to append the data, I'd use >> instead of >.
15 7 * * * /usr/bin/curl -sS "http://delightful.com/data_stats?no_header=1" > $(date "+/home/jborn/delightful.com/cronlogs/\%Y\%m\%dDATAlog.txt") && mutt -s "Data Stats for Today" -a $(date "+/home/jborn/delightful.com/cronlogs/\%Y\%m\%dDATAlog.txt") -- me#email.com
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