gopkg.in/hugelgupf/u-root.v2@v2.0.0-20180831055005-3f8fdb0ce09d/pkg/sos/html/wifi.html (about) 1 <head> 2 <script> 3 function sendConnect(elem, index) { 4 replaceWithConnecting(elem); 5 disableOtherButtons(elem); 6 essid = document.getElementById("essid".concat(index)).innerHTML 7 pass = document.getElementById("pass".concat(index)) ? 8 document.getElementById("pass".concat(index)).value : "" 9 id = document.getElementById("id".concat(index)) ? 10 document.getElementById("id".concat(index)).value : "" 11 fetch("http://localhost:{{.Port}}/connect", { 12 method: 'Post', 13 headers: { 14 'Accept': 'application/json', 15 'Content-Type': 'application/json' 16 }, 17 body: JSON.stringify({ 18 Essid: essid, 19 Pass: pass, 20 Id: id 21 }) 22 }) 23 .then(r => r.json()) 24 .then( s => { 25 if (s !== null) { 26 alert(s.Error); 27 window.location.reload(); 28 } 29 else { 30 window.location.reload(); 31 } 32 }) 33 .catch(err => alert(err)) 34 } 35 36 function replaceWithConnecting(elem) { 37 connectingTxt = document.createTextNode("Connecting..."); 38 elem.style.display = "none"; 39 elem.parentNode.appendChild(connectingTxt); 40 } 41 42 function sendRefresh(elem) { 43 elem.setAttribute("disabled", "true"); 44 elem.setAttribute("value","Refreshing"); 45 disableOtherButtons(elem); 46 fetch("http://localhost:{{.Port}}/refresh", { 47 method: 'Post' 48 }) 49 .then(r => r.json()) 50 .then( s => { 51 if (s !== null) { 52 alert(s.Error); 53 window.location.reload(); 54 } 55 else { 56 window.location.reload(); 57 } 58 }) 59 .catch(err => alert(err)) 60 } 61 62 function disableOtherButtons(elem) { 63 btns = document.getElementsByClassName("btn"); 64 for (let btn of btns) { 65 if (btn === elem) { 66 continue; 67 } 68 btn.setAttribute("disabled", "true"); 69 } 70 } 71 </script> 72 <title>WiFi</title> 73 <link rel="stylesheet" href="css/stylesheet.css"> 74 <meta charset="utf-8"> 75 </head> 76 77 <body> 78 <div class="banner"> 79 <h1><a href="http://localhost:8000" target="_blank" class="bannerbtn">Service of Services</a></h1> 80 </div> 81 82 <div class="content"> 83 {{$NoEnc := 0}} 84 {{$WpaPsk := 1}} 85 {{$WpaEap := 2}} 86 {{$connectedEssid := .ConnectedEssid}} 87 {{$connectingEssid := .ConnectingEssid}} 88 <div class="center"> 89 <h2 class="center">Available Networks</h2> 90 <table class="center"> 91 <tr> 92 <th>Essid</th> 93 <th>Identity</th> 94 <th>Password / Passphrase</th> 95 <th><input type="submit" class="textbutton" onclick=sendRefresh(this) value="Refresh"></th> 96 </tr> 97 {{range $idx, $opt := .WifiOpts}} 98 {{if eq $opt.AuthSuite $NoEnc}} 99 <tr> 100 <td id="essid{{$idx}}">{{$opt.Essid}}</td> 101 <td></td> 102 <td></td> 103 {{if and (eq $connectedEssid $opt.Essid) (ne $connectedEssid "")}} 104 <td>Connected</td> 105 {{else if and (and (eq $connectingEssid $opt.Essid) (ne $connectingEssid "")) (ne $connectingEssid $connectedEssid) }} 106 <td>Connecting...</td> 107 {{else}} 108 <td><input type="submit" class="textbutton" onclick="sendConnect(this, {{$idx}})" value="Connect"></td> 109 {{end}} 110 </tr> 111 {{else if eq $opt.AuthSuite $WpaPsk}} 112 <tr> 113 <td id="essid{{$idx}}">{{$opt.Essid}}</td> 114 <td></td> 115 <td><input type="password" id="pass{{$idx}}"></td> 116 {{if and (eq $connectedEssid $opt.Essid) (ne $connectedEssid "")}} 117 <td>Connected</td> 118 {{else if and (and (eq $connectingEssid $opt.Essid) (ne $connectingEssid "")) (ne $connectingEssid $connectedEssid) }} 119 <td>Connecting...</td> 120 {{else}} 121 <td><input type="submit" class="textbutton" onclick="sendConnect(this, {{$idx}})" value="Connect"></td> 122 {{end}} 123 </tr> 124 {{else if eq $opt.AuthSuite $WpaEap}} 125 <tr> 126 <td id="essid{{$idx}}">{{$opt.Essid}}</td> 127 <td><input type="text" id="id{{$idx}}"></td> 128 <td><input type="password" id="pass{{$idx}}"></td> 129 {{if and (eq $connectedEssid $opt.Essid) (ne $connectedEssid "")}} 130 <td>Connected</td> 131 {{else if and (and (eq $connectingEssid $opt.Essid) (ne $connectingEssid "")) (ne $connectingEssid $connectedEssid) }} 132 <td>Connecting...</td> 133 {{else}} 134 <td><input type="submit" class="textbutton" onclick="sendConnect(this, {{$idx}})" value="Connect"></td> 135 {{end}} 136 </tr> 137 {{else}} 138 <tr> 139 <td id="essid{{$idx}}">{{$opt.Essid}}</td> 140 <td colspan="3">Not a supported protocol</td> 141 </tr> 142 {{end}} 143 {{else}} 144 <td colspan="4">No essids found</td> 145 {{end}} 146 </table> 147 </div> 148 149 {{if and (ne $connectingEssid "") (ne $connectingEssid $connectedEssid) }} 150 <script>disableOtherButtons(null)</script> 151 {{end}} 152 </div> 153 154 </body>