| Server IP : 80.74.154.100 / Your IP : 216.73.217.0 Web Server : Apache System : Linux marissa.metanet.ch 4.18.0-553.141.2.lve.el7h.x86_64 #1 SMP Wed Jul 8 17:20:31 UTC 2026 x86_64 User : onlineadmin ( 10487) PHP Version : 8.5.7 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/httpd/vhosts/comeonline.ch/mybin/ |
Upload File : |
#! /bin/bash
# Bash interface to the PushBullet api.
# Author: Red5d - https://github.com/Red5d
if [ ! -n "$PB_CONFIG" ]; then
PB_CONFIG=~/.config/pushbullet
fi
source $PB_CONFIG > /dev/null 2>&1
API_URL=https://api.pushbullet.com/v2
EXECUTABLE="$(cd "$( dirname "$0" )" && pwd )"
PROGDIR="${EXECUTABLE%/*}"
if [ -z "$PB_API_KEY" ]; then
echo "could not find api key"
exit 1
fi
printUsage() {
echo "Usage: pushbullet <action> <device> <type> <data>
Actions:
list - Lists all devices in your PushBullet account. (does not require
additional parameters)
push - Pushes data to a device. (the device name can simply be a unique part of
the name that \"list\" returns)
pushes active - Get your 'active' pushes (pushes that haven't been deleted)
delete - Deletes a push, you must give the push 'iden', see https://docs.pushbullet.com/v2/pushes/
Types:
note
address
list
file
link
Type Parameters:
(all parameters must be put inside quotes if more than one word)
\"note\" type: give the title, then the note text. The note text can also be
given via stdin, leaving the note text field empty.
\"address\" type: give the address name, then the address or Google Maps query.
\"list\" type: give the name of the list, then each of the list items,
separated by spaces.
\"file\" type: give the path to the file.
\"link\" type: give the title of the link, then the url.
"
}
function getactivepushes () {
allpushes=$("$PROGDIR"/JSON.sh -l)
activepushes=$(echo "$allpushes" | egrep "\[\"pushes\",[0-9]+,\"active\"\].*true"|while read line; do echo "$line"|cut -f 2 -d ,; done)
for id in $activepushes; do
iden=$(echo "$allpushes" | grep "^\[\"pushes\",$id,\"iden\"\]"|cut -f 2)
title=$(echo "$allpushes" | grep "^\[\"pushes\",$id,\"title\"\]"|cut -f 2)
if [[ -z "$title" ]]; then
echo "(no title) $iden"
else
echo "$title $iden"
fi
done
}
function deletepush () {
curlres=$(curl -s "$API_URL/pushes/$1" -u "$PB_API_KEY": -d device_iden="$dev_id" -d active="false" -X POST)
checkCurlOutput "$curlres"
}
checkCurlOutput() {
res=$(echo "$1" | grep -o "created" | tail -n1)
if [[ "$res" != "created" ]]; then
echo "Error submitting the request. The POST error message was:"
fi
echo "$res"
}
if [ "$1" = "" ];then
if [ "$PB_API_KEY" = "" ];then
echo -e "\e[0;33mWarning, your API key is not set.\nPlease create $PB_CONFIG with a line starting with PB_API_KEY= and your PushBullet key\e[00m"
fi
printUsage
exit
fi
case $1 in
list)
echo "Available devices:"
echo "------------------"
curl -s "$API_URL/devices" -u "$PB_API_KEY": | tr ',' '\n' | grep nickname | cut -d '"' -f4
echo "all"
;;
pushes)
case $2 in
active)
echo "Your active pushes:"
echo "------------------"
curl -s "$API_URL/pushes" -u "$PB_API_KEY": | getactivepushes
;;
esac
;;
delete)
if [ -z "$2" ]; then
printUsage
exit
fi
curlres=$(curl -s "$API_URL/pushes/$2" -u "$PB_API_KEY": -X DELETE)
if [ "$curlres" == '{}' ]; then
echo "ok"
fi
;;
push)
if [ -z "$2" ]; then
printUsage
exit
fi
devices=$(curl -s "$API_URL/devices" -u "$PB_API_KEY": | tr '{' '\n' | tr ',' '\n' | grep nickname | cut -d'"' -f4)
idens=$(curl -s "$API_URL/devices" -u "$PB_API_KEY": | tr '{' '\n' | tr ',' '\n' | grep iden | cut -d'"' -f4)
lineNum=$(echo "$devices" | grep -i -n "$2" | cut -d: -f1)
dev_id=$(echo "$idens" | sed -n $lineNum'p')
case $3 in
note)
body=""
if [ ! -t 0 ]; then
# we have something on stdin
body=$(cat)
# remove unprintable characters, or pushbullet API fails
body=$(echo "$body"|tr -dc '[:print:]\n')
fi
if [ ! -z "$5" ]; then
body="$5"
fi
if [ "$2" = "all" ]; then
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -d type=note -d title="$4" --data-urlencode body="$body" -X POST)
elif [[ "$2" == *@* ]]; then
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -d email="$2" -d type=note -d title="$4" --data-urlencode body="$body" -X POST)
else
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -d device_iden="$dev_id" -d type=note -d title="$4" --data-urlencode body="$body" -X POST)
fi
checkCurlOutput "$curlres"
;;
address)
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -d device_iden="$dev_id" -d type=address -d name="$4" -d address="$5" -X POST)
checkCurlOutput "$curlres"
;;
list)
# print all array items after $4, convert them to a JSON array
# URLencoded data requests do not work for lists at the moment
itemlist=$(printf '%s\n' "${@:5}" \
| awk ' BEGIN { ORS = ""; print "["; } { print "/@"$0"/@"; } END { print "]"; }' \
| sed "s^\"^\\\\\"^g;s^\/\@\/\@^\", \"^g;s^\/\@^\"^g")
if [ "$2" = "all" ]; then
JsonData='{"type": "list", "title": "'"$4"'", "items": '"$itemlist"'}'
else
JsonData='{"type": "list", "device_iden": "'"$dev_id"'", "title":"'"$4"'", "items":'"$itemlist"'}'
fi
curlres=$(curl -s $API_URL/pushes -u "$PB_API_KEY": -X POST \
--header 'Content-Type: application/json' --data-binary "$JsonData")
checkCurlOutput "$curlres"
;;
file)
# Api docs: https://docs.pushbullet.com/v2/upload-request/
mimetype=$(file -i -b $4)
curlres=$(curl -s "$API_URL/upload-request" -u "$PB_API_KEY": -d file_name=$4 -d file_type=${mimetype%:*} -X POST)
#echo $curlres | "$PROGDIR"/JSON.sh -b
curlres2=$(curl -s -i $(echo $curlres | "$PROGDIR"/JSON.sh -b | grep upload_url |awk -F\" '{print $(NF-1)}') -X POST \
-F awsaccesskeyid=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep awsaccesskeyid |awk -F\" '{print $(NF-1)}') \
-F acl=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep acl | awk -F\" '{print $(NF-1)}') \
-F key=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep key | tail -1 | awk -F\" '{print $(NF-1)}') \
-F signature=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep signature | awk -F\" '{print $(NF-1)}') \
-F policy=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep policy | awk -F\" '{print $(NF-1)}') \
-F content-type=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep content-type | awk -F\" '{print $(NF-1)}') \
-F file=@$4)
if [ "$2" = "all" ]; then
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -F type=file \
-F file_name=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_name |awk -F\" '{print $(NF-1)}') \
-F file_type=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_type |awk -F\" '{print $(NF-1)}') \
-F file_url=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_url |awk -F\" '{print $(NF-1)}') \
-X POST)
elif [[ "$2" == *@* ]]; then
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -F email="$2" -F type=file \
-F file_name=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_name |awk -F\" '{print $(NF-1)}') \
-F file_type=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_type |awk -F\" '{print $(NF-1)}') \
-F file_url=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_url |awk -F\" '{print $(NF-1)}') \
-X POST)
else
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -F device_iden="$dev_id" -F type=file \
-F file_name=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_name |awk -F\" '{print $(NF-1)}') \
-F file_type=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_type |awk -F\" '{print $(NF-1)}') \
-F file_url=$(echo $curlres | "$PROGDIR"/JSON.sh -b | grep file_url |awk -F\" '{print $(NF-1)}') \
-X POST)
fi
checkCurlOutput "$curlres"
;;
link)
if [ "$2" = "all" ]; then
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -d type=link -d title="$4" -d url="$5" -X POST)
else
curlres=$(curl -s "$API_URL/pushes" -u "$PB_API_KEY": -d device_iden="$dev_id" -d type=link -d title="$4" -d url="$5" -X POST)
fi
checkCurlOutput "$curlres"
;;
*)
printUsage
;;
esac
;;
*)
printUsage
;;
esac