|
|
|
@ -10,10 +10,16 @@ error_exit() {
|
|
|
|
|
usage() {
|
|
|
|
|
printf "usage: %s [OPTIONS] URI [ARGS]\n" "$PROGNAME"
|
|
|
|
|
printf "Simple client for spartan protocol\n"
|
|
|
|
|
printf "Options:
|
|
|
|
|
-h, --help - display this help
|
|
|
|
|
-p, --port - change port number (default is 300)
|
|
|
|
|
-m, --message - input as string
|
|
|
|
|
-i, --input-file - input as file
|
|
|
|
|
-u, --url - url to the capsule\n"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
request(){
|
|
|
|
|
page=$(printf "$host /$path $post_len\r\n$post\r\n" | nc $host $port)
|
|
|
|
|
page=$(printf "$host /$path 0\r\n" | nc $host $port)
|
|
|
|
|
status=$(echo $page | awk 'NR == 1 {print $1}')
|
|
|
|
|
meta=$(echo $page | awk 'NR == 1 {$1=="";print}')
|
|
|
|
|
if [[ $status == 2 ]]; then
|
|
|
|
@ -28,15 +34,19 @@ request(){
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while getopts ":h:p:i:u:" arg; do
|
|
|
|
|
while getopts ":h:p:m:i:u:" arg; do
|
|
|
|
|
case $arg in
|
|
|
|
|
h | --help)
|
|
|
|
|
usage; exit ;;
|
|
|
|
|
p | --port)
|
|
|
|
|
export port=$OPTARG
|
|
|
|
|
;;
|
|
|
|
|
i | --input)
|
|
|
|
|
export post=$OPTARG
|
|
|
|
|
i | --input-file)
|
|
|
|
|
export post=$(cat $OPTARG)
|
|
|
|
|
export post_len=$(echo $post | wc -c )
|
|
|
|
|
;;
|
|
|
|
|
m | --message)
|
|
|
|
|
export post=$( echo $OPTARG)
|
|
|
|
|
export post_len=$( echo $post | wc -c )
|
|
|
|
|
;;
|
|
|
|
|
u | --url)
|
|
|
|
@ -55,7 +65,7 @@ while getopts ":h:p:i:u:" arg; do
|
|
|
|
|
echo $url_unparsed is not a Spartan URL
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
* | -* | --*)
|
|
|
|
|
*)
|
|
|
|
|
usage; error_exit "unknown option $1" ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|