aboutsummaryrefslogtreecommitdiff
path: root/src/wan.js
blob: 675ef18230779060d074d00db2c5fd587d83a4e9 (plain) (blame)
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
const { invoke } = window.__TAURI__.tauri;
const { ask, message } = window.__TAURI__.dialog;

let connectionStatusEl;
let connectionIpv4El;
let connectionIpv6El;

let credentialsUsernameEl;
let credentialsPasswordEl;
let credentialsSubmitEl;
let credentialsStatusEl;

let dhcpv6TimestampEl;
let dhcpv6SrvAddrEl;
let dhcpv6SrvIdEl;
let dhcpv6T1El;
let dhcpv6T2El;
let dhcpv6PrefixEl;
let dhcpv6WanAddrEl;
let dhcpv6PrefLftEl;
let dhcpv6ValidLftEl;
let dhcpv6Dns1El;
let dhcpv6Dns2El;
let dhcpv6AftrEl;

let dhcpv6DuidEl;
let dhcpv6SubmitEl;
let dhcpv6StatusEl;

async function refreshConnectionStatus() {
  const connectionStatus = await invoke("connection_status", {});

  connectionStatusEl.innerText = connectionStatus.session;
  connectionIpv4El.innerText = connectionStatus.ipv4;
  connectionIpv6El.innerText = connectionStatus.ipv6;
}

async function warmReconnect() {
  const error = await invoke("kill", { process: "rsdsl_pppoe3", signal: "hup" });

  if (error !== "") {
    await message("Befehl konnte nicht erteilt werden: " + error, {
      kind: "error",
      title: "Neusynchronisation nicht erfolgt"
    });
  }
}

async function coldReconnect() {
  const error = await invoke("kill", { process: "rsdsl_pppoe3", signal: "term" });

  if (error !== "") {
    await message("Befehl konnte nicht erteilt werden: " + error, {
      kind: "error",
      title: "Neueinwahl nicht erfolgt"
    });
  }
}

async function forceReconnect() {
  const error = await invoke("kill", { process: "rsdsl_pppoe3", signal: "kill" });

  if (error !== "") {
    await message("Befehl konnte nicht erteilt werden: " + error, {
      kind: "error",
      title: "Neueinwahl nicht erfolgt"
    });
  }
}

function showCredentials() {
  switch (credentialsPasswordEl.type) {
    case "password":
      credentialsPasswordEl.type = "text";
      break;
    case "text":
      credentialsPasswordEl.type = "password";
      break;
  }
}

async function loadCredentials() {
  credentialsStatusEl.innerText = "Lade aktuelle Zugangsdaten...";
  document.body.style.cursor = "progress";

  const currentCredentials = await invoke("load_wan_credentials", {});

  credentialsUsernameEl.value = currentCredentials.username;
  credentialsPasswordEl.value = currentCredentials.password;
  credentialsStatusEl.innerText = currentCredentials.status_text;
  document.body.style.cursor = "default";
}

async function changeCredentials() {
  // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
  credentialsUsernameEl.disabled = true;
  credentialsPasswordEl.disabled = true;
  credentialsSubmitEl.disabled = true;
  credentialsStatusEl.innerText = "Änderungsanfrage...";
  document.body.style.cursor = "progress";

  credentialsStatusEl.innerText = await invoke("change_wan_credentials", {
    credentials: {
      username: credentialsUsernameEl.value,
      password: credentialsPasswordEl.value
    }
  });

  credentialsUsernameEl.disabled = false;
  credentialsPasswordEl.disabled = false;
  credentialsSubmitEl.disabled = false;
  document.body.style.cursor = "default";

  const reconnect = await ask("Zum Übernehmen der neuen Zugangsdaten muss die Einwahl zum Internetanbieter neu aufgebaut werden. Dies dauert ca. 30 Sekunden. Möchten Sie die Einwahl jetzt neu herstellen?", {
    kind: "info",
    title: "Neueinwahl erforderlich"
  });

  if (reconnect) {
    await coldReconnect();
  }
}

async function refreshDhcpv6Status() {
  const dhcpv6Status = await invoke("dhcpv6_status", {});

  dhcpv6TimestampEl.innerText = dhcpv6Status.timestamp;
  dhcpv6SrvAddrEl.innerText = dhcpv6Status.srvaddr;
  dhcpv6SrvIdEl.innerText = dhcpv6Status.srvid;
  dhcpv6T1El.innerText = dhcpv6Status.t1;
  dhcpv6T2El.innerText = dhcpv6Status.t2;
  dhcpv6PrefixEl.innerText = dhcpv6Status.prefix;
  dhcpv6WanAddrEl.innerText = dhcpv6Status.wanaddr;
  dhcpv6PrefLftEl.innerText = dhcpv6Status.preflft;
  dhcpv6ValidLftEl.innerText = dhcpv6Status.validlft;
  dhcpv6Dns1El.innerText = dhcpv6Status.dns1;
  dhcpv6Dns2El.innerText = dhcpv6Status.dns2;
  dhcpv6AftrEl.innerText = dhcpv6Status.aftr;
}

async function loadDuid() {
  dhcpv6StatusEl.innerText = "Lade aktuellen Client-DUID...";
  document.body.style.cursor = "progress";

  const currentDuid = await invoke("load_duid", {});

  dhcpv6DuidEl.value = currentDuid.duid;
  dhcpv6StatusEl.innerText = currentDuid.status_text;
  document.body.style.cursor = "default";
}

async function changeDuid() {
  dhcpv6DuidEl.disabled = true;
  dhcpv6SubmitEl.disabled = true;
  dhcpv6StatusEl.innerText = "Änderungsanfrage...";
  document.body.style.cursor = "progress";

  const statusText = await invoke("change_duid", { duid: dhcpv6DuidEl.value });

  dhcpv6DuidEl.disabled = false;
  dhcpv6SubmitEl.disabled = false;
  dhcpv6StatusEl.innerText = statusText;
  document.body.style.cursor = "default";

  if (statusText === "Änderung erfolgreich") {
    const apply = await ask("Zum Übernehmen des neuen Client-DUID muss der DHCPv6-Client neu gestartet werden. Dies dauert ca. 30 Sekunden, sollte die Internetverbindung aber nicht unterbrechen. Dabei wird eine Verlängerung mit Serversuche durchgeführt. Möchten Sie den DHCPv6-Client jetzt neu starten?", {
      kind: "info",
      title: "DHCPv6-Client-Neustart erforderlich",
    });

    if (apply) {
      await killDhcpv6();
    }
  }
}

async function killDhcpv6() {
  const error = await invoke("kill", { process: "rsdsl_dhcp6", signal: "term" });

  if (error !== "") {
    await message("Befehl konnte nicht erteilt werden: " + error, {
      kind: "error",
      title: "DHCPv6-Client-Neustart nicht erfolgt",
    });
  }
}

window.addEventListener("DOMContentLoaded", () => {
  connectionStatusEl = document.querySelector("#connection-status");
  connectionIpv4El = document.querySelector("#connection-ipv4");
  connectionIpv6El = document.querySelector("#connection-ipv6");

  refreshConnectionStatus();

  document.querySelector("#connection-warm-reconnect").addEventListener("click", (e) => {
    e.preventDefault();
    warmReconnect();
  });
  document.querySelector("#connection-cold-reconnect").addEventListener("click", (e) => {
    e.preventDefault();
    coldReconnect();
  });
  document.querySelector("#connection-force-reconnect").addEventListener("click", (e) => {
    e.preventDefault();
    forceReconnect();
  });

  credentialsUsernameEl = document.querySelector("#credentials-username");
  credentialsPasswordEl = document.querySelector("#credentials-password");
  credentialsSubmitEl = document.querySelector("#credentials-submit");
  credentialsStatusEl = document.querySelector("#credentials-status");

  document.querySelector("#credentials-show").addEventListener("click", (e) => {
    e.preventDefault();
    showCredentials();
  });

  document.querySelector("#credentials-form").addEventListener("submit", (e) => {
    e.preventDefault();
    changeCredentials();
  });

  loadCredentials();

  dhcpv6TimestampEl = document.querySelector("#dhcpv6-timestamp");
  dhcpv6SrvAddrEl = document.querySelector("#dhcpv6-srvaddr");
  dhcpv6SrvIdEl = document.querySelector("#dhcpv6-srvid");
  dhcpv6T1El = document.querySelector("#dhcpv6-t1");
  dhcpv6T2El = document.querySelector("#dhcpv6-t2");
  dhcpv6PrefixEl = document.querySelector("#dhcpv6-prefix");
  dhcpv6WanAddrEl = document.querySelector("#dhcpv6-wanaddr");
  dhcpv6PrefLftEl = document.querySelector("#dhcpv6-preflft");
  dhcpv6ValidLftEl = document.querySelector("#dhcpv6-validlft");
  dhcpv6Dns1El = document.querySelector("#dhcpv6-dns1");
  dhcpv6Dns2El = document.querySelector("#dhcpv6-dns2");
  dhcpv6AftrEl = document.querySelector("#dhcpv6-aftr");

  refreshDhcpv6Status();

  document.querySelector("#dhcpv6-kill").addEventListener("click", (e) => {
    e.preventDefault();
    killDhcpv6();
  });

  dhcpv6DuidEl = document.querySelector("#dhcpv6-duid");
  dhcpv6SubmitEl = document.querySelector("#dhcpv6-submit");
  dhcpv6StatusEl = document.querySelector("#dhcpv6-status");

  document.querySelector("#dhcpv6-form").addEventListener("submit", (e) => {
    e.preventDefault();
    changeDuid();
  });

  loadDuid();
});

setInterval(refreshConnectionStatus, 3000);
setInterval(refreshDhcpv6Status, 3000);