Welcome to mirror list, hosted at ThFree Co, Russian Federation.

wsgateEHS.hpp « wsgate - github.com/FreeRDP/FreeRDP-WebConnect.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cc3cae33353591094d1525c081fb95b06167230e (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
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
#ifndef _WSGATE_EHS_
#define _WSGATE_EHS_

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <ehs/ehs.h>
#include <vector>
#include <sstream>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <typeinfo>
#include <cstdlib>
#include <cstdio>
#include <cerrno>
#include <boost/algorithm/string.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/regex.hpp>
#include <boost/optional/optional.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/detail/file_parser_error.hpp>

#include "common.hpp"
#include "btexception.hpp"
#include "base64.hpp"
#include "sha1.hpp"
#include "logging.hpp"
#include "wsendpoint.hpp"
#include "myrawsocket.hpp"
#include "nova_token_auth.hpp"

using namespace std;
using boost::algorithm::iequals;
using boost::algorithm::to_lower_copy;
using boost::algorithm::ends_with;
using boost::algorithm::replace_all;
using boost::algorithm::to_upper_copy;
using boost::algorithm::trim_right_copy_if;
using boost::algorithm::trim;
using boost::algorithm::is_any_of;
using boost::algorithm::split;
namespace po = boost::program_options;
namespace fs = boost::filesystem;
namespace pt = boost::posix_time;
using boost::filesystem::path;

namespace wsgate{
    // subclass of EHS that defines a custom HTTP response.
    class WsGate : public EHS
    {
        public:
            WsGate(EHS *parent = NULL, std::string registerpath = "");
            virtual ~WsGate();
            HttpResponse *HandleThreadException(ehs_threadid_t, HttpRequest *request, exception &ex);
            void CheckForPredefined(string& rdpHost, string& rdpUser, string& rdpPass);
            bool ConnectionIsAllowed(string rdphost);
            void LogInfo(std::basic_string<char> remoteAdress, string uri, const char response[]);
            ResponseCode HandleRobotsRequest(HttpRequest *request, HttpResponse *response, string uri, string thisHost);
            ResponseCode HandleCursorRequest(HttpRequest *request, HttpResponse *response, string uri, string thisHost);
            ResponseCode HandleRedirectRequest(HttpRequest *request, HttpResponse *response, string uri, string thisHost);
            int CheckIfWSocketRequest(HttpRequest *request, HttpResponse *response, string uri, string thisHost);
            ResponseCode HandleWsgateRequest(HttpRequest *request, HttpResponse *response, std::string uri, std::string thisHost);
            ResponseCode HandleRequest(HttpRequest *request, HttpResponse *response);
            ResponseCode HandleHTTPRequest(HttpRequest *request, HttpResponse *response, bool tokenAuth = false);
            boost::property_tree::ptree GetConfig();
            const string & GetConfigFile();
            bool GetEnableCore();
            bool SetConfigFile(const string &name);
            bool ReadConfig(wsgate::log *logger = NULL);
            bool GetDaemon();
            void SetPidFile(const string &name);
            void RegisterRdpSession(rdp_ptr rdp);
            void UnregisterRdpSession(rdp_ptr rdp);
            WsRdpOverrideParams getOverrideParams();
        private:
            typedef enum {
                TEXT,
                HTML,
                PNG,
                ICO,
                JAVASCRIPT,
                JSON,
                CSS,
                OGG,
                CUR,
                BINARY
            } MimeType;
            typedef map<string, rdp_ptr> SessionMap;
            typedef boost::tuple<time_t, string> cache_entry;
            typedef map<path, cache_entry> StaticCache;

            string m_sHostname;
            string m_sDocumentRoot;
            string m_sPidFile;
            bool m_bDebug;
            bool m_bEnableCore;
            SessionMap m_SessionMap;
            vector<boost::regex> m_allowedHosts;
            vector<boost::regex> m_deniedHosts;
            WsRdpOverrideParams overrideParams;
            bool m_bOrderDenyAllow;
            string m_sConfigFile;
            boost::property_tree::ptree m_ptIniConfig;
            bool m_bDaemon;
            bool m_bRedirect;
            StaticCache m_StaticCache;
            string m_sOpenStackAuthUrl;
            string m_sOpenStackUsername;
            string m_sOpenStackPassword;
            string m_sOpenStackTenantName;
            string m_sOpenStackProjectId;
            string m_sOpenStackKeystoneVersion;
            string m_sOpenStackRegion;
            string m_sHyperVHostUsername;
            string m_sHyperVHostPassword;

            // Non-copyable
            WsGate(const WsGate&);
            WsGate & operator=(const WsGate&);

            MimeType simpleMime(const string & filename);
            template <typename T> std::vector<T> as_vector(boost::property_tree::ptree const& pt, boost::property_tree::ptree::key_type const& key);
            bool notModified(HttpRequest *request, HttpResponse *response, time_t mtime);
            int str2bint(const string &s);
            bool str2bool(const string &s);
            void wc2pat(string &wildcards);
            void setHostList(const vector<string> &hosts, vector<boost::regex> &hostlist);
            void setAclOrder(const string &order);
    };
}

#endif