aboutsummaryrefslogtreecommitdiff
path: root/lib/_ak_html
blob: 5a478368590b29422258c5c778886819d3380a85 (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env bash
###
### arching-kaos-tools
### Tools to interact and build an Arching Kaos Infochain
### Copyright (C) 2021 - 2025  kaotisk
###
### This program is free software: you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation, either version 3 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program.  If not, see <http://www.gnu.org/licenses/>.
###
source $AK_LIBDIR/_ak_log

_ak_generate_html_header(){   
    printf '<!DOCTYPE html>\n<html>\n<head>\n'
    printf '<title>Arching Kaos Chain Data</title>\n'
    printf '    <meta charset="UTF-8">\n'
    printf '    <meta name="viewport" content="width=device-width, initial-scale=1">\n'
    printf '    <style>\n'
    printf '    body {\n'
    printf '        background-color: #000;\n'
    printf '        color: lightgreen;\n'
    printf '        padding: 2%%;\n'
    printf '        width: auto;\n'
    printf '        font-family: monospace;\n'
    printf '        font-size: 1rem;\n'
    printf '    }\n'
    printf '    h1, h2, h3, h4 {\n'
    printf '        text-align: left;\n'
    printf '    }\n'
    printf '    td {\n'
    printf '        text-align: initial;\n'
    printf '        background-color: #090909;\n'
    printf '        border: 1px dashed #444;\n'
    printf '        font-size: 1rem;\n'
    printf '        padding: 1vh 1vw;\n'
    printf '        margin: 0;\n'
    printf '    }\n'
    printf '    p, summary {\n'
    printf '        background: #061624;\n'
    printf '        border: 1px solid #827c7c;\n'
    printf '        padding: 1vh 1vw;\n'
    printf '        margin: 0;\n'
    printf '        color: lightgreen;\n'
    printf '        font-style: normal;\n'
    printf '        text-decoration: none;\n'
    printf '    }\n'
    printf '    summary:hover {\n'
    printf '        background: lightgreen;\n'
    printf '        color: #061624;\n'
    printf '    }\n'
    printf '    a {\n'
    printf '        color: #042746;\n'
    printf '        background-color: lightyellow;\n'
    printf '        border: 1px solid #827c7c;\n'
    printf '        padding: 1vh 1vw;\n'
    printf '        margin: 0;\n'
    printf '        font-style: normal;\n'
    printf '        text-decoration: none;\n'
    printf '    }\n'
    printf '    a:hover {\n'
    printf '        background-color: lightgreen;\n'
    printf '        color: #042746;\n'
    printf '    }\n'
    printf '    details {\n'
    printf '        border: 1px dotted;\n'
    printf '        background-color: #1d4055;\n'
    printf '    }\n'
    printf '    footer {\n'
    printf '        text-align: center;\n'
    printf '    }\n'
    printf '    </style>\n'
    printf '</head>\n'
    printf '<body>\n'
}

_ak_generate_html_zblock(){
    if [ ! -z $1 ] && [ -n "$1" ]
    then
        arg="$1"
    else
        _ak_log_error "No argument given"
        exit 1
    fi
    # Iterate through each argument and parse data
    if [ -f "$arg" ]
    then
        # Extract data from argument
        zblock=$(cat $arg | jq -r '.zblock')
        if [ ! -n "$zblock" ]
        then
            _ak_log_error "Empty zblock value"
            exit 1
        fi
        block=$(cat $arg | jq -r '.block')
        if [ ! -n "$block" ]
        then
            _ak_log_error "Empty block value"
            exit 1
        fi
        timestamp=$(cat $arg | jq -r '.timestamp')
        if [ ! -n "$timestamp" ]
        then
            _ak_log_error "Empty timestamp value"
            exit 1
        fi
        block_signature=$(cat $arg | jq -r '.block_signature')
        if [ ! -n "$block_signature" ]
        then
            _ak_log_error "Empty block_signature value"
            exit 1
        fi
        detach=$(cat $arg | jq -r '.detach')
        if [ ! -n "$detach" ]
        then
            _ak_log_error "Empty detach value"
            exit 1
        fi
        data=$(cat $arg | jq -r '.data')
        if [ ! -n "$data" ]
        then
            _ak_log_error "Empty data value"
            exit 1
        fi
        module=$(cat $arg | jq -r '.module')
        if [ ! -n "$module" ]
        then
            _ak_log_error "Empty module value"
            exit 1
        fi
        action=$(cat $arg | jq -r '.action')
        if [ ! -n "$action" ]
        then
            _ak_log_error "Empty action value"
            exit 1
        fi
        gpg=$(cat $arg | jq -r '.gpg')
        if [ ! -n "$gpg" ]
        then
            _ak_log_error "Empty gpg value"
            exit 1
        fi
        previous=$(cat $arg | jq -r '.previous')
        if [ ! -n "$previous" ]
        then
            _ak_log_error "Empty previous value"
            exit 1
        fi
        datablock=$(cat $arg | jq -r ".$data")
        if [ ! -n "$datablock" ]
        then
            _ak_log_error "Empty datablock value"
            exit 1
        fi

        # Output data in HTML format
        printf '    <h1>%s</h1>\n' "$PROGRAM"
        printf '    <h2>🔎 %szblock</h2>\n' "$zblock"
        if [ -f $AK_MODULESDIR/$module/main.sh ] && [ "$action" == "add" ]
        then
            ak -m $module -x $zblock > /dev/null 2>&1
            if [ $? -eq 0 ]
            then
                ak -m $module -x $zblock
            fi
        fi
        printf '    <h2>ℹī¸ %s</h2>\n' "$zblock"
        printf '    <table>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>đŸ“Ļ ZBLOCK</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$zblock"
        printf '        <pre>%s</pre>' "$(_ak_ipfs_cat $zblock | jq)"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>đŸ“Ļ BLOCK</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$block"
        printf '        <pre>%s</pre>\n' "$(_ak_ipfs_cat $block | jq)"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>🔏 BLOCK SIGNATURE</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$block_signature"
        printf '        <pre>%s</pre>\n' "$(_ak_ipfs_cat $block_signature)"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>⌚ TIMESTAMP</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <p>%s</p>\n' "$timestamp"
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>🔌 MODULE</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <p>%s</p>\n' "$module"
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>đŸĒ§ ACTION</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <p>%s</p>\n' "$action"
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>🔑 GPG</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$gpg"
        printf '        <pre>%s</pre>\n' "$(_ak_ipfs_cat $gpg)"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>đŸ“Ļ PREVIOUS</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <a target="_blank" href="./zblock-%s.html">🔗 %s</a>\n' "$previous" "$previous"
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>đŸ“Ļ DATA</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$data"
        printf '        <pre>%s</pre>\n' "$datablock"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>🔏 DATA_SIGNATURE</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$detach"
        printf '        <pre>%s</pre>\n' "$(_ak_ipfs_cat $detach)"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>📄 ipfs</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <a target="_blank" href="http://gw.ipfs.z.kaotisk-hund.com/ipfs/%s">🔗 %s</a>\n' "$(echo $datablock | jq -r '.ipfs')" "$(echo $datablock | jq -r '.ipfs')"
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>🔏 detach</pre>\n'
        printf '            </td>\n'
        printf '            <td>\n'
        printf '    <details>\n'
        printf '        <summary>%s</summary>\n' "$(echo $datablock | jq -r '.detach')"
        printf '        <pre>%s</pre>\n' "$(_ak_ipfs_cat $(echo $datablock | jq -r '.detach'))"
        printf '    </details>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '    </table>\n'
        printf '    <table>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>📃 Rendered ZBLOCK</pre>\n'
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '        <tr>\n'
        printf '            <td>\n'
        printf '    <pre>%s</pre>\n' "$(cat $arg | jq)"
        printf '            </td>\n'
        printf '        </tr>\n'
        printf '    </table>\n'
    fi
}