2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_VIRTUAL_HOST_H_
18 #define incl_HPHP_VIRTUAL_HOST_H_
20 #include "hphp/util/hdf.h"
21 #include "hphp/runtime/server/ip-block-map.h"
22 #include "hphp/runtime/base/ini-setting.h"
25 ///////////////////////////////////////////////////////////////////////////////
28 static VirtualHost
&GetDefault();
30 static VirtualHost
* Resolve(const std::string
& host
);
31 static void SetCurrent(VirtualHost
*vhost
);
32 static const VirtualHost
*GetCurrent();
33 static int64_t GetMaxPostSize();
34 static int64_t GetLowestMaxPostSize();
35 static int64_t GetUploadMaxFileSize();
36 static void UpdateSerializationSizeLimit();
37 static const std::vector
<std::string
> &GetAllowedDirectories();
38 static void SortAllowedDirectories(std::vector
<std::string
>& dirs
);
39 static bool IsDefault(const IniSetting::Map
&ini
, const Hdf
&vh
,
40 const std::string
&ini_key
= "");
43 VirtualHost(const IniSetting::Map
& ini
, const Hdf
& vh
,
44 const std::string
&ini_key
= "");
46 void init(const IniSetting::Map
& ini
, const Hdf
& vh
,
47 const std::string
&ini_key
= "");
48 void addAllowedDirectories(const std::vector
<std::string
>& dirs
);
49 int getRequestTimeoutSeconds(int defaultTimeout
) const;
50 int64_t getMaxPostSize() const;
52 const std::string
&getName() const { return m_name
;}
53 const std::string
&getPathTranslation() const { return m_pathTranslation
;}
54 const std::string
&getDocumentRoot() const { return m_documentRoot
;}
55 const std::map
<std::string
, std::string
> &getServerVars() const {
58 std::string
serverName(const std::string
&host
) const;
60 bool valid() const { return !(m_prefix
.empty() && !m_pattern
); }
61 bool match(const String
&host
) const;
62 bool disabled() const { return m_disabled
; }
64 // whether to check (and serve) files that exist before applying rewrite rules
65 bool checkExistenceBeforeRewrite() const {
66 return m_checkExistenceBeforeRewrite
;
68 // should we always decode the post data as if it were
69 // application/x-www-form-urlencoded
70 bool alwaysDecodePostData(const String
& url
) const;
73 bool rewriteURL(const String
& host
, String
&url
,
74 bool &qsa
, int &redirect
) const;
77 bool isBlocking(const std::string
&command
, const std::string
&ip
) const;
79 // query string filters
80 bool hasLogFilter() const { return !m_queryStringFilters
.empty();}
81 std::string
filterUrl(const std::string
&url
) const;
97 bool qsa
= false; // whether to append original query string
98 bool encode_backrefs
= false;
99 int redirect
= 0; // redirect status code (301 or 302) or 0 for no redirect
100 std::vector
<RewriteCond
> rewriteConds
;
103 struct QueryStringFilter
{
104 std::string urlPattern
; // matching URLs
105 std::string namePattern
; // matching parameter names
106 std::string replaceWith
; // what to replace with
109 struct VhostRuntimeOption
{
111 int requestTimeoutSeconds
= -1;
112 int64_t maxPostSize
= -1;
113 int64_t uploadMaxFileSize
= -1;
114 std::vector
<std::string
> allowedDirectories
;
115 int64_t serializationSizeLimit
= StringData::MaxSize
;
118 void initRuntimeOption(const IniSetting::Map
& ini
, const Hdf
& overwrite
);
119 bool m_disabled
= false;
120 bool m_checkExistenceBeforeRewrite
= true;
121 bool m_alwaysDecodePostData
= true;
122 std::set
<std::string
, stdltistr
> m_decodePostDataBlackList
;
124 std::string m_prefix
;
125 StringData
* m_pattern
{nullptr};
127 std::string m_serverName
;
128 std::map
<std::string
, std::string
> m_serverVars
;
129 std::string m_pathTranslation
;
130 std::string m_documentRoot
;
132 std::vector
<RewriteRule
> m_rewriteRules
;
133 std::shared_ptr
<IpBlockMap
> m_ipBlocks
;
134 std::vector
<QueryStringFilter
> m_queryStringFilters
;
136 VhostRuntimeOption m_runtimeOption
;
139 ///////////////////////////////////////////////////////////////////////////////
142 #endif // incl_HPHP_VIRTUAL_HOST_H_