-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakewebpage.sh
More file actions
121 lines (100 loc) · 2.77 KB
/
makewebpage.sh
File metadata and controls
121 lines (100 loc) · 2.77 KB
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
#!/bin/bash
# written by Chris.McDonald@uwa.edu.au and modified slightly using Chat GPT
# thanks to: https://en.clipdealer.com/vector/media/A:112583666
HOST="localhost" # assuming all stations on the same host
LEAVE=`date '+%H:%M'` # or set to a fixed value
# ---------------------------------------
usage() {
echo "Usage: $0 startscript output.html"
exit 1
}
if [ $# != "2" ]; then
usage
fi
if [ ! -f $1 ]; then
echo cannot read $1
usage
fi
# ---------------------------------------
TMP="/tmp/mf-$$"
trap "rm -f $TMP ; exit 1" INT TERM
header() {
cat << THE_END
<html>
<body style="background-image: url('https://images.assetsdelivery.com/compings_v2/zoaarts/zoaarts1810/zoaarts181000012.jpg'); background-repeat: repeat;">
<style>
div.box {
margin: 1em;
width: 30em;
border-radius: 6px;
border: 1px solid gray;
background-color: honeydew;
padding: 0.4em;
}
</style>
<div class="box">
<h3> Leaving after</h3>
<form>
<input type="time" id="leaveTime" name="leaveTime" onchange="updateLeaveTime()">
</form>
</div>
<script>
window.onload = function() {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
// Ensure hours and minutes are two digits
hours = hours < 10 ? '0' + hours : hours;
minutes = minutes < 10 ? '0' + minutes : minutes;
var timeStr = hours + ':' + minutes;
document.getElementById('leaveTime').value = timeStr;
updateLeaveTime(); // Update all forms initially with the current time
};
function updateLeaveTime() {
var time = document.getElementById('leaveTime').value;
var inputs = document.querySelectorAll('input[name="leave"]');
inputs.forEach(input => {
input.value = time;
});
}
</script>
THE_END
}
each_station() {
while read from tcpport ; do
echo ; echo '<div class="box">'
cat << THE_END
<form action="http://$HOST:$tcpport/">
<table>
<tr>
<td style="text-align: right;">Leaving from:</td>
<td style="text-align: left;"> <b>$from</b></td>
<td style="padding-left: 3em;"><i>http://$HOST:$tcpport/</i></td>
</tr>
<tr>
<td style="text-align: right;"><label>Destination:</label></td>
<td><select name="to">
THE_END
while read dest _ ; do
if [ "$dest" != "$from" ]; then
echo " <option value='$dest'>$dest</option>"
fi
done < $TMP
cat << THE_END
</select></td>
<td style="padding-left: 3em;"><input type="submit" value=" Let's go! "></td>
</tr>
</table>
<input type="hidden" name="leave" value="$LEAVE">
</form>
THE_END
echo "</div>"
done < $TMP
}
# ---------------------------------------
echo "reading file $1"
echo "creating file $2"
expand < $1 | sed 's/^ //g' | \
tr -s ' ' | grep '[a-z]' | cut '-d ' -f2,3 | sort > $TMP
( header ; each_station ) > $2
rm -f $TMP