-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHPSDRProgrammer_web.go
More file actions
1420 lines (1192 loc) · 40.7 KB
/
HPSDRProgrammer_web.go
File metadata and controls
1420 lines (1192 loc) · 40.7 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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// HPSDRProgrammer_web program
//
// by David R. Larsen, copyright December 19, 2015
// License LGPL 2.0
// Part of the OpenHPSDR Software Defined Radio Project (openhpsdr.org)
//
package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"html/template"
"io"
"io/ioutil"
"log"
"math"
"net/http"
"os"
"os/user"
"runtime"
"strconv"
"strings"
"time"
"golang.org/x/net/websocket"
//"oak.snr.missouri.edu/daveradio/newopenhpsdr"
"newopenhpsdr"
)
// Server address and port
var srvaddress string
const srvport string = "8228"
// Constants to define the program state
const version string = "0.2.9"
const protocol string = ">1.7"
const update string = "2019-3-14"
// String to define the program banner in each web window
const banner string = `
<div id="header" align="left" style="background-color:Darkblue;border:2px solid; border-radius:8px; ">
<b align="left" width="90%" style="margin-left:45px; color:white; font-size:38px ">HPSDR Programmer</b>
<p style="margin-left:45px; color:white; font-size:12 ">By Dave, KVØS (N1GP TEST) - Version {{.Version}}, Protocol {{.Protocol}} - Last Updated {{.Update}} - <a style="color:white; font-size:12px" href="http://openhpsdr.org">openhpsdr.org</a> </p>
</div>
`
// HTML to define the style and header settings
const w1p string = `
<html>
<head>
<title> HPSDRProgrammer Web </title>
<meta charset=utf-8 />
`
// HTML to define the style and header settings
const w1style string = `
<style>
html, body, h1, div, select {
}
body {
background: #ffffff;
color: #000000;
font-family: Helvetica, Geneva, Arial, sans-serif;
padding: 20px;
}
@-viewport {
width: 640px;
}
h1 {
font-size: 28px;
margin-bottom: 20px;
}
select, input, button {
display:block;
border-radius:8px;
-moz-border-radius: 8;
-webkit-border-radius: 8px;
border: 5px solid Darkblue;
height: 35px;
font-size: 20px;
}
table {
empty-cells: show
}
.hdr {
display:block;
background: #eeeeee;
border-radius:8px;
-moz-border-radius: 8;
-webkit-border-radius: 8px;
border: 2px solid black;
height: 35px;
font-size: 20px;
}
.nic1 {
font-size: 20px;
}
.mac1 {
font-size: 20px;
}
.btn {
display:block;
align:center;
valign:bottom;
border-radius:8px;
-moz-border-radius: 8;
-webkit-border-radius: 8px;
border: 5px solid Darkblue;
height: 35px;
width: 200px;
font-size: 20p
}
.intp {
display:block;
align:center;
valign:bottom;
border-radius:6px;
-moz-border-radius: 6;
-webkit-border-radius: 6px;
border: 3px solid Darkblue;
height: 35px;
width: 70;
font-size: 16
}
.fileintp {
display:block;
align:center;
valign:bottom;
border-radius:6px;
-moz-border-radius: 6;
-webkit-border-radius: 6px;
border: 3px solid Darkblue;
height: 35px;
width: 600;
font-size: 16
}
}
</style>
`
// HTML to define the style and header settings
const w2p string = `
</head>
<body>
`
// Intro window text
const intro string = `
<h2>Overview</h2>
<p> The HPSDRProgrammer is a tool to load {{.Protocol}} protocol firmware into HPSDR boards. This program
performs the same function as the HPSDRProgrammer. It perform the following tasks.
<ul>
<li>Discovery of the HPSDR boards available.</li>
<li>Changing the HPSDR board to a fixed IPv4 address within your subnet</li>
<li>Erase and Program an RBF file to the HPSDR Board.</li>
</ul>
`
// Counter window text
const w1cnt string = `
<script type="text/javascript" src="http://{{.Address}}:{{.Port}}/js/lib/jquery-1.12.1.min.js"></script>
<script type="text/javascript" >
var wsUri = "ws://{{.Address}}:{{.Port}}/counter/";
var output;
var packet;
function init() {
output = document.getElementById("output");
packet = document.getElementById("packet");
websocket = new WebSocket(wsUri);
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) }; }
function onMessage(evt) {
console.log(evt.data);
writeToScreen(evt.data); }
//function onError(evt) {
// writeToScreen('<span style="color: red;">ERROR:<\/span> ' + evt.data); }
function writeToScreen(message) {
output.innerHTML = message.split(",")[0];
packet.innerHTML = message.split(",")[1]; }
window.addEventListener("load", init, false);
</script>
`
const w2cnt string = `
<script>
$(document).ready(function() {
$.ajax({
dataType: "json",
url: "http://{{.Address}}:{{.Port}}/counter/"
}).then(function(data) {
data.getJSON(data);
$('.packet').append(data.packet);
$('.time').append(data.time);
});
});
/script>
`
// used get the selected information to different parts of the code with out closure tricks on Handlers
// current selected board
var crtbd newopenhpsdr.Hpsdrboard
// current file
var rbffiledir string
var rbffilename string
//
func usage() {
log.Printf(" For a list of commands use --help \n\n")
}
// Print out HTML to creat a server computer table
func Computertable(itr newopenhpsdr.Intface) (str string) {
var strs []string
s := fmt.Sprintf("<td align=\"right\"><b>Computer:</b></td><td> (%v)</td></tr><tr>", itr.MAC)
strs = append(strs, s)
s = fmt.Sprintf("<td align=\"right\"><b>OS:</b></td><td> %s (%s) %d CPU(s)</td></tr><tr>", runtime.GOOS, runtime.GOARCH, runtime.NumCPU())
strs = append(strs, s)
if runtime.GOARCH != "arm" {
u, err := user.Current()
if err != nil {
panic(err.Error())
}
s = fmt.Sprintf("<td align=\"right\"><b>User:</b></td><td> %s (%s) %s </td></tr><tr>", u.Name, u.Username, u.HomeDir)
strs = append(strs, s)
}
s = fmt.Sprintf("<td align=\"right\"><b>IPV4:</b></td><td> %v</td></tr><tr>", itr.Ipv4)
strs = append(strs, s)
s = fmt.Sprintf("<td align=\"right\"><b>IPV6:</b></td><td> %v</td></tr><tr>", itr.Ipv6)
strs = append(strs, s)
str = strings.Join(strs, "")
return str
}
type message struct {
Time string `json:"time"`
Packet string `json:"packet"`
Msg chan bool
Done chan bool
}
// structure definition for the Html struct
type Html struct {
Version string
Protocol string
Update string
Address string
Port string
}
// Convenience function to print interface data
func Listinterface(itr newopenhpsdr.Intface) {
log.Printf(" Computer: (%v)\n", itr.MAC)
log.Printf(" OS: %s (%s) %d CPU(s)\n", runtime.GOOS, runtime.GOARCH, runtime.NumCPU())
if runtime.GOARCH != "arm" {
u, err := user.Current()
if err != nil {
panic(err.Error())
}
log.Printf(" Username: %s (%s) %s\n", u.Name, u.Username, u.HomeDir)
}
log.Printf(" Name: %v\n", itr.Intname)
log.Printf(" MAC: %v\n", itr.MAC)
log.Printf(" IPV4: %v\n", itr.Ipv4)
//log.Printf(" Mask: %d\n", itr.Mask)
//log.Printf(" Network: %v\n", itr.Network)
log.Printf(" IPV6: %v\n", itr.Ipv6)
}
// Convenience function to print board data
func Listboard(str newopenhpsdr.Hpsdrboard) {
if str.Macaddress != "0:0:0:0:0:0" {
log.Printf("\n")
log.Printf(" Board Type: %s\n", str.Board)
log.Printf(" HPSDR Board: (%s)\n", str.Macaddress)
log.Printf(" Board Address: %s\n", str.Baddress)
log.Printf(" Protocol: %s\n", str.Protocol)
log.Printf(" Firmware: %s\n", str.Firmware)
log.Printf(" Receivers: %d\n", str.Receivers)
log.Printf(" Freq. Input: %s\n", str.Freqinput)
log.Printf(" IQ data format: %s\n", str.Iqdata)
log.Printf(" Status: %s\n", str.Status)
}
}
// Web handler function to produce the intro webpage
func introhandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Introduction page.")
log.Printf("Browser type %s", r.Header.Get("User-Agent"))
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("body").Parse(w2p)
t2.Execute(w, "body")
t3, _ := template.New("webbanner").Parse(banner)
t3.Execute(w, H)
t4, _ := template.New("intro").Parse(intro)
t4.Execute(w, H)
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/nic/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"nic\" value=\"nic\"> Select Interface</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td>")
fmt.Fprintf(w, "<td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/closescreen/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to produce the nic selection web page
func nichandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Network Interface page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
r.ParseForm()
crtbd = newopenhpsdr.ResetHpsdrboard(crtbd)
str := fmt.Sprintf("http://%s:%s/nic/json/", srvaddress, srvport)
res, err := http.Get(str)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err.Error())
}
var intf []newopenhpsdr.Intface
err = json.Unmarshal(body, &intf)
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("body").Parse(w2p)
t2.Execute(w, "body")
t3, _ := template.New("webbanner").Parse(banner)
t3.Execute(w, H)
fmt.Fprintf(w, "<h2>Network Interfaces</h2> <p> Please select the interface to perform a Discovery</p>")
fmt.Fprintf(w, "<table>\n")
fmt.Fprintf(w, "<tr><td align=\"right\"><b>Index:</b></td><td><b>(Network) (MAC) (IPV4) (IPV6)</b></td></tr>\n")
for i := range intf {
fmt.Fprintf(w, "%s", newopenhpsdr.Intfacetable(intf[i]))
}
fmt.Fprintf(w, "</table>\n")
fmt.Fprintf(w, "<br/>\n")
fmt.Fprintf(w, "<table><tr><td valign=\"top\">")
fmt.Fprintf(w, "<form action=\"/board/\" >")
if r.FormValue("index") == "0" {
fmt.Fprintf(w, "<b>Select Network interface</b>")
} else {
fmt.Fprintf(w, "<b>Selected Network interface</b>")
}
fmt.Fprintf(w, "</td><td></td><td></td></tr><tr><td valign=\"top\">")
fmt.Fprintf(w, "<select name=\"index\" >")
nic, _ := strconv.ParseInt(r.FormValue("index"), 0, 0)
for i := range intf {
if nic == int64(intf[i].Index) {
fmt.Fprintf(w, "<option selected value=\"%d\">%d: %s (%s)</option>", intf[i].Index, intf[i].Index, intf[i].Intname, intf[i].MAC)
} else {
fmt.Fprintf(w, "<option value=\"%d\">%d: %s (%s)</option>", intf[i].Index, intf[i].Index, intf[i].Intname, intf[i].MAC)
}
}
fmt.Fprintf(w, "</select>")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"select\" value=\"nic\"> Select</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/closescreen/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to create the board selection web page
func boardhandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Radio Select page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("body").Parse(w2p)
t2.Execute(w, "body")
t3, _ := template.New("webbanner").Parse(banner)
t3.Execute(w, H)
r.ParseForm()
fmt.Fprintf(w, "<h2>Computer</h2> ")
intf := newopenhpsdr.Interfaces()
var itr newopenhpsdr.Intface
nic, _ := strconv.ParseInt(r.FormValue("index"), 0, 0)
for i := range intf {
if nic == int64(intf[i].Index) {
itr = intf[i]
}
}
Listinterface(itr)
fmt.Fprintf(w, "<table>\n")
fmt.Fprintf(w, "%s", Computertable(itr))
fmt.Fprintf(w, "</td></tr>\n")
fmt.Fprintf(w, "</table>\n")
fmt.Fprintf(w, "<h2>Radios</h2> <p> Please select from these available Radios</p>")
//var adr string
//var bcadr string
var boardtype string
boardtype = "none"
//adr = itr.Ipv4 + ":1024"
//bcadr = itr.Ipv4Bcast + ":1024"
// perform a discovery
sd := fmt.Sprintf("http://%s:%s/discover/json/?index=%d", srvaddress, srvport, itr.Index)
log.Printf("Discovery Call: %s\n", sd)
res, err := http.Get(sd)
if err != nil {
log.Fatal(err)
}
log.Printf("Reply Header: %s\n ", res.Header)
log.Printf("Reply Body: %s\n ", res.Body)
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Println("Read Error ", err)
}
var str []newopenhpsdr.Hpsdrboard
err = json.Unmarshal(body, &str)
if err != nil {
log.Println("Unmarshall Error ", err)
}
for i := 0; i < len(str); i++ {
fmt.Fprintf(w, "%s", newopenhpsdr.Hpsdrboardlist(str[i]))
log.Printf(" %s: (%s) (%s)\n", str[i].Board, str[i].Macaddress, str[i].Baddress)
}
fmt.Fprintf(w, "<br/><br/>\n")
fmt.Fprintf(w, "<table>\n<tr>\n<td align=\"right\">\n")
fmt.Fprintf(w, "<form action=\"/board/\" >\n")
if r.FormValue("index") == "0" {
fmt.Fprintf(w, "<b>Select Network interface</b>")
} else {
fmt.Fprintf(w, "<b>Selected Network interface: </b>")
}
fmt.Fprintf(w, "</td><td valign=\"top\"> %d: <b>%s</b> (%s)</td><td></td></tr>", itr.Index, itr.Intname, itr.MAC)
fmt.Fprintf(w, "<tr><td align=\"right\" >")
if r.FormValue("board") == "" {
fmt.Fprintf(w, "<b>Select HPSDR Board</b>")
}
fmt.Fprintf(w, "</td></tr></table>")
//fmt.Fprintf(w, "<br/>\n")
fmt.Fprintf(w, "<table>\n<tr>\n<td align=\"right\" valign=\"top\">\n")
//fmt.Fprintf(w, "</td><td></td></tr><tr><td>")
if r.FormValue("index") == "0" {
fmt.Fprintf(w, "<select disabled=\"disabled\" name=\"board\" >\n")
} else {
fmt.Fprintf(w, "<select name=\"board\" >\n")
}
fmt.Fprintf(w, "<option value=\"%s\">%s %s</option>\n", "none", "none", "none")
for i := 0; i < len(str); i++ {
if r.FormValue("board") == str[i].Macaddress {
fmt.Fprintf(w, "<option selected value=\"%s\">%s (%s)</option>\n", str[i].Macaddress, str[i].Board, str[i].Macaddress)
//istr = strings.Split(str[i].Baddress, ".")
boardtype = str[i].Board
crtbd = str[i]
} else {
fmt.Fprintf(w, "<option value=\"%s\">%s (%s)</option>\n", str[i].Macaddress, str[i].Board, str[i].Macaddress)
}
}
fmt.Fprintf(w, "</select>\n")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<input type=\"hidden\" name=\"index\" value=%s>\n", r.FormValue("index"))
fmt.Fprintf(w, "<input type=\"hidden\" name=\"boardtype\" value=%s>\n", boardtype)
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" value=\"board\"> Select</button>\n")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>\n")
if r.FormValue("board") != "" {
fmt.Fprintf(w, "<b>Select HPSDR Board</b>")
fmt.Fprintf(w, "<table>\n")
fmt.Fprintf(w, "%s", newopenhpsdr.Hpsdrboardtable(crtbd))
Listboard(crtbd)
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/setip/\" >")
fmt.Fprintf(w, "<input type=\"hidden\" name=\"index\" value=%s>\n", r.FormValue("index"))
fmt.Fprintf(w, "<input type=\"hidden\" name=\"board\" value=%s>\n", r.FormValue("board"))
fmt.Fprintf(w, "<input type=\"hidden\" name=\"baddress\" value=%s>\n", crtbd.Baddress)
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"setip\" value=\"setip\"> Change IP</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/prog/\" >")
fmt.Fprintf(w, "<input type=\"hidden\" name=\"index\" value=%s>\n", r.FormValue("index"))
fmt.Fprintf(w, "<input type=\"hidden\" name=\"boardtype\" value=%s>\n", boardtype)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"board\" value=%s>\n", r.FormValue("board"))
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"program\" value=\"program\"> Program</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/closescreen/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>\n")
fmt.Fprintf(w, "<br/>\n")
}
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to produce the change IP web page.
func setiphandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Set IP Interface page.")
r.ParseForm()
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
//intf := newopenhpsdr.Interfaces()
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("body").Parse(w2p)
t2.Execute(w, "body")
t3, _ := template.New("webbanner").Parse(banner)
t3.Execute(w, H)
adr := r.FormValue("baddress")
boardtype := r.FormValue("boardtype")
board := r.FormValue("board")
nic := r.FormValue("index")
ad := strings.Split(adr, ":")
aa := strings.Split(ad[0], ".")
fmt.Fprintf(w, "<h2>Change IP Interfaces</h2> <p> Please select the interface to perform a Change to the IP address.</p>")
fmt.Fprintf(w, "<table>\n")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/changedip/\" >")
//fmt.Fprintf(w, "<form >")
s, _ := strconv.ParseInt(aa[0], 10, 32)
fmt.Fprintf(w, "<input class=\"intp\" type=\"number\" min=\"0\" max=\"254\" name=\"ip1\" value=%d>\n", s)
fmt.Fprintf(w, "</td><td valign=\"top\">")
s1, _ := strconv.ParseInt(aa[1], 10, 32)
fmt.Fprintf(w, "<input class=\"intp\" type=\"number\" min=\"0\" max=\"254\" name=\"ip2\" value=%d>\n", s1)
fmt.Fprintf(w, "</td><td valign=\"top\">")
s2, _ := strconv.ParseInt(aa[2], 10, 32)
fmt.Fprintf(w, "<input class=\"intp\" type=\"number\" min=\"0\" max=\"254\" name=\"ip3\" value=%d>\n", s2)
fmt.Fprintf(w, "</td><td valign=\"top\">")
s3, _ := strconv.ParseInt(aa[3], 10, 32)
fmt.Fprintf(w, "<input class=\"intp\" type=\"number\" min=\"0\" max=\"254\" name=\"ip4\" value=%d>\n", s3)
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<input type=\"hidden\" name=\"oldaddress\" value=%s>\n", adr)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"index\" value=%s>\n", nic)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"boardtype\" value=%s>\n", boardtype)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"board\" value=%s>\n", board)
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"setip\" value=\"setip\"> Set IP</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/changedip/\" >")
fmt.Fprintf(w, "<input type=\"hidden\" name=\"oldaddress\" value=%s>\n", adr)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"index\" value=%s>\n", nic)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"boardtype\" value=%s>\n", boardtype)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"board\" value=%s>\n", board)
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"dhcp\" value=\"dhcp\"> DHCP</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td><td valign=\"top\">")
fmt.Fprintf(w, "<form method=\"link\" action=\"/closescreen/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>\n")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to make the programs board web page.
func prghandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Program Interface page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
r.ParseForm()
boardtype := r.FormValue("boardtype")
intf := r.FormValue("index")
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("body").Parse(w2p)
t2.Execute(w, "body")
t3, _ := template.New("webbanner").Parse(banner)
t3.Execute(w, H)
fmt.Fprintf(w, "<h2>Program Interfaces</h2> <p> Please select the interface to perform a Board Program</p>")
fmt.Fprintf(w, "<legend>Get the latest RBF file from the repository</legend>\n")
if boardtype == "METIS" {
fmt.Fprintf(w, "<a href=\"http://%s:%s/nosite/\">%s</a><br/>\n", srvaddress, srvport, boardtype)
//fmt.Fprintf(w, "<a href=\"http://svn.tapr.org/repos_sdr_hpsdr/trunk/Metis/Release/\">%s</a><br/>\n", boardtype)
} else if boardtype == "HERMES" {
fmt.Fprintf(w, "<a href=\"http://%s:%s/nosite/\">%s</a><br/>\n", srvaddress, srvport, boardtype)
//fmt.Fprintf(w, "<a href=\"http://svn.tapr.org/repos_sdr_hpsdr/trunk/Hermes/Release/\">%s</a><br/>\n", boardtype)
} else if boardtype == "ANGELIA" {
fmt.Fprintf(w, "<a href=\"http://%s:%s/nosite/\">%s</a><br/>\n", srvaddress, srvport, boardtype)
//fmt.Fprintf(w, "<a href=\"http://www.k5so.com/HPSDR_downloads.html\">%s</a><br/>\n", boardtype)
} else if boardtype == "ORIAN" {
fmt.Fprintf(w, "<a href=\"http://%s:%s/nosite/\">%s</a><br/>\n", srvaddress, srvport, boardtype)
//fmt.Fprintf(w, "<a href=\"http://www.k5so.com/HPSDR_downloads.html\">%s</a><br/>\n", boardtype)
}
fmt.Fprintf(w, "<br/>")
fmt.Fprintf(w, "<form enctype=\"multipart/form-data\" action=\"/upload/\" method=\"post\">")
fmt.Fprintf(w, "<input type=\"hidden\" name=\"index\" value=%s>\n", intf)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"boardtype\" value=%s>\n", boardtype)
fmt.Fprintf(w, "<input type=\"hidden\" name=\"token\" value=\"{{.}}\">\n")
fmt.Fprintf(w, " Select a file: <input class=\"fileintp\" type=\"file\" accept=\".rbf, .RBF\" name=\"uploadfile\" id=\"uploadfile\">")
fmt.Fprintf(w, " <input class=\"btn\" type=\"submit\" value=\"Upload\">")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "<br/>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to make the programs board web page.
func filehandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Program Interface page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
r.ParseForm()
filename := r.FormValue("img")
//boardtype := r.FormValue("boardtype")
//intf := r.FormValue("index")
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t3, _ := template.New("body").Parse(w2p)
t3.Execute(w, "body")
t4, _ := template.New("webbanner").Parse(banner)
t4.Execute(w, H)
// Open the RBF file
rbffilename = filename
log.Println(" Looking for rbf file:", filename)
f, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer func() {
err := f.Close()
if err != nil {
log.Fatal(err)
}
}()
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr>\n")
fmt.Fprintf(w, "<td align=\"right\"><b class=\"nic1\">Erase flash memory:</b> </td>")
fmt.Fprintf(w, "<td><div id=\"output\" class=\"nic1\"> </div></td>")
fmt.Fprintf(w, "</tr><tr>\n")
fmt.Fprintf(w, "<td align=\"right\"><b class=\"nic1\">Programming:</b> </td>")
fmt.Fprintf(w, "<td><div id=\"packet\" class=\"nic1\"> </div></td>")
fmt.Fprintf(w, "</tr>\n")
fmt.Fprintf(w, "</table><br/><br/>\n")
t5, _ := template.New("script").Parse(w1cnt)
t5.Execute(w, H)
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/nic/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"nic\" value=\"nic\"> Return</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td>")
fmt.Fprintf(w, "<td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/closescreen/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to produce the quit warning web page.
func nositehandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served No Site Interface page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
r.ParseForm()
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("webbanner").Parse(banner)
t2.Execute(w, H)
t3, _ := template.New("body").Parse(w2p)
t3.Execute(w, "body")
fmt.Fprintf(w, "<h1>No site at this time!</h1> <p> Please select the Quit or Return</p>")
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/nic/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"nic\" value=\"nic\"> Return</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td>")
fmt.Fprintf(w, "<td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/close/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to produce the quit warning web page.
func closescreenhandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Close screen Interface page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
r.ParseForm()
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("webbanner").Parse(banner)
t2.Execute(w, H)
t3, _ := template.New("body").Parse(w2p)
t3.Execute(w, "body")
fmt.Fprintf(w, "<h1>Shutting down the HPSDRProgrammer!</h1> <p> Please select the Quit or Return</p>")
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/nic/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"nic\" value=\"nic\"> Return</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td>")
fmt.Fprintf(w, "<td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/close/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to stop the webserver.
func closehandler(w http.ResponseWriter, r *http.Request) {
log.Fatal("Program shut down by user!")
}
func changediphandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Changed IP Interface page.")
var H Html
H.Version = version
H.Protocol = protocol
H.Update = update
H.Address = srvaddress
H.Port = srvport
r.ParseForm()
nic := r.FormValue("index")
board := r.FormValue("board")
oadr := r.FormValue("oldaddress")
ip1 := r.FormValue("ip1")
ip2 := r.FormValue("ip2")
ip3 := r.FormValue("ip3")
ip4 := r.FormValue("ip4")
str := fmt.Sprintf("http://%s:%s/setip/json/?index=%s&board=%s&oldaddress=%s&ip1=%s&ip2=%s&ip3=%s&ip4=%s", srvaddress, srvport, nic, board, oadr, ip1, ip2, ip3, ip4)
res, err := http.Get(str)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err.Error())
}
var msg newopenhpsdr.SetIPmessage
err = json.Unmarshal(body, &msg)
//log.Printf("String %s\n", str)
//log.Printf("%v\n", msg)
if r.FormValue("dhcp") == "dhcp" {
msg.Newaddress = "dhcp"
}
t, _ := template.New("head").Parse(w1p)
t.Execute(w, "head")
t1, _ := template.New("style").Parse(w1style)
t1.Execute(w, "style")
t2, _ := template.New("body").Parse(w2p)
t2.Execute(w, "body")
t3, _ := template.New("webbanner").Parse(banner)
t3.Execute(w, H)
fmt.Fprintf(w, "<h1>Radio Board changed</h1> ")
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr><td align=\"right\">")
fmt.Fprintf(w, "<b>Message:</b>")
fmt.Fprintf(w, "</td><td> %s", msg.Message)
fmt.Fprintf(w, "</td></tr><tr><td><b>MAC Address:</b>")
fmt.Fprintf(w, "</td><td> %s", msg.Macaddress)
fmt.Fprintf(w, "</td></tr><tr><td><b>Old Address:</b>")
fmt.Fprintf(w, "</td><td> %s", msg.Oldaddress)
fmt.Fprintf(w, "</td></tr><tr><td><b>New Address:</b>")
fmt.Fprintf(w, "</td><td> %s", msg.Newaddress)
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "<table>")
fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/nic/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"return\" value=\"return\"> Return</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td>")
fmt.Fprintf(w, "<td>")
fmt.Fprintf(w, "<form method=\"link\" action=\"/closescreen/\" >")
fmt.Fprintf(w, "<button class=\"btn\" type=\"submit\" name=\"quit\" value=\"quit\"> Quit</button>")
fmt.Fprintf(w, "</form>")
fmt.Fprintf(w, "</td></tr>")
fmt.Fprintf(w, "</table>")
fmt.Fprintf(w, "</body>\n")
fmt.Fprintf(w, "</html>\n")
}
// Web handler function to produce the nic json packet.
func nicjsonhandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Network Interface json.")
intf := newopenhpsdr.Interfaces()
enc := json.NewEncoder(w)
enc.Encode(intf)
}
// Web handler function to produce the discover json packet.
func discoverjsonhandler(w http.ResponseWriter, r *http.Request) {
log.Println("Served Discovery json.")
r.ParseForm()
intf := newopenhpsdr.Interfaces()
var itr newopenhpsdr.Intface
nic, _ := strconv.ParseInt(r.FormValue("index"), 0, 0)
for i := range intf {
if nic == int64(intf[i].Index) {
itr = intf[i]
log.Printf("Match %s %s %s\n", nic, itr.Intname, itr.Matchname)
} else {
log.Printf("No Match %s (%s) (%s)\n", nic, itr.Intname, itr.Matchname)
}
}
var adr string