Skip to content

Instantly share code, notes, and snippets.

@aljamima
Forked from a-r-d/mailer.php
Created May 25, 2018 21:36
Show Gist options
  • Save aljamima/d9046370a4a58b05c8848436b45edefc to your computer and use it in GitHub Desktop.
Save aljamima/d9046370a4a58b05c8848436b45edefc to your computer and use it in GitHub Desktop.
bitcoin mining status checker for slush's pool
<?php
/*
What: mailer script for notifications:
Required params under POST:
msg
sub
ret
pass
*/
if(!(isset($_POST['msg']) && isset($_POST['sub']) && isset($_POST['ret']) && isset($_POST['pass']))) {
// echo back some json response saying we didnt get a POST.
$res = array("status" => 0, "message" => "required not posted.");
echo json_encode($res);
exit;
}
$msg = $_POST['msg'];
$sub = $_POST['sub'];
$to = "[email protected]";
$ret = $_POST['ret'];
$pass = $_POST['pass'];
// lol authentication
if($pass != "password") {
$res = array("status" => 0, "message" => "failed to authenticate.");
echo json_encode($res);
exit;
}
// send message
$ip = $_SERVER['REMOTE_ADDR'];
$stamp = time();
$subject = "$sub";
$message = "Return email: $ret \n IP: $ip \n Time: $stamp \n subject: $sub \n \n$msg\n";
$headers = "From: $ret\r\n";
// Or sendmail_username@hostname by default
mail($to, $subject, $message, $headers);
$res = array("status" => 1, "message" => "success");
echo json_encode($res);
?>
# get current mining status
import urllib
import urllib2
import json
import time
MAIL_URL = 'http://examplecom/somemailscript.php'
SLUSH_API = "https://mining.bitcoin.cz/accounts/profile/json/"
SLUSH_TOKEN = "API KEY GOES HERE"
def send_mail(subject, message, return_addr, password):
the_page = ""
try:
url = MAIL_URL
values = {
'sub' : subject,
'msg' : message,
'ret' : return_addr,
'pass' : password
}
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
return the_page
except Exception, e:
return e
def get_status_slush():
print "pulling status from slush's server"
res = ""
try:
url = "%s%s" % (SLUSH_API, SLUSH_TOKEN)
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
json_result = json.loads(the_page)
return "confirmed_reward: %s \nunconfirmed_reward: %s \nestimated_reward_round: %s \nhashrate: %s \nsend_threshold: %s \nwallet %s" % (
json_result["confirmed_reward"],
json_result["unconfirmed_reward"],
json_result["estimated_reward"],
json_result["hashrate"],
json_result["send_threshold"],
json_result["wallet"]
)
except Exception, e:
print e
return res
def do_loop():
res = get_status_slush()
print res
send_mail("slush mining status", res, "[email protected]", "password")
time.sleep(60*60*2) # 2 hours btwn status
do_loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment