summaryrefslogtreecommitdiff
path: root/util.cpp
blob: bdd1a51f1f891d3e0bfa4e40cdaffccc990528e9 (plain)
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
#include "util.h"

// creates a page that redirects the user to 'target' after 'timeout'
String makeRedirectPage(String target, int timeout) {
  String s = "<!DOCTYPE html><html><head>";
  s += "<meta name=\"viewport\" content=\"width=device-width,user-scalable=0\">";
  s += "<meta charset=\"utf-8\">";
  s += "<meta http-equiv=\"refresh\" content=\"" + String(timeout) + ";url=" + target + "\">";
  s += "<title>Weiterleitung…</title></head><body>";
  s += "<p>Leite nach <a href=\"" + target + "\">" + target + "</a> weiter…</p>";
  s += "</body></html>";
  return s;
}

// returns html skeleton filled with 'title' and 'contents'
String makePage(String title, String contents) {
  String s = "<!DOCTYPE html><html><head>";
  s += "<meta name=\"viewport\" content=\"width=device-width,user-scalable=0\">";
  s += "<meta charset=\"utf-8\">";
  s += "<title>";
  s += title;
  s += "</title></head><body>";
  s += contents;
  s += "</body></html>";
  return s;
}

String urlDecode(String input) {
  String s = input;
  s.replace("%20", " ");
  s.replace("+", " ");
  s.replace("%21", "!");
  s.replace("%22", "\"");
  s.replace("%23", "#");
  s.replace("%24", "$");
  s.replace("%25", "%");
  s.replace("%26", "&");
  s.replace("%27", "\'");
  s.replace("%28", "(");
  s.replace("%29", ")");
  s.replace("%30", "*");
  s.replace("%31", "+");
  s.replace("%2C", ",");
  s.replace("%2E", ".");
  s.replace("%2F", "/");
  s.replace("%2C", ",");
  s.replace("%3A", ":");
  s.replace("%3A", ";");
  s.replace("%3C", "<");
  s.replace("%3D", "=");
  s.replace("%3E", ">");
  s.replace("%3F", "?");
  s.replace("%40", "@");
  s.replace("%5B", "[");
  s.replace("%5C", "\\");
  s.replace("%5D", "]");
  s.replace("%5E", "^");
  s.replace("%5F", "-");
  s.replace("%60", "`");
  return s;
}

// converts IPv4 array to String
String ipToStr(IPAddress address) {
  String res = "";
  for (int i = 0; i < 3; i++) {
    res += address[i];
    res += ".";
  }
  res += String(address[3]);
  return res;
}