Skip to content

Instantly share code, notes, and snippets.

@ghostbitmeta
Created May 30, 2015 00:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ghostbitmeta/2b0d089a9ee2d88cdb5f to your computer and use it in GitHub Desktop.
Save ghostbitmeta/2b0d089a9ee2d88cdb5f to your computer and use it in GitHub Desktop.
Synology + Pushbullet
<?php
// Used code from the following sources:
// https://gist.github.com/styxit/e34d4c6f8cb23d55f5af#file-synology-pushover-php
// http://pastebin.com/iHAFAHGq
// Thanks to: https://styxit.com/2014/05/10/synology-pushover.html
// Only allow request made by localhost?
// Set this to false if this script is not running on your synology webserver (less secure)
$localOnly = true;
echo time();
// Validate httpHost and/or remote addr?
if ($localOnly) {
if ($_SERVER['HTTP_HOST'] != 'localhost') {
// Not locahost
die;
}
}
// Open curl connection
$ch = curl_init();
// Set variables from user input
$postdata = json_encode([
"type" => "note",
"title" => isset($_GET['text']) ? $_GET['text'] : false,
"body" => isset($_GET['text']) ? $_GET['text'] : false,
]);
$token = $_GET['appkey'];
// Prepare HTTP header for authentication
$header = array();
$header[] = "Authorization: Bearer " . $token;
$header[] = "Content-Type: application/json";
// Set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, "https://api.pushbullet.com/v2/pushes");
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
// Execute post
$result = curl_exec($ch);
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment