-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticated-atom-forums
executable file
·106 lines (85 loc) · 2.42 KB
/
authenticated-atom-forums
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
#! /usr/bin/env bash
# © 2023 Unvanquished Developers
# MIT License https://spdx.org/licenses/MIT.html
export shell_opts="${shell_opts:--u -e -o pipefail}"
set ${shell_opts}
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
cd "${script_dir}"
. 'irc-atom-notice.conf'
. 'credentials-forums.conf'
# Not a bad thing to do
chmod og-rwx 'credentials-forums.conf'
if [ -z "${1:-}" ]
then
echo 'ERROR: missing url' &>2
false
fi
forum_url="${1}"
atom_url="${forum_url}/app.php/feed"
forum_login_url="${forum_url}/ucp.php?mode=login"
forum_cache_dir="${cache_dir}/forums"
cookie_file="${forum_cache_dir}/cookies.txt"
login_page="${forum_cache_dir}/login.html"
sid_file="${forum_cache_dir}/sid.txt"
token_file="${forum_cache_dir}/token.txt"
time_file="${forum_cache_dir}/time.txt"
output_file="${forum_cache_dir}/output.txt"
config_file="${forum_cache_dir}/config.txt"
mkdir -p "${forum_cache_dir}"
chmod go-rwx "${forum_cache_dir}"
curl --silent \
--output "${login_page}" \
--cookie-jar "${cookie_file}" \
"${forum_login_url}"
grep 'id="login"' "${login_page}" \
| sed -e 's/^.*sid=\([0-9a-z]*\)".*$/\1/' \
> "${sid_file}"
grep 'name="creation_time"' "${login_page}" \
| sed -e 's/^.*value="\([0-9a-z]*\)".*$/\1/' \
> "${time_file}"
grep 'name="form_token"' "${login_page}" \
| sed -e 's/^.*value="\([0-9a-z]*\)".*$/\1/' \
> "${token_file}"
sid_string="$(cat "${sid_file}")"
time_string="$(cat "${time_file}")"
token_string="$(cat "${token_file}")"
# It looks like the “viewonline” option
# is to not be listed as online…
cat > "${config_file}" <<EOF
--form login="Login"
--form autologin='on'
--form viewonline='on'
--form username="${forums_username}"
--form password="${forums_password}"
--form sid="${sid_string}"
--form creation_time="${time_string}"
--form form_token="${token_string}"
--form redirect="${atom_url}"
EOF
# Retry 5 times
for i in {1..5}
do
curl --silent \
--location \
--output "${output_file}" \
--cookie "${cookie_file}" \
--cookie-jar "${cookie_file}" \
--config "${config_file}" \
"${forum_login_url}&sid=${sid_string}"
output_format="$(head -n 2 "${output_file}" | tail -n 1)"
case "${output_format}" in
'<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">')
cat "${output_file}"
break
;;
esac
sleep 1s;
done
rm "${cookie_file}"
rm "${login_page}"
rm "${sid_file}"
rm "${token_file}"
rm "${time_file}"
rm "${output_file}"
rm "${config_file}"
rmdir "${forum_cache_dir}"