Skip to content

Commit 4b2328b

Browse files
committed
add another simple example
1 parent 9f7c093 commit 4b2328b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

examples/write-to-file.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Example request:
4+
# http://localhost/cgi-bin/r8168.cgi?rev=0x00&probe=b0cdd5070e
5+
6+
# https://github.com/mikhailnov/bashlib, https://abf.io/import/bashlib
7+
. bashlib ||{ echo "Failed to source bashlib!" ; exit 1 ;}
8+
9+
readonly file="/var/www/r8168.list"
10+
readonly lock="/var/www/r8168.lock"
11+
readonly rev="$(safe_param rev)"
12+
readonly probe="$(safe_param probe)"
13+
14+
# possible values: 0x15, 0x09
15+
if ! [[ "$rev" =~ ^0x..$ ]]; then
16+
echo "Status: 400 Bad request"
17+
echo "Content-Type: text/plain; charset=utf-8"
18+
echo ""
19+
echo "Incorrect value of rev"
20+
exit 1
21+
fi
22+
23+
if [ ${#probe} -gt 20 ] || ! [[ "$probe" =~ ^[a-zA-Z0-9]+$ ]]; then
24+
echo "Status: 400 Bad request"
25+
echo "Content-Type: text/plain; charset=utf-8"
26+
echo ""
27+
echo "Incorrect value of probe"
28+
exit 1
29+
fi
30+
31+
set -e
32+
echo "$rev;$probe" | flock "$lock" tee -a "$file" >/dev/null
33+
echo "Status: 200 OK"
34+
echo "Content-Type: text/plain; charset=utf-8"
35+
echo ""
36+
echo "OK"

0 commit comments

Comments
 (0)