]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/ws-auth.hh
rec: mention rust compiler in compiling docs
[thirdparty/pdns.git] / pdns / ws-auth.hh
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22 #pragma once
23 #include <string>
24 #include <map>
25 #include <ctime>
26 #include <pthread.h>
27 #include "misc.hh"
28 #include "namespaces.hh"
29 #include "webserver.hh"
30 #include "statbag.hh"
31
32 class Ewma
33 {
34 public:
35 Ewma();
36
37 void submit(int val);
38 [[nodiscard]] double get10() const;
39 [[nodiscard]] double get5() const;
40 [[nodiscard]] double get1() const;
41 [[nodiscard]] double getMax() const;
42
43 private:
44 DTime dt;
45 int d_last{};
46 double d_10{}, d_5{}, d_1{}, d_max{};
47 };
48
49 class AuthWebServer
50 {
51 public:
52 AuthWebServer();
53 void go(StatBag& stats);
54 static string makePercentage(const double& val);
55
56 private:
57 void indexfunction(HttpRequest* req, HttpResponse* resp);
58 void jsonstat(HttpRequest* req, HttpResponse* resp);
59 void registerApiHandler(const string& url, std::function<void(HttpRequest*, HttpResponse*)> handler);
60 void webThread();
61 void statThread(StatBag& stats);
62
63 time_t d_start;
64 double d_min10, d_min5, d_min1;
65 Ewma d_queries, d_cachehits, d_cachemisses;
66 Ewma d_qcachehits, d_qcachemisses;
67 unique_ptr<WebServer> d_ws{nullptr};
68 };
69
70 void apiDocs(HttpRequest* req, HttpResponse* resp);