-
Notifications
You must be signed in to change notification settings - Fork 2
/
EXTERNAL.ino
68 lines (61 loc) · 2.77 KB
/
EXTERNAL.ino
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
// find out if the request comes from inside the network
bool checkRemote(String url) {
//check if the first 9 characters of the router 192.168.0
if(securityLevel == 0) return false; // never remote
if ( url.indexOf(WiFi.gatewayIP().toString().substring(0, securityLevel)) == -1 ) return true; else return false;
}
// we come here when an unknown request is done
void handleNotFound(AsyncWebServerRequest *request) {
bool intern = false;
if(!checkRemote( request->client()->remoteIP().toString()) ) intern = true;
// **************************************************************************
// R E S T R I C T E D A R E A
// **************************************************************************
// access only from inside the network
if ( intern ) { //DebugPrintln("the request comes from inside the network");
String serverUrl = request->url().c_str();
Serial.println("serverUrl = " + serverUrl);
// if ( serverUrl.indexOf("/CONSOLE")>-1 ) {
// request->send_P(200, "text/html", CONSOLE_HTML);
// }
// if ( serverUrl.indexOf("/MENU")>-1 ) {
// Serial.println("requestUrl = " + request->url() ); // can we use this
// loginBoth(request, "admin");
// toSend = FPSTR(HTML_HEAD);
// toSend += FPSTR(MENUPAGE);
// request->send(200, "text/html", toSend);
// }
// POLL=;
if ( serverUrl.indexOf("POLL=") > -1) {
if(Polling)
{
request->send ( 200, "text/plain", "polling is automatic, skipping" ); //zend bevestiging
return;
}
if( diagNose != 0 ) consoleOut(F("handleNotFound found POLL="));
int x = serverUrl.indexOf("POLL=");
//DebugPrintln("serverUrl = " + serverUrl);
//DebugPrintln("sub = " + serverUrl.substring(6,7));
int inv = serverUrl.substring(6,7).toInt();
//DebugPrintln("inv= " + String(inv));
String teZenden = "polling inverternr " + String(inv);
if(inv > inverterCount-1 || zigbeeUp != 1) {
String teZenden="ERROR " + serverUrl + " zigbee down or inverter not exists !";
request->send ( 200, "text/plain", teZenden );
return;
}
iKeuze = inv;
teZenden = "polled inverter " + String(inv);
request->send ( 200, "text/plain", teZenden );
actionFlag = 47; // takes care for the polling
return;
}
// if we are here, no valid api was found
request->send ( 200, "text/plain", "ERROR this link is invalid, go back <--" );//send not found message
}
else
{ // not intern
//DebugPrint("\t\t\t\t unauthorized, not from inside the network : ");
request->send ( 200, "text/plain", "ERROR you are not authorised, go back <--" );//send not found message
}
}