This repository was archived by the owner on Sep 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpbin
executable file
·189 lines (160 loc) · 4.91 KB
/
pbin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# bash pastebin.com client
# https://github.com/mefuckin/pastebin-shell
# Path to config file
config_file="$HOME/.config/pastebin.conf"
# Config file overwrites following default settings
# This is my API Developer Key (you can change it here or use config file)
api_dev_key="97d4dbcc849cf72fe005154e40904f71"
# Autologin
logintopastebin="0"
# Default paste title, if -n argument is not defined
api_paste_name=""
# Default paste highlighting, if -f argument is not defined
api_paste_format="text"
# Default private settings, if -p argument is not defined (0=public, 1=unlisted, 2=private)
api_paste_private="0"
# Default expire date, if -e argument is not defined
api_paste_expire_date="1H"
# Pastebin.com API URL
api_url="http://pastebin.com/api"
usage()
{
cat << EOF
Usage: $0 [options]
Post text from stdin to pastebin.com.
Options:
-l Log into pastebin.com
-u Your pastebin.com username
-p Your pastebin.com password
-n name Paste title
-f format Syntax highlightig format (you can find list
of formats at http://pastebin.com/api#5)
-e expire Paste expire time:
n (or never) - never
10M - 10 minutes
1H - 1 hour
1D - 1 day
1M - 1 month
-r private Private settings: public (or 0), unlisted (or 1)
or private (or 2, need to login)
-h Show this message
-o Print sample config
-c /path/to/pastebin.conf Set path to config file
EOF
}
# command_exists() tells if a given command exists.
function command_exists() {
command -v "$1" >/dev/null 2>&1
}
sample_config()
{
cat << EOF
# Change to your API Developer Key
#api_dev_key=""
# Change to your pastebin.com username, if you want to log into your account
#api_user_name=""
# Change to your pastebin.com password
#api_user_password=""
# Set to 1 if you want to log into your account automatically
# (you may login with -l, -u, -p arguments also)
#logintopastebin="0"
# Default paste title, if -n argument is not defined
#api_paste_name=""
# Default paste highlighting, if -f argument is not defined
# (see http://pastebin.com/api#5 for more)
#api_paste_format="text"
# Default private settings, if -p argument is not defined
# (0=public, 1=unlisted, 2=private)
#api_paste_private="0"
# Default expire date, if -e argument is not defined
#api_paste_expire_date="N"
EOF
}
auth_user()
{
if [ -z "$api_user_name" ] || [ -z "$api_user_password" ]
then
echo "Username and/or password is undefined."
echo "Please adjust 'api_user_name' and 'api_user_password' in the configuration file '$config_file'"
exit 1
fi
server_reply="$(curl --silent --data "api_dev_key=$api_dev_key" --data-urlencode "api_user_name=$api_user_name" --data-urlencode "api_user_password=$api_user_password" "$api_url/api_login.php")"
if [[ $server_reply == Bad* ]]
then
echo "Username: $api_user_name"
echo "$server_reply"
exit 1
else
api_user_key="$server_reply"
fi
}
if ! command_exists curl; then
echo "'curl' is needed. Please install 'curl'. More details can be found at https://curl.haxx.se/"
exit 1
fi
# Load configuration file if it exists.
if [ -f "$config_file" ]; then
# shellcheck source=/dev/null
source "$config_file"
fi
while getopts "hu:p:ln:f:c:e:r:o" OPTION ; do
case $OPTION in
h) usage; exit ;;
o) sample_config; exit ;;
u) api_user_name="$OPTARG"; logintopastebin=1 ;;
p) api_user_password="$OPTARG" ;;
l) logintopastebin=1 ;;
n) api_paste_name="$OPTARG" ;;
f) api_paste_format="$OPTARG" ;;
e) case $OPTARG in
n|never) api_paste_expire_date=N ;;
10M) api_paste_expire_date=10M ;;
1H) api_paste_expire_date=1H ;;
1D) api_paste_expire_date=1D ;;
1M) api_paste_expire_date=1M ;;
1W) api_paste_expire_date=1W ;;
2W) api_paste_expire_date=2W ;;
*) echo "Invalid expire date"; exit 1 ;;
esac ;;
r) case $OPTARG in
public|0) api_paste_private=0 ;;
unlisted|1) api_paste_private=1 ;;
private|2)
if [ $logintopastebin -ne 1 ]
then
echo "You need to log in (option -l or -u) if you want to post private pastes."
exit 1
else
api_paste_private=2
fi
;;
*) echo "Invalid private value"; exit 1 ;;
esac
;;
c) if [ -f "$OPTARG" ];
then
# shellcheck source=/dev/null
source "$OPTARG"
else
echo "$OPTARG is not exists"
exit 1
fi
;;
esac
done
[ $logintopastebin -ne 0 ] && auth_user
api_paste_code=$( cat - )
curl -0 --show-error \
--data "api_dev_key=$api_dev_key" \
--data "api_option=paste" \
--data "api_paste_code=$api_paste_code" \
--data "api_paste_format=$api_paste_format" \
--data "api_paste_private=$api_paste_private" \
--data "api_paste_expire_date=$api_paste_expire_date" \
--data "api_user_key=$api_user_key" \
--data-urlencode "api_paste_name=$api_paste_name" \
--data-urlencode "api_paste_code=$api_paste_code" \
"$api_url/api_post.php"
echo
exit $?