-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlib_poppay.js
More file actions
182 lines (126 loc) · 5.23 KB
/
lib_poppay.js
File metadata and controls
182 lines (126 loc) · 5.23 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
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
this.show_index=function(csrf,token,redir){
return new Promise(function(resolve,reject){
var reply = '<!DOCTYPE html><html class="h-100">'
reply +='<title>LIGHTNING CAPTIVE PORTAL</title>'
reply +='<meta charset="utf-8">'
reply +='<meta name="viewport" content="width=device-width, initial-scale=1">'
reply +='<body class="h-100">'
reply +='<br>'
reply +='<h1>LIGHTNING CAPTIVE PORTAL</h1><br>'
reply +='Pay 100 sats to get wifi-access.<br><br>'
reply +='<form action="/invoice" method="post">'
reply +='<input type="hidden" name="_csrf" value='+csrf+'>'
reply +='<input type="hidden" name="_token" value='+token+'>'
reply +='<input type="hidden" name="_redir" value='+redir+'>'
reply +='<input type="hidden" name="_amt" value=0.000001>'
reply +='<button class="btn btn-info mt-4" type="submit">Connect for 100 sats</button>'
reply +='</form>'
reply +='</body>'
reply +='</html>'
resolve(reply);
})
}
this.show_notpayed=function(){
return new Promise(function(resolve,reject){
var reply = '<!DOCTYPE html><html class="h-100">'
reply +='<title>LIGHTNING CAPTIVE PORTAL</title>'
reply +='<meta charset="utf-8">'
reply +='<meta name="viewport" content="width=device-width, initial-scale=1">'
reply +='<body>'
reply +='<br>'
reply +='<div class="container d-flex h-95">'
reply +=' <div class="justify-content-center align-self-center text-center mx-auto">'
reply +=' <h1 class="mb-4">Invoice not payed</h1>'
reply +='<form action="/" method="get">'
reply +='<button class="btn btn-info mt-4" type="submit">cancel</button>'
reply +='</form>'
reply +=' </div>'
reply +='</div>'
reply +='</body>'
reply +='</html>'
resolve(reply);
})
}
this.show_invoice=function(invoice,csrf,token_in,amt_in,redir_in,id_in,req){
return new Promise(function(resolve,reject){
var reply = '<!DOCTYPE html><html class="h-100">'
reply +='<title>LIGHTNING CAPTIVE PORTAL</title>'
reply +='<meta charset="utf-8">'
reply +='<meta name="viewport" content="width=device-width, initial-scale=1">'
//QR
reply +='<script type="text/javascript" src="../code/qrcode.min.js"></script>'
//copy button
reply +=' <script> '
reply +=' function myFunction() {'
reply +=' var copyText = document.getElementById("invoiceID");'
reply +=' copyText.select();'
reply +=' document.execCommand("copy");'
reply +=' alert("Copied the text: " + copyText.value);'
reply +=' }'
reply +=' </script>'
//sse
reply+='<script type="text/javascript"> \
var source = new EventSource("/inv_event/'+csrf+'"); \
source.onmessage = function(e) { \
window.location.replace(e.data); \
document.body.innerHTML += e.data + "<br>"; \
}; \
</script>';
reply +='<body class="h-100">'
reply +='<br>'
reply +='<div class="container">'
reply +=' <div class="justify-content-center align-self-center text-center mx-auto">'
reply +=' <h1 class="mb-4">Invoice</h1>'
reply += "pay "+Number(amt_in) * 100000000 +" sats to get wifi access<br>"
reply += '<textarea class="form-control" rows="3" id="invoiceID" value="'+invoice+'" readonly>'
reply += invoice
reply += '</textarea>'
reply += ' <div class="input-group-btn">'
reply += ' <button onclick="myFunction()" class="btn btn-primary">copy</button>'
reply += ' </div>'
//QR
reply += '<br>'
reply+='<div id="qrcode" style="width:240px; height:240px; margin: 0 auto; margin-top:20px;"></div>'
reply +='You will be redirect when the invoice is paid. If the invoice is paid and you are not redirected in a few seconds, click check button.<br>'
//acabar.
reply +='<form action="/check_invoice" method="post">'
reply +='<input type="hidden" name="_csrf" value='+csrf+'>'
reply +='<input type="hidden" name="_token" value='+token_in+'>'
reply +='<input type="hidden" name="_redir" value='+redir_in+'>'
reply +='<input type="hidden" name="_amt" value='+amt_in+'>'
reply +='<input type="hidden" name="_id" value='+id_in+'>'
reply +='<button class="btn btn-info mt-4" type="submit">Check</button>'
reply +='</form>'
reply +='<form action="/" method="get">'
reply +='<button class="btn btn-info mt-4" type="submit">cancel</button>'
reply +='</form>'
reply += '<script type="text/javascript">'
reply += ' var qrcode = new QRCode(document.getElementById("qrcode"), { '
reply += ' width : 200, '
reply += ' height : 200 '
reply += ' }); '
reply += ' function makeCode () {'
reply += ' var elText = document.getElementById("invoiceID");'
reply += ' if (!elText.value) { '
reply += ' alert("Input a text"); '
reply += ' elText.focus(); '
reply += ' return; '
reply += ' } '
reply += ' qrcode.makeCode(elText.value); '
reply += ' } '
reply += ' makeCode(); '
reply += ' $("#text"). '
reply += ' on("blur", function () { '
reply += ' makeCode(); '
reply += ' }). '
reply += ' on("keydown", function (e) { '
reply += ' if (e.keyCode == 13) { '
reply += ' makeCode(); '
reply += ' } '
reply += ' }); '
reply += ' </script>'
reply +='</body>'
reply +='</html>'
resolve(reply);
})
}