├── src ├── banned_ips.txt ├── static │ ├── images │ │ ├── favicon.ico │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── apple-touch-icon.png │ │ ├── ringo_high_quality.png │ │ ├── android-chrome-192x192.png │ │ ├── android-chrome-512x512.png │ │ └── site.webmanifest │ ├── css │ │ └── style.css │ └── js │ │ └── script.js ├── requirements.txt ├── templates │ ├── sidebar.html │ ├── register.html │ ├── login.html │ ├── api.html │ ├── tunnel_logs.html │ └── public_ip_settings.html ├── yaml-cpp │ └── include │ │ └── yaml-cpp │ │ ├── anchor.h │ │ ├── emitterstyle.h │ │ ├── node │ │ ├── type.h │ │ ├── detail │ │ │ ├── iterator_fwd.h │ │ │ ├── memory.h │ │ │ ├── iterator.h │ │ │ ├── node_ref.h │ │ │ ├── node_data.h │ │ │ ├── node_iterator.h │ │ │ ├── node.h │ │ │ └── impl.h │ │ ├── ptr.h │ │ ├── emit.h │ │ ├── iterator.h │ │ ├── parse.h │ │ ├── node.h │ │ ├── impl.h │ │ └── convert.h │ │ ├── emitterdef.h │ │ ├── noexcept.h │ │ ├── yaml.h │ │ ├── null.h │ │ ├── mark.h │ │ ├── contrib │ │ ├── anchordict.h │ │ └── graphbuilder.h │ │ ├── stlemitter.h │ │ ├── eventhandler.h │ │ ├── emitfromevents.h │ │ ├── dll.h │ │ ├── ostream_wrapper.h │ │ ├── binary.h │ │ ├── depthguard.h │ │ ├── parser.h │ │ ├── traits.h │ │ ├── emittermanip.h │ │ ├── emitter.h │ │ └── exceptions.h ├── config.yaml ├── tcp.sh ├── udp.sh └── forwarder.sh ├── telegramBot ├── requirements.txt ├── config.json └── robot.py └── LICENSE /src/banned_ips.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /telegramBot/requirements.txt: -------------------------------------------------------------------------------- 1 | python-telegram-bot>=20.0 2 | requests>=2.20.0 3 | PyYAML>=6.0 4 | -------------------------------------------------------------------------------- /src/static/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/favicon.ico -------------------------------------------------------------------------------- /src/requirements.txt: -------------------------------------------------------------------------------- 1 | Flask 2 | Flask-Caching 3 | Flask-Login 4 | bcrypt 5 | pyotp 6 | pyyaml 7 | psutil 8 | scapy 9 | -------------------------------------------------------------------------------- /src/static/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/favicon-16x16.png -------------------------------------------------------------------------------- /src/static/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/favicon-32x32.png -------------------------------------------------------------------------------- /src/static/images/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/apple-touch-icon.png -------------------------------------------------------------------------------- /src/static/images/ringo_high_quality.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/ringo_high_quality.png -------------------------------------------------------------------------------- /src/static/images/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/android-chrome-192x192.png -------------------------------------------------------------------------------- /src/static/images/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azumi67/proxyforwarder/HEAD/src/static/images/android-chrome-512x512.png -------------------------------------------------------------------------------- /telegramBot/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "telegram_bot_token": "YOUR_TELEGRAM_BOT_TOKEN", 3 | "api_base_url": "http://localhost:8080", 4 | "api_key": "YOUR_API_KEY" 5 | } 6 | -------------------------------------------------------------------------------- /src/static/images/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /src/templates/sidebar.html: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/anchor.h: -------------------------------------------------------------------------------- 1 | #ifndef ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | namespace YAML { 13 | using anchor_t = std::size_t; 14 | const anchor_t NullAnchor = 0; 15 | } 16 | 17 | #endif // ANCHOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 18 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/emitterstyle.h: -------------------------------------------------------------------------------- 1 | #ifndef EMITTERSTYLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EMITTERSTYLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | namespace YAML { 11 | namespace EmitterStyle { 12 | enum value { Default, Block, Flow }; 13 | } 14 | 15 | } 16 | 17 | #endif // EMITTERSTYLE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 18 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/type.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | namespace YAML { 11 | namespace NodeType { 12 | enum value { Undefined, Null, Scalar, Sequence, Map }; 13 | } 14 | 15 | } 16 | 17 | #endif // VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 18 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/emitterdef.h: -------------------------------------------------------------------------------- 1 | #ifndef EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | namespace YAML { 11 | struct EmitterNodeType { 12 | enum value { NoType, Property, Scalar, FlowSeq, BlockSeq, FlowMap, BlockMap }; 13 | }; 14 | } 15 | 16 | #endif // EMITTERDEF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 17 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/noexcept.h: -------------------------------------------------------------------------------- 1 | #ifndef NOEXCEPT_H_768872DA_476C_11EA_88B8_90B11C0C0FF8 2 | #define NOEXCEPT_H_768872DA_476C_11EA_88B8_90B11C0C0FF8 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | // This is here for compatibility with older versions of Visual Studio 11 | // which don't support noexcept. 12 | #if defined(_MSC_VER) && _MSC_VER < 1900 13 | #define YAML_CPP_NOEXCEPT _NOEXCEPT 14 | #else 15 | #define YAML_CPP_NOEXCEPT noexcept 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/static/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, sans-serif; 3 | display: flex; 4 | } 5 | 6 | .sidebar { 7 | width: 200px; 8 | background-color: #2c3e50; 9 | color: white; 10 | padding: 15px; 11 | height: 100vh; 12 | } 13 | 14 | .sidebar a { 15 | color: white; 16 | text-decoration: none; 17 | display: block; 18 | margin: 10px 0; 19 | } 20 | 21 | .content { 22 | padding: 20px; 23 | flex: 1; 24 | } 25 | 26 | .circle-container { 27 | display: flex; 28 | gap: 20px; 29 | } 30 | 31 | .circle { 32 | width: 100px; 33 | height: 100px; 34 | border-radius: 50%; 35 | display: flex; 36 | align-items: center; 37 | justify-content: center; 38 | background-color: #3498db; 39 | color: white; 40 | font-size: 18px; 41 | } -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/yaml.h: -------------------------------------------------------------------------------- 1 | #ifndef YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/parser.h" 11 | #include "yaml-cpp/emitter.h" 12 | #include "yaml-cpp/emitterstyle.h" 13 | #include "yaml-cpp/stlemitter.h" 14 | #include "yaml-cpp/exceptions.h" 15 | 16 | #include "yaml-cpp/node/node.h" 17 | #include "yaml-cpp/node/impl.h" 18 | #include "yaml-cpp/node/convert.h" 19 | #include "yaml-cpp/node/iterator.h" 20 | #include "yaml-cpp/node/detail/impl.h" 21 | #include "yaml-cpp/node/parse.h" 22 | #include "yaml-cpp/node/emit.h" 23 | 24 | #endif // YAML_H_62B23520_7C8E_11DE_8A39_0800200C9A66 25 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/null.h: -------------------------------------------------------------------------------- 1 | #ifndef NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include 12 | 13 | namespace YAML { 14 | class Node; 15 | 16 | struct YAML_CPP_API _Null {}; 17 | inline bool operator==(const _Null&, const _Null&) { return true; } 18 | inline bool operator!=(const _Null&, const _Null&) { return false; } 19 | 20 | YAML_CPP_API bool IsNull(const Node& node); // old API only 21 | YAML_CPP_API bool IsNullString(const std::string& str); 22 | 23 | extern YAML_CPP_API _Null Null; 24 | } 25 | 26 | #endif // NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 27 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/mark.h: -------------------------------------------------------------------------------- 1 | #ifndef MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | 12 | namespace YAML { 13 | struct YAML_CPP_API Mark { 14 | Mark() : pos(0), line(0), column(0) {} 15 | 16 | static const Mark null_mark() { return Mark(-1, -1, -1); } 17 | 18 | bool is_null() const { return pos == -1 && line == -1 && column == -1; } 19 | 20 | int pos; 21 | int line, column; 22 | 23 | private: 24 | Mark(int pos_, int line_, int column_) 25 | : pos(pos_), line(line_), column(column_) {} 26 | }; 27 | } 28 | 29 | #endif // MARK_H_62B23520_7C8E_11DE_8A39_0800200C9A66 30 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/iterator_fwd.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include 12 | #include 13 | #include 14 | 15 | namespace YAML { 16 | 17 | namespace detail { 18 | struct iterator_value; 19 | template 20 | class iterator_base; 21 | } 22 | 23 | using iterator = detail::iterator_base; 24 | using const_iterator = detail::iterator_base; 25 | } 26 | 27 | #endif // VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 28 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/ptr.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | namespace YAML { 13 | namespace detail { 14 | class node; 15 | class node_ref; 16 | class node_data; 17 | class memory; 18 | class memory_holder; 19 | 20 | using shared_node = std::shared_ptr; 21 | using shared_node_ref = std::shared_ptr; 22 | using shared_node_data = std::shared_ptr; 23 | using shared_memory_holder = std::shared_ptr; 24 | using shared_memory = std::shared_ptr; 25 | } 26 | } 27 | 28 | #endif // VALUE_PTR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 29 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/emit.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include "yaml-cpp/dll.h" 14 | 15 | namespace YAML { 16 | class Emitter; 17 | class Node; 18 | 19 | /** 20 | * Emits the node to the given {@link Emitter}. If there is an error in writing, 21 | * {@link Emitter#good} will return false. 22 | */ 23 | YAML_CPP_API Emitter& operator<<(Emitter& out, const Node& node); 24 | 25 | /** Emits the node to the given output stream. */ 26 | YAML_CPP_API std::ostream& operator<<(std::ostream& out, const Node& node); 27 | 28 | /** Converts the node to a YAML string. */ 29 | YAML_CPP_API std::string Dump(const Node& node); 30 | } // namespace YAML 31 | 32 | #endif // NODE_EMIT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 33 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/contrib/anchordict.h: -------------------------------------------------------------------------------- 1 | #ifndef ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | #include "../anchor.h" 13 | 14 | namespace YAML { 15 | /** 16 | * An object that stores and retrieves values correlating to {@link anchor_t} 17 | * values. 18 | * 19 | *

Efficient implementation that can make assumptions about how 20 | * {@code anchor_t} values are assigned by the {@link Parser} class. 21 | */ 22 | template 23 | class AnchorDict { 24 | public: 25 | AnchorDict() : m_data{} {} 26 | void Register(anchor_t anchor, T value) { 27 | if (anchor > m_data.size()) { 28 | m_data.resize(anchor); 29 | } 30 | m_data[anchor - 1] = value; 31 | } 32 | 33 | T Get(anchor_t anchor) const { return m_data[anchor - 1]; } 34 | 35 | private: 36 | std::vector m_data; 37 | }; 38 | } // namespace YAML 39 | 40 | #endif // ANCHORDICT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 41 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | #include "yaml-cpp/dll.h" 13 | #include "yaml-cpp/node/ptr.h" 14 | 15 | namespace YAML { 16 | namespace detail { 17 | class node; 18 | } // namespace detail 19 | } // namespace YAML 20 | 21 | namespace YAML { 22 | namespace detail { 23 | class YAML_CPP_API memory { 24 | public: 25 | memory() : m_nodes{} {} 26 | node& create_node(); 27 | void merge(const memory& rhs); 28 | 29 | private: 30 | using Nodes = std::set; 31 | Nodes m_nodes; 32 | }; 33 | 34 | class YAML_CPP_API memory_holder { 35 | public: 36 | memory_holder() : m_pMemory(new memory) {} 37 | 38 | node& create_node() { return m_pMemory->create_node(); } 39 | void merge(memory_holder& rhs); 40 | 41 | private: 42 | shared_memory m_pMemory; 43 | }; 44 | } // namespace detail 45 | } // namespace YAML 46 | 47 | #endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 48 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include "yaml-cpp/node/node.h" 12 | #include "yaml-cpp/node/detail/iterator_fwd.h" 13 | #include "yaml-cpp/node/detail/iterator.h" 14 | #include 15 | #include 16 | #include 17 | 18 | // Assert in place so gcc + libc++ combination properly builds 19 | static_assert(std::is_constructible::value, "Node must be copy constructable"); 20 | 21 | namespace YAML { 22 | namespace detail { 23 | struct iterator_value : public Node, std::pair { 24 | iterator_value() = default; 25 | explicit iterator_value(const Node& rhs) 26 | : Node(rhs), 27 | std::pair(Node(Node::ZombieNode), Node(Node::ZombieNode)) {} 28 | explicit iterator_value(const Node& key, const Node& value) 29 | : Node(Node::ZombieNode), std::pair(key, value) {} 30 | }; 31 | } 32 | } 33 | 34 | #endif // VALUE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 35 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/stlemitter.h: -------------------------------------------------------------------------------- 1 | #ifndef STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace YAML { 16 | template 17 | inline Emitter& EmitSeq(Emitter& emitter, const Seq& seq) { 18 | emitter << BeginSeq; 19 | for (const auto& v : seq) 20 | emitter << v; 21 | emitter << EndSeq; 22 | return emitter; 23 | } 24 | 25 | template 26 | inline Emitter& operator<<(Emitter& emitter, const std::vector& v) { 27 | return EmitSeq(emitter, v); 28 | } 29 | 30 | template 31 | inline Emitter& operator<<(Emitter& emitter, const std::list& v) { 32 | return EmitSeq(emitter, v); 33 | } 34 | 35 | template 36 | inline Emitter& operator<<(Emitter& emitter, const std::set& v) { 37 | return EmitSeq(emitter, v); 38 | } 39 | 40 | template 41 | inline Emitter& operator<<(Emitter& emitter, const std::map& m) { 42 | emitter << BeginMap; 43 | for (const auto& v : m) 44 | emitter << Key << v.first << Value << v.second; 45 | emitter << EndMap; 46 | return emitter; 47 | } 48 | } 49 | 50 | #endif // STLEMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 51 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/eventhandler.h: -------------------------------------------------------------------------------- 1 | #ifndef EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | #include "yaml-cpp/anchor.h" 13 | #include "yaml-cpp/emitterstyle.h" 14 | 15 | namespace YAML { 16 | struct Mark; 17 | 18 | class EventHandler { 19 | public: 20 | virtual ~EventHandler() = default; 21 | 22 | virtual void OnDocumentStart(const Mark& mark) = 0; 23 | virtual void OnDocumentEnd() = 0; 24 | 25 | virtual void OnNull(const Mark& mark, anchor_t anchor) = 0; 26 | virtual void OnAlias(const Mark& mark, anchor_t anchor) = 0; 27 | virtual void OnScalar(const Mark& mark, const std::string& tag, 28 | anchor_t anchor, const std::string& value) = 0; 29 | 30 | virtual void OnSequenceStart(const Mark& mark, const std::string& tag, 31 | anchor_t anchor, EmitterStyle::value style) = 0; 32 | virtual void OnSequenceEnd() = 0; 33 | 34 | virtual void OnMapStart(const Mark& mark, const std::string& tag, 35 | anchor_t anchor, EmitterStyle::value style) = 0; 36 | virtual void OnMapEnd() = 0; 37 | 38 | virtual void OnAnchor(const Mark& /*mark*/, 39 | const std::string& /*anchor_name*/) { 40 | // empty default implementation for compatibility 41 | } 42 | }; 43 | } // namespace YAML 44 | 45 | #endif // EVENTHANDLER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 46 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/emitfromevents.h: -------------------------------------------------------------------------------- 1 | #ifndef EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | #include "yaml-cpp/anchor.h" 13 | #include "yaml-cpp/emitterstyle.h" 14 | #include "yaml-cpp/eventhandler.h" 15 | 16 | namespace YAML { 17 | struct Mark; 18 | } // namespace YAML 19 | 20 | namespace YAML { 21 | class Emitter; 22 | 23 | class EmitFromEvents : public EventHandler { 24 | public: 25 | EmitFromEvents(Emitter& emitter); 26 | ~EmitFromEvents() override = default; 27 | 28 | void OnDocumentStart(const Mark& mark) override; 29 | void OnDocumentEnd() override; 30 | 31 | void OnNull(const Mark& mark, anchor_t anchor) override; 32 | void OnAlias(const Mark& mark, anchor_t anchor) override; 33 | void OnScalar(const Mark& mark, const std::string& tag, 34 | anchor_t anchor, const std::string& value) override; 35 | 36 | void OnSequenceStart(const Mark& mark, const std::string& tag, 37 | anchor_t anchor, EmitterStyle::value style) override; 38 | void OnSequenceEnd() override; 39 | 40 | void OnMapStart(const Mark& mark, const std::string& tag, 41 | anchor_t anchor, EmitterStyle::value style) override; 42 | void OnMapEnd() override; 43 | 44 | private: 45 | void BeginNode(); 46 | void EmitProps(const std::string& tag, anchor_t anchor); 47 | 48 | private: 49 | Emitter& m_emitter; 50 | 51 | struct State { 52 | enum value { WaitingForSequenceEntry, WaitingForKey, WaitingForValue }; 53 | }; 54 | std::stack m_stateStack; 55 | }; 56 | } 57 | 58 | #endif // EMITFROMEVENTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 59 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/dll.h: -------------------------------------------------------------------------------- 1 | #ifndef DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | // Definition YAML_CPP_STATIC_DEFINE using to building YAML-CPP as static 5 | // library (definition created by CMake or defined manually) 6 | 7 | // Definition yaml_cpp_EXPORTS using to building YAML-CPP as dll/so library 8 | // (definition created by CMake or defined manually) 9 | 10 | #ifdef YAML_CPP_STATIC_DEFINE 11 | # define YAML_CPP_API 12 | # define YAML_CPP_NO_EXPORT 13 | #else 14 | # if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) 15 | # ifndef YAML_CPP_API 16 | # ifdef yaml_cpp_EXPORTS 17 | /* We are building this library */ 18 | # define YAML_CPP_API __declspec(dllexport) 19 | # else 20 | /* We are using this library */ 21 | # define YAML_CPP_API __declspec(dllimport) 22 | # endif 23 | # endif 24 | # ifndef YAML_CPP_NO_EXPORT 25 | # define YAML_CPP_NO_EXPORT 26 | # endif 27 | # else /* No _MSC_VER */ 28 | # ifndef YAML_CPP_API 29 | # ifdef yaml_cpp_EXPORTS 30 | /* We are building this library */ 31 | # define YAML_CPP_API __attribute__((visibility("default"))) 32 | # else 33 | /* We are using this library */ 34 | # define YAML_CPP_API __attribute__((visibility("default"))) 35 | # endif 36 | # endif 37 | # ifndef YAML_CPP_NO_EXPORT 38 | # define YAML_CPP_NO_EXPORT __attribute__((visibility("hidden"))) 39 | # endif 40 | # endif /* _MSC_VER */ 41 | #endif /* YAML_CPP_STATIC_DEFINE */ 42 | 43 | #ifndef YAML_CPP_DEPRECATED 44 | # ifdef _MSC_VER 45 | # define YAML_CPP_DEPRECATED __declspec(deprecated) 46 | # else 47 | # define YAML_CPP_DEPRECATED __attribute__ ((__deprecated__)) 48 | # endif 49 | #endif 50 | 51 | #ifndef YAML_CPP_DEPRECATED_EXPORT 52 | # define YAML_CPP_DEPRECATED_EXPORT YAML_CPP_API YAML_CPP_DEPRECATED 53 | #endif 54 | 55 | #ifndef YAML_CPP_DEPRECATED_NO_EXPORT 56 | # define YAML_CPP_DEPRECATED_NO_EXPORT YAML_CPP_NO_EXPORT YAML_CPP_DEPRECATED 57 | #endif 58 | 59 | #endif /* DLL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 */ 60 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/ostream_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include "yaml-cpp/dll.h" 14 | 15 | namespace YAML { 16 | class YAML_CPP_API ostream_wrapper { 17 | public: 18 | ostream_wrapper(); 19 | explicit ostream_wrapper(std::ostream& stream); 20 | ostream_wrapper(const ostream_wrapper&) = delete; 21 | ostream_wrapper(ostream_wrapper&&) = delete; 22 | ostream_wrapper& operator=(const ostream_wrapper&) = delete; 23 | ostream_wrapper& operator=(ostream_wrapper&&) = delete; 24 | ~ostream_wrapper(); 25 | 26 | void write(const std::string& str); 27 | void write(const char* str, std::size_t size); 28 | 29 | void set_comment() { m_comment = true; } 30 | 31 | const char* str() const { 32 | if (m_pStream) { 33 | return nullptr; 34 | } else { 35 | m_buffer[m_pos] = '\0'; 36 | return &m_buffer[0]; 37 | } 38 | } 39 | 40 | std::size_t row() const { return m_row; } 41 | std::size_t col() const { return m_col; } 42 | std::size_t pos() const { return m_pos; } 43 | bool comment() const { return m_comment; } 44 | 45 | private: 46 | void update_pos(char ch); 47 | 48 | private: 49 | mutable std::vector m_buffer; 50 | std::ostream* const m_pStream; 51 | 52 | std::size_t m_pos; 53 | std::size_t m_row, m_col; 54 | bool m_comment; 55 | }; 56 | 57 | template 58 | inline ostream_wrapper& operator<<(ostream_wrapper& stream, 59 | const char (&str)[N]) { 60 | stream.write(str, N - 1); 61 | return stream; 62 | } 63 | 64 | inline ostream_wrapper& operator<<(ostream_wrapper& stream, 65 | const std::string& str) { 66 | stream.write(str); 67 | return stream; 68 | } 69 | 70 | inline ostream_wrapper& operator<<(ostream_wrapper& stream, char ch) { 71 | stream.write(&ch, 1); 72 | return stream; 73 | } 74 | } // namespace YAML 75 | 76 | #endif // OSTREAM_WRAPPER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 77 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/binary.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include "yaml-cpp/dll.h" 14 | 15 | namespace YAML { 16 | YAML_CPP_API std::string EncodeBase64(const unsigned char *data, 17 | std::size_t size); 18 | YAML_CPP_API std::vector DecodeBase64(const std::string &input); 19 | 20 | class YAML_CPP_API Binary { 21 | public: 22 | Binary(const unsigned char *data_, std::size_t size_) 23 | : m_data{}, m_unownedData(data_), m_unownedSize(size_) {} 24 | Binary() : Binary(nullptr, 0) {} 25 | Binary(const Binary &) = default; 26 | Binary(Binary &&) = default; 27 | Binary &operator=(const Binary &) = default; 28 | Binary &operator=(Binary &&) = default; 29 | 30 | bool owned() const { return !m_unownedData; } 31 | std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; } 32 | const unsigned char *data() const { 33 | return owned() ? &m_data[0] : m_unownedData; 34 | } 35 | 36 | void swap(std::vector &rhs) { 37 | if (m_unownedData) { 38 | m_data.swap(rhs); 39 | rhs.clear(); 40 | rhs.resize(m_unownedSize); 41 | std::copy(m_unownedData, m_unownedData + m_unownedSize, rhs.begin()); 42 | m_unownedData = nullptr; 43 | m_unownedSize = 0; 44 | } else { 45 | m_data.swap(rhs); 46 | } 47 | } 48 | 49 | bool operator==(const Binary &rhs) const { 50 | const std::size_t s = size(); 51 | if (s != rhs.size()) 52 | return false; 53 | const unsigned char *d1 = data(); 54 | const unsigned char *d2 = rhs.data(); 55 | for (std::size_t i = 0; i < s; i++) { 56 | if (*d1++ != *d2++) 57 | return false; 58 | } 59 | return true; 60 | } 61 | 62 | bool operator!=(const Binary &rhs) const { return !(*this == rhs); } 63 | 64 | private: 65 | std::vector m_data; 66 | const unsigned char *m_unownedData; 67 | std::size_t m_unownedSize; 68 | }; 69 | } // namespace YAML 70 | 71 | #endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66 72 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/parse.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "yaml-cpp/dll.h" 15 | 16 | namespace YAML { 17 | class Node; 18 | 19 | /** 20 | * Loads the input string as a single YAML document. 21 | * 22 | * @throws {@link ParserException} if it is malformed. 23 | */ 24 | YAML_CPP_API Node Load(const std::string& input); 25 | 26 | /** 27 | * Loads the input string as a single YAML document. 28 | * 29 | * @throws {@link ParserException} if it is malformed. 30 | */ 31 | YAML_CPP_API Node Load(const char* input); 32 | 33 | /** 34 | * Loads the input stream as a single YAML document. 35 | * 36 | * @throws {@link ParserException} if it is malformed. 37 | */ 38 | YAML_CPP_API Node Load(std::istream& input); 39 | 40 | /** 41 | * Loads the input file as a single YAML document. 42 | * 43 | * @throws {@link ParserException} if it is malformed. 44 | * @throws {@link BadFile} if the file cannot be loaded. 45 | */ 46 | YAML_CPP_API Node LoadFile(const std::string& filename); 47 | 48 | /** 49 | * Loads the input string as a list of YAML documents. 50 | * 51 | * @throws {@link ParserException} if it is malformed. 52 | */ 53 | YAML_CPP_API std::vector LoadAll(const std::string& input); 54 | 55 | /** 56 | * Loads the input string as a list of YAML documents. 57 | * 58 | * @throws {@link ParserException} if it is malformed. 59 | */ 60 | YAML_CPP_API std::vector LoadAll(const char* input); 61 | 62 | /** 63 | * Loads the input stream as a list of YAML documents. 64 | * 65 | * @throws {@link ParserException} if it is malformed. 66 | */ 67 | YAML_CPP_API std::vector LoadAll(std::istream& input); 68 | 69 | /** 70 | * Loads the input file as a list of YAML documents. 71 | * 72 | * @throws {@link ParserException} if it is malformed. 73 | * @throws {@link BadFile} if the file cannot be loaded. 74 | */ 75 | YAML_CPP_API std::vector LoadAllFromFile(const std::string& filename); 76 | } // namespace YAML 77 | 78 | #endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 79 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/depthguard.h: -------------------------------------------------------------------------------- 1 | #ifndef DEPTH_GUARD_H_00000000000000000000000000000000000000000000000000000000 2 | #define DEPTH_GUARD_H_00000000000000000000000000000000000000000000000000000000 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "exceptions.h" 11 | 12 | namespace YAML { 13 | 14 | /** 15 | * @brief The DeepRecursion class 16 | * An exception class which is thrown by DepthGuard. Ideally it should be 17 | * a member of DepthGuard. However, DepthGuard is a templated class which means 18 | * that any catch points would then need to know the template parameters. It is 19 | * simpler for clients to not have to know at the catch point what was the 20 | * maximum depth. 21 | */ 22 | class DeepRecursion : public ParserException { 23 | public: 24 | virtual ~DeepRecursion() = default; 25 | 26 | DeepRecursion(int depth, const Mark& mark_, const std::string& msg_); 27 | 28 | // Returns the recursion depth when the exception was thrown 29 | int depth() const { 30 | return m_depth; 31 | } 32 | 33 | private: 34 | int m_depth = 0; 35 | }; 36 | 37 | /** 38 | * @brief The DepthGuard class 39 | * DepthGuard takes a reference to an integer. It increments the integer upon 40 | * construction of DepthGuard and decrements the integer upon destruction. 41 | * 42 | * If the integer would be incremented past max_depth, then an exception is 43 | * thrown. This is ideally geared toward guarding against deep recursion. 44 | * 45 | * @param max_depth 46 | * compile-time configurable maximum depth. 47 | */ 48 | template 49 | class DepthGuard final { 50 | public: 51 | DepthGuard(int & depth_, const Mark& mark_, const std::string& msg_) : m_depth(depth_) { 52 | ++m_depth; 53 | if ( max_depth <= m_depth ) { 54 | throw DeepRecursion{m_depth, mark_, msg_}; 55 | } 56 | } 57 | 58 | DepthGuard(const DepthGuard & copy_ctor) = delete; 59 | DepthGuard(DepthGuard && move_ctor) = delete; 60 | DepthGuard & operator=(const DepthGuard & copy_assign) = delete; 61 | DepthGuard & operator=(DepthGuard && move_assign) = delete; 62 | 63 | ~DepthGuard() { 64 | --m_depth; 65 | } 66 | 67 | int current_depth() const { 68 | return m_depth; 69 | } 70 | 71 | private: 72 | int & m_depth; 73 | }; 74 | 75 | } // namespace YAML 76 | 77 | #endif // DEPTH_GUARD_H_00000000000000000000000000000000000000000000000000000000 78 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include "yaml-cpp/dll.h" 14 | 15 | namespace YAML { 16 | class EventHandler; 17 | class Node; 18 | class Scanner; 19 | struct Directives; 20 | struct Token; 21 | 22 | /** 23 | * A parser turns a stream of bytes into one stream of "events" per YAML 24 | * document in the input stream. 25 | */ 26 | class YAML_CPP_API Parser { 27 | public: 28 | /** Constructs an empty parser (with no input. */ 29 | Parser(); 30 | 31 | Parser(const Parser&) = delete; 32 | Parser(Parser&&) = delete; 33 | Parser& operator=(const Parser&) = delete; 34 | Parser& operator=(Parser&&) = delete; 35 | 36 | /** 37 | * Constructs a parser from the given input stream. The input stream must 38 | * live as long as the parser. 39 | */ 40 | explicit Parser(std::istream& in); 41 | 42 | ~Parser(); 43 | 44 | /** Evaluates to true if the parser has some valid input to be read. */ 45 | explicit operator bool() const; 46 | 47 | /** 48 | * Resets the parser with the given input stream. Any existing state is 49 | * erased. 50 | */ 51 | void Load(std::istream& in); 52 | 53 | /** 54 | * Handles the next document by calling events on the {@code eventHandler}. 55 | * 56 | * @throw a ParserException on error. 57 | * @return false if there are no more documents 58 | */ 59 | bool HandleNextDocument(EventHandler& eventHandler); 60 | 61 | void PrintTokens(std::ostream& out); 62 | 63 | private: 64 | /** 65 | * Reads any directives that are next in the queue, setting the internal 66 | * {@code m_pDirectives} state. 67 | */ 68 | void ParseDirectives(); 69 | 70 | void HandleDirective(const Token& token); 71 | 72 | /** 73 | * Handles a "YAML" directive, which should be of the form 'major.minor' (like 74 | * a version number). 75 | */ 76 | void HandleYamlDirective(const Token& token); 77 | 78 | /** 79 | * Handles a "TAG" directive, which should be of the form 'handle prefix', 80 | * where 'handle' is converted to 'prefix' in the file. 81 | */ 82 | void HandleTagDirective(const Token& token); 83 | 84 | private: 85 | std::unique_ptr m_pScanner; 86 | std::unique_ptr m_pDirectives; 87 | }; 88 | } // namespace YAML 89 | 90 | #endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 91 | -------------------------------------------------------------------------------- /src/config.yaml: -------------------------------------------------------------------------------- 1 | #TCP USAGE 2 | forwarders: 3 | - listen_address: "0.0.0.0" # Address to listen on (IPv4) 4 | listen_port: 8080 # Port to listen on 5 | target_address: "192.168.1.10" # Target address to forward traffic to 6 | target_port: 9090 # Target port to forward traffic to 7 | 8 | - listen_address: "::" # Address to listen on (IPv6) 9 | listen_port: 7070 # Another forwarder configuration 10 | target_address: "2001:db8::1" 11 | target_port: 8081 12 | # port range 13 | - listen_address: "0.0.0.0" 14 | target_address: "192.168.1.10" 15 | port_range: 16 | start: 8080 17 | end: 8085 18 | 19 | - listen_address: "::" # IPv6 address 20 | target_address: "fe80::1" # IPv6 target address 21 | port_range: 22 | start: 9090 23 | end: 9095 24 | 25 | thread_pool: 26 | threads: 2 # threads based on the number of cpu cores 27 | 28 | max_connections: 200 # Maximum number of simultaneous active connections 29 | retry_attempts: 5 # Number of retry attempts for connections 30 | retry_delay: 10 # delay between retries in seconds 31 | tcp_no_delay: false # Disable Nagle's algorithm for low latency 32 | buffer_size: 8092 #max buffer size 65535 or whatever 33 | 34 | monitoring_port: 8080 # monitoring port used by flask 35 | 36 | timeout: 37 | connection: 3000 # Timeout for connections in seconds 38 | 39 | health_check: 40 | enabled: true #true or false 41 | interval: 300 # Interval for performing health checks in seconds 42 | 43 | tcp_keep_alive: 44 | enabled: true # enable or disable TCP keepalive 45 | idle: 60 # time in seconds the connection is idle before keepalive goods are sent 46 | interval: 10 # time in seconds between individual keep-alive probes 47 | count: 5 # number of keepalive goods sent before the connection is dropped 48 | 49 | logging: 50 | enabled: true # Enable or disable logging (true/false) 51 | file: "logfile.log" # Name of the file 52 | level: "INFO" # Options: "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "ALL" 53 | 54 | 55 | 56 | #UDP USAGE 57 | srcAddrPorts: 58 | - "0.0.0.0:1150" #only ipv4, USE Geneve local ip if your server is limited 59 | - "0.0.0.0:1151" 60 | dstAddrPorts: 61 | - "66.200.1.1:1150" 62 | - "66.200.1.2:1151" 63 | 64 | timeout: 3000 # Timeout for idle connections (in seconds) 65 | buffer_size: 8092 #buffer size or max 65530 66 | thread_pool: 67 | threads: 2 68 | 69 | logging: 70 | enabled: true # Enable/disable logging 71 | file: "logfile.log" #log file directory 72 | level: "INFO" # Log level: TRACE, DEBUG, INFO, WARN, ERROR 73 | monitroing_port: 8080 # or whatever port you want 74 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include "yaml-cpp/node/detail/node_iterator.h" 12 | #include "yaml-cpp/node/node.h" 13 | #include "yaml-cpp/node/ptr.h" 14 | #include 15 | #include 16 | 17 | 18 | namespace YAML { 19 | namespace detail { 20 | struct iterator_value; 21 | 22 | template 23 | class iterator_base { 24 | 25 | private: 26 | template 27 | friend class iterator_base; 28 | struct enabler {}; 29 | using base_type = node_iterator; 30 | 31 | struct proxy { 32 | explicit proxy(const V& x) : m_ref(x) {} 33 | V* operator->() { return std::addressof(m_ref); } 34 | operator V*() { return std::addressof(m_ref); } 35 | 36 | V m_ref; 37 | }; 38 | 39 | public: 40 | using iterator_category = std::forward_iterator_tag; 41 | using value_type = V; 42 | using difference_type = std::ptrdiff_t; 43 | using pointer = V*; 44 | using reference = V&; 45 | 46 | public: 47 | iterator_base() : m_iterator(), m_pMemory() {} 48 | explicit iterator_base(base_type rhs, shared_memory_holder pMemory) 49 | : m_iterator(rhs), m_pMemory(pMemory) {} 50 | 51 | template 52 | iterator_base(const iterator_base& rhs, 53 | typename std::enable_if::value, 54 | enabler>::type = enabler()) 55 | : m_iterator(rhs.m_iterator), m_pMemory(rhs.m_pMemory) {} 56 | 57 | iterator_base& operator++() { 58 | ++m_iterator; 59 | return *this; 60 | } 61 | 62 | iterator_base operator++(int) { 63 | iterator_base iterator_pre(*this); 64 | ++(*this); 65 | return iterator_pre; 66 | } 67 | 68 | template 69 | bool operator==(const iterator_base& rhs) const { 70 | return m_iterator == rhs.m_iterator; 71 | } 72 | 73 | template 74 | bool operator!=(const iterator_base& rhs) const { 75 | return m_iterator != rhs.m_iterator; 76 | } 77 | 78 | value_type operator*() const { 79 | const typename base_type::value_type& v = *m_iterator; 80 | if (v.pNode) 81 | return value_type(Node(*v, m_pMemory)); 82 | if (v.first && v.second) 83 | return value_type(Node(*v.first, m_pMemory), Node(*v.second, m_pMemory)); 84 | return value_type(); 85 | } 86 | 87 | proxy operator->() const { return proxy(**this); } 88 | 89 | private: 90 | base_type m_iterator; 91 | shared_memory_holder m_pMemory; 92 | }; 93 | } // namespace detail 94 | } // namespace YAML 95 | 96 | #endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 97 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/traits.h: -------------------------------------------------------------------------------- 1 | #ifndef TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace YAML { 16 | template 17 | struct is_numeric { 18 | enum { value = false }; 19 | }; 20 | 21 | template <> 22 | struct is_numeric { 23 | enum { value = true }; 24 | }; 25 | template <> 26 | struct is_numeric { 27 | enum { value = true }; 28 | }; 29 | template <> 30 | struct is_numeric { 31 | enum { value = true }; 32 | }; 33 | template <> 34 | struct is_numeric { 35 | enum { value = true }; 36 | }; 37 | template <> 38 | struct is_numeric { 39 | enum { value = true }; 40 | }; 41 | template <> 42 | struct is_numeric { 43 | enum { value = true }; 44 | }; 45 | template <> 46 | struct is_numeric { 47 | enum { value = true }; 48 | }; 49 | template <> 50 | struct is_numeric { 51 | enum { value = true }; 52 | }; 53 | #if defined(_MSC_VER) && (_MSC_VER < 1310) 54 | template <> 55 | struct is_numeric<__int64> { 56 | enum { value = true }; 57 | }; 58 | template <> 59 | struct is_numeric { 60 | enum { value = true }; 61 | }; 62 | #else 63 | template <> 64 | struct is_numeric { 65 | enum { value = true }; 66 | }; 67 | template <> 68 | struct is_numeric { 69 | enum { value = true }; 70 | }; 71 | #endif 72 | template <> 73 | struct is_numeric { 74 | enum { value = true }; 75 | }; 76 | template <> 77 | struct is_numeric { 78 | enum { value = true }; 79 | }; 80 | template <> 81 | struct is_numeric { 82 | enum { value = true }; 83 | }; 84 | 85 | template 86 | struct enable_if_c { 87 | using type = T; 88 | }; 89 | 90 | template 91 | struct enable_if_c {}; 92 | 93 | template 94 | struct enable_if : public enable_if_c {}; 95 | 96 | template 97 | struct disable_if_c { 98 | using type = T; 99 | }; 100 | 101 | template 102 | struct disable_if_c {}; 103 | 104 | template 105 | struct disable_if : public disable_if_c {}; 106 | } 107 | 108 | template 109 | struct is_streamable { 110 | template 111 | static auto test(int) 112 | -> decltype(std::declval() << std::declval(), std::true_type()); 113 | 114 | template 115 | static auto test(...) -> std::false_type; 116 | 117 | static const bool value = decltype(test(0))::value; 118 | }; 119 | 120 | template 121 | struct streamable_to_string { 122 | static std::string impl(const Key& key) { 123 | std::stringstream ss; 124 | ss.imbue(std::locale("C")); 125 | ss << key; 126 | return ss.str(); 127 | } 128 | }; 129 | 130 | template 131 | struct streamable_to_string { 132 | static std::string impl(const Key&) { 133 | return ""; 134 | } 135 | }; 136 | #endif // TRAITS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 137 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/node_ref.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include "yaml-cpp/node/type.h" 12 | #include "yaml-cpp/node/ptr.h" 13 | #include "yaml-cpp/node/detail/node_data.h" 14 | 15 | namespace YAML { 16 | namespace detail { 17 | class node_ref { 18 | public: 19 | node_ref() : m_pData(new node_data) {} 20 | node_ref(const node_ref&) = delete; 21 | node_ref& operator=(const node_ref&) = delete; 22 | 23 | bool is_defined() const { return m_pData->is_defined(); } 24 | const Mark& mark() const { return m_pData->mark(); } 25 | NodeType::value type() const { return m_pData->type(); } 26 | const std::string& scalar() const { return m_pData->scalar(); } 27 | const std::string& tag() const { return m_pData->tag(); } 28 | EmitterStyle::value style() const { return m_pData->style(); } 29 | 30 | void mark_defined() { m_pData->mark_defined(); } 31 | void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; } 32 | 33 | void set_mark(const Mark& mark) { m_pData->set_mark(mark); } 34 | void set_type(NodeType::value type) { m_pData->set_type(type); } 35 | void set_tag(const std::string& tag) { m_pData->set_tag(tag); } 36 | void set_null() { m_pData->set_null(); } 37 | void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } 38 | void set_style(EmitterStyle::value style) { m_pData->set_style(style); } 39 | 40 | // size/iterator 41 | std::size_t size() const { return m_pData->size(); } 42 | 43 | const_node_iterator begin() const { 44 | return static_cast(*m_pData).begin(); 45 | } 46 | node_iterator begin() { return m_pData->begin(); } 47 | 48 | const_node_iterator end() const { 49 | return static_cast(*m_pData).end(); 50 | } 51 | node_iterator end() { return m_pData->end(); } 52 | 53 | // sequence 54 | void push_back(node& node, shared_memory_holder pMemory) { 55 | m_pData->push_back(node, pMemory); 56 | } 57 | void insert(node& key, node& value, shared_memory_holder pMemory) { 58 | m_pData->insert(key, value, pMemory); 59 | } 60 | 61 | // indexing 62 | template 63 | node* get(const Key& key, shared_memory_holder pMemory) const { 64 | return static_cast(*m_pData).get(key, pMemory); 65 | } 66 | template 67 | node& get(const Key& key, shared_memory_holder pMemory) { 68 | return m_pData->get(key, pMemory); 69 | } 70 | template 71 | bool remove(const Key& key, shared_memory_holder pMemory) { 72 | return m_pData->remove(key, pMemory); 73 | } 74 | 75 | node* get(node& key, shared_memory_holder pMemory) const { 76 | return static_cast(*m_pData).get(key, pMemory); 77 | } 78 | node& get(node& key, shared_memory_holder pMemory) { 79 | return m_pData->get(key, pMemory); 80 | } 81 | bool remove(node& key, shared_memory_holder pMemory) { 82 | return m_pData->remove(key, pMemory); 83 | } 84 | 85 | // map 86 | template 87 | void force_insert(const Key& key, const Value& value, 88 | shared_memory_holder pMemory) { 89 | m_pData->force_insert(key, value, pMemory); 90 | } 91 | 92 | private: 93 | shared_node_data m_pData; 94 | }; 95 | } 96 | } 97 | 98 | #endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 99 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/emittermanip.h: -------------------------------------------------------------------------------- 1 | #ifndef EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | 12 | namespace YAML { 13 | enum EMITTER_MANIP { 14 | // general manipulators 15 | Auto, 16 | TagByKind, 17 | Newline, 18 | 19 | // output character set 20 | EmitNonAscii, 21 | EscapeNonAscii, 22 | EscapeAsJson, 23 | 24 | // string manipulators 25 | // Auto, // duplicate 26 | SingleQuoted, 27 | DoubleQuoted, 28 | Literal, 29 | 30 | // null manipulators 31 | LowerNull, 32 | UpperNull, 33 | CamelNull, 34 | TildeNull, 35 | 36 | // bool manipulators 37 | YesNoBool, // yes, no 38 | TrueFalseBool, // true, false 39 | OnOffBool, // on, off 40 | UpperCase, // TRUE, N 41 | LowerCase, // f, yes 42 | CamelCase, // No, Off 43 | LongBool, // yes, On 44 | ShortBool, // y, t 45 | 46 | // int manipulators 47 | Dec, 48 | Hex, 49 | Oct, 50 | 51 | // document manipulators 52 | BeginDoc, 53 | EndDoc, 54 | 55 | // sequence manipulators 56 | BeginSeq, 57 | EndSeq, 58 | Flow, 59 | Block, 60 | 61 | // map manipulators 62 | BeginMap, 63 | EndMap, 64 | Key, 65 | Value, 66 | // Flow, // duplicate 67 | // Block, // duplicate 68 | // Auto, // duplicate 69 | LongKey 70 | }; 71 | 72 | struct _Indent { 73 | _Indent(int value_) : value(value_) {} 74 | int value; 75 | }; 76 | 77 | inline _Indent Indent(int value) { return _Indent(value); } 78 | 79 | struct _Alias { 80 | _Alias(const std::string& content_) : content(content_) {} 81 | std::string content; 82 | }; 83 | 84 | inline _Alias Alias(const std::string& content) { return _Alias(content); } 85 | 86 | struct _Anchor { 87 | _Anchor(const std::string& content_) : content(content_) {} 88 | std::string content; 89 | }; 90 | 91 | inline _Anchor Anchor(const std::string& content) { return _Anchor(content); } 92 | 93 | struct _Tag { 94 | struct Type { 95 | enum value { Verbatim, PrimaryHandle, NamedHandle }; 96 | }; 97 | 98 | explicit _Tag(const std::string& prefix_, const std::string& content_, 99 | Type::value type_) 100 | : prefix(prefix_), content(content_), type(type_) {} 101 | std::string prefix; 102 | std::string content; 103 | Type::value type; 104 | }; 105 | 106 | inline _Tag VerbatimTag(const std::string& content) { 107 | return _Tag("", content, _Tag::Type::Verbatim); 108 | } 109 | 110 | inline _Tag LocalTag(const std::string& content) { 111 | return _Tag("", content, _Tag::Type::PrimaryHandle); 112 | } 113 | 114 | inline _Tag LocalTag(const std::string& prefix, const std::string content) { 115 | return _Tag(prefix, content, _Tag::Type::NamedHandle); 116 | } 117 | 118 | inline _Tag SecondaryTag(const std::string& content) { 119 | return _Tag("", content, _Tag::Type::NamedHandle); 120 | } 121 | 122 | struct _Comment { 123 | _Comment(const std::string& content_) : content(content_) {} 124 | std::string content; 125 | }; 126 | 127 | inline _Comment Comment(const std::string& content) { return _Comment(content); } 128 | 129 | struct _Precision { 130 | _Precision(int floatPrecision_, int doublePrecision_) 131 | : floatPrecision(floatPrecision_), doublePrecision(doublePrecision_) {} 132 | 133 | int floatPrecision; 134 | int doublePrecision; 135 | }; 136 | 137 | inline _Precision FloatPrecision(int n) { return _Precision(n, -1); } 138 | 139 | inline _Precision DoublePrecision(int n) { return _Precision(-1, n); } 140 | 141 | inline _Precision Precision(int n) { return _Precision(n, n); } 142 | } 143 | 144 | #endif // EMITTERMANIP_H_62B23520_7C8E_11DE_8A39_0800200C9A66 145 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/node_data.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "yaml-cpp/dll.h" 17 | #include "yaml-cpp/node/detail/node_iterator.h" 18 | #include "yaml-cpp/node/iterator.h" 19 | #include "yaml-cpp/node/ptr.h" 20 | #include "yaml-cpp/node/type.h" 21 | 22 | namespace YAML { 23 | namespace detail { 24 | class node; 25 | } // namespace detail 26 | } // namespace YAML 27 | 28 | namespace YAML { 29 | namespace detail { 30 | class YAML_CPP_API node_data { 31 | public: 32 | node_data(); 33 | node_data(const node_data&) = delete; 34 | node_data& operator=(const node_data&) = delete; 35 | 36 | void mark_defined(); 37 | void set_mark(const Mark& mark); 38 | void set_type(NodeType::value type); 39 | void set_tag(const std::string& tag); 40 | void set_null(); 41 | void set_scalar(const std::string& scalar); 42 | void set_style(EmitterStyle::value style); 43 | 44 | bool is_defined() const { return m_isDefined; } 45 | const Mark& mark() const { return m_mark; } 46 | NodeType::value type() const { 47 | return m_isDefined ? m_type : NodeType::Undefined; 48 | } 49 | const std::string& scalar() const { return m_scalar; } 50 | const std::string& tag() const { return m_tag; } 51 | EmitterStyle::value style() const { return m_style; } 52 | 53 | // size/iterator 54 | std::size_t size() const; 55 | 56 | const_node_iterator begin() const; 57 | node_iterator begin(); 58 | 59 | const_node_iterator end() const; 60 | node_iterator end(); 61 | 62 | // sequence 63 | void push_back(node& node, const shared_memory_holder& pMemory); 64 | void insert(node& key, node& value, const shared_memory_holder& pMemory); 65 | 66 | // indexing 67 | template 68 | node* get(const Key& key, shared_memory_holder pMemory) const; 69 | template 70 | node& get(const Key& key, shared_memory_holder pMemory); 71 | template 72 | bool remove(const Key& key, shared_memory_holder pMemory); 73 | 74 | node* get(node& key, const shared_memory_holder& pMemory) const; 75 | node& get(node& key, const shared_memory_holder& pMemory); 76 | bool remove(node& key, const shared_memory_holder& pMemory); 77 | 78 | // map 79 | template 80 | void force_insert(const Key& key, const Value& value, 81 | shared_memory_holder pMemory); 82 | 83 | public: 84 | static const std::string& empty_scalar(); 85 | 86 | private: 87 | void compute_seq_size() const; 88 | void compute_map_size() const; 89 | 90 | void reset_sequence(); 91 | void reset_map(); 92 | 93 | void insert_map_pair(node& key, node& value); 94 | void convert_to_map(const shared_memory_holder& pMemory); 95 | void convert_sequence_to_map(const shared_memory_holder& pMemory); 96 | 97 | template 98 | static node& convert_to_node(const T& rhs, shared_memory_holder pMemory); 99 | 100 | private: 101 | bool m_isDefined; 102 | Mark m_mark; 103 | NodeType::value m_type; 104 | std::string m_tag; 105 | EmitterStyle::value m_style; 106 | 107 | // scalar 108 | std::string m_scalar; 109 | 110 | // sequence 111 | using node_seq = std::vector; 112 | node_seq m_sequence; 113 | 114 | mutable std::size_t m_seqSize; 115 | 116 | // map 117 | using node_map = std::vector>; 118 | node_map m_map; 119 | 120 | using kv_pair = std::pair; 121 | using kv_pairs = std::list; 122 | mutable kv_pairs m_undefinedPairs; 123 | }; 124 | } 125 | } 126 | 127 | #endif // VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 128 | -------------------------------------------------------------------------------- /src/tcp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RESET="\033[0m" 4 | CYAN="\033[1;36m" 5 | GREEN="\033[1;32m" 6 | RED="\033[1;31m" 7 | BLUE="\033[1;34m" 8 | 9 | function print_info() { echo -e "${BLUE}[INFO]${RESET} $1"; } 10 | function print_success() { echo -e "${GREEN}[SUCCESS]${RESET} $1"; } 11 | function print_error() { echo -e "${RED}[ERROR]${RESET} $1"; } 12 | 13 | function kill_existing_forwarder() { 14 | print_info "Checking for existing TCP forwarder processes..." 15 | existing_pid=$(pgrep -f "tcp_forwarder") 16 | if [ -n "$existing_pid" ]; then 17 | print_info "Killing existing TCP forwarder process (PID: $existing_pid)..." 18 | kill -9 "$existing_pid" 19 | if [ $? -eq 0 ]; then 20 | print_success "Existing TCP forwarder process terminated." 21 | else 22 | print_error "Failed to terminate TCP forwarder process (PID: $existing_pid)." 23 | fi 24 | else 25 | print_info "No existing TCP forwarder process found." 26 | fi 27 | } 28 | 29 | function kill_existing_app() { 30 | print_info "Checking for existing app.py processes..." 31 | existing_app_pid=$(pgrep -f "python app.py") 32 | if [ -n "$existing_app_pid" ]; then 33 | print_info "Killing existing app.py process (PID: $existing_app_pid)..." 34 | kill -9 "$existing_app_pid" 35 | if [ $? -eq 0 ]; then 36 | print_success "Existing app.py process terminated." 37 | else 38 | print_error "Failed to terminate app.py process (PID: $existing_app_pid)." 39 | fi 40 | else 41 | print_info "No existing app.py process found." 42 | fi 43 | } 44 | 45 | function start_tcp_forwarder() { 46 | kill_existing_forwarder 47 | 48 | if [ ! -f "./tcp_forwarder" ]; then 49 | print_error "TCP forwarder binary not found. Please compile it first." 50 | exit 1 51 | fi 52 | 53 | print_info "Starting TCP Forwarder..." 54 | ./tcp_forwarder "$CONFIG_FILE" > tcp_forwarder.log 2>&1 & 55 | FORWARDER_PID=$! 56 | sleep 1 57 | if ps -p $FORWARDER_PID > /dev/null 2>&1; then 58 | print_success "TCP Forwarder started (PID: $FORWARDER_PID). Logs: tcp_forwarder.log" 59 | else 60 | print_error "Failed to start TCP Forwarder. Check tcp_forwarder.log for details." 61 | exit 1 62 | fi 63 | } 64 | 65 | function start_app_py() { 66 | kill_existing_app 67 | 68 | VENV_DIR="./venv" 69 | 70 | if [ ! -d "$VENV_DIR" ]; then 71 | print_error "Virtual environment not found. Please set it up first." 72 | exit 1 73 | fi 74 | 75 | print_info "Activating Python virtual environment..." 76 | source "$VENV_DIR/bin/activate" 77 | if [ $? -ne 0 ]; then 78 | print_error "Failed to activate virtual environment." 79 | exit 1 80 | fi 81 | print_success "Virtual environment activated." 82 | 83 | if [ ! -f "./app.py" ]; then 84 | print_error "app.py not found in the current directory." 85 | deactivate 86 | exit 1 87 | fi 88 | 89 | print_info "Starting app.py..." 90 | python app.py > app.log 2>&1 & 91 | APP_PID=$! 92 | sleep 1 93 | if ps -p $APP_PID > /dev/null 2>&1; then 94 | print_success "app.py started (PID: $APP_PID). Logs: app.log" 95 | else 96 | print_error "Failed to start app.py. Check app.log for details." 97 | deactivate 98 | exit 1 99 | fi 100 | } 101 | 102 | function cleanup() { 103 | print_info "Termination signal received. Shutting down processes..." 104 | kill_existing_forwarder 105 | kill_existing_app 106 | print_success "All processes terminated. Exiting." 107 | exit 0 108 | } 109 | 110 | trap cleanup SIGINT SIGTERM 111 | 112 | if [ "$#" -ne 1 ]; then 113 | print_error "No configuration file provided." 114 | echo -e "\nUsage: ./run_tcp.sh " 115 | exit 1 116 | else 117 | CONFIG_FILE=$1 118 | if [ ! -f "$CONFIG_FILE" ]; then 119 | print_error "Configuration file '$CONFIG_FILE' does not exist." 120 | exit 1 121 | fi 122 | export CONFIG_FILE 123 | fi 124 | 125 | start_tcp_forwarder 126 | start_app_py 127 | 128 | wait 129 | -------------------------------------------------------------------------------- /src/udp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RESET="\033[0m" 4 | CYAN="\033[1;36m" 5 | GREEN="\033[1;32m" 6 | RED="\033[1;31m" 7 | BLUE="\033[1;34m" 8 | 9 | function print_info() { echo -e "${BLUE}[INFO]${RESET} $1"; } 10 | function print_success() { echo -e "${GREEN}[SUCCESS]${RESET} $1"; } 11 | function print_error() { echo -e "${RED}[ERROR]${RESET} $1"; } 12 | 13 | function kill_existing_forwarder() { 14 | print_info "Checking for existing UDP forwarder processes..." 15 | existing_pid=$(pgrep -f "udp_forwarder") 16 | if [ -n "$existing_pid" ]; then 17 | print_info "Killing existing UDP forwarder process (PID: $existing_pid)..." 18 | kill -9 "$existing_pid" 19 | if [ $? -eq 0 ]; then 20 | print_success "Existing UDP forwarder process terminated." 21 | else 22 | print_error "Failed to terminate UDP forwarder process (PID: $existing_pid)." 23 | fi 24 | else 25 | print_info "No existing UDP forwarder process found." 26 | fi 27 | } 28 | 29 | function kill_existing_app() { 30 | print_info "Checking for existing app.py processes..." 31 | existing_app_pid=$(pgrep -f "python app.py") 32 | if [ -n "$existing_app_pid" ]; then 33 | print_info "Killing existing app.py process (PID: $existing_app_pid)..." 34 | kill -9 "$existing_app_pid" 35 | if [ $? -eq 0 ]; then 36 | print_success "Existing app.py process terminated." 37 | else 38 | print_error "Failed to terminate app.py process (PID: $existing_app_pid)." 39 | fi 40 | else 41 | print_info "No existing app.py process found." 42 | fi 43 | } 44 | 45 | function start_udp_forwarder() { 46 | kill_existing_forwarder 47 | 48 | if [ ! -f "./udp_forwarder" ]; then 49 | print_error "UDP forwarder binary not found. Please compile it first." 50 | exit 1 51 | fi 52 | 53 | print_info "Starting UDP Forwarder..." 54 | ./udp_forwarder "$CONFIG_FILE" > udp_forwarder.log 2>&1 & 55 | FORWARDER_PID=$! 56 | sleep 1 57 | if ps -p $FORWARDER_PID > /dev/null 2>&1; then 58 | print_success "UDP Forwarder started (PID: $FORWARDER_PID). Logs: udp_forwarder.log" 59 | else 60 | print_error "Failed to start UDP Forwarder. Check udp_forwarder.log for details." 61 | exit 1 62 | fi 63 | } 64 | 65 | function start_app_py() { 66 | kill_existing_app 67 | 68 | VENV_DIR="./venv" 69 | 70 | if [ ! -d "$VENV_DIR" ]; then 71 | print_error "Virtual environment not found. Please set it up first." 72 | exit 1 73 | fi 74 | 75 | print_info "Activating Python virtual environment..." 76 | source "$VENV_DIR/bin/activate" 77 | if [ $? -ne 0 ]; then 78 | print_error "Failed to activate virtual environment." 79 | exit 1 80 | fi 81 | print_success "Virtual environment activated." 82 | 83 | if [ ! -f "./app.py" ]; then 84 | print_error "app.py not found in the current directory." 85 | deactivate 86 | exit 1 87 | fi 88 | 89 | print_info "Starting app.py..." 90 | python app.py > app.log 2>&1 & 91 | APP_PID=$! 92 | sleep 1 93 | if ps -p $APP_PID > /dev/null 2>&1; then 94 | print_success "app.py started (PID: $APP_PID). Logs: app.log" 95 | else 96 | print_error "Failed to start app.py. Check app.log for details." 97 | deactivate 98 | exit 1 99 | fi 100 | } 101 | 102 | function cleanup() { 103 | print_info "Termination signal received. Shutting down processes..." 104 | kill_existing_forwarder 105 | kill_existing_app 106 | print_success "All processes terminated. Exiting." 107 | exit 0 108 | } 109 | 110 | trap cleanup SIGINT SIGTERM 111 | 112 | if [ "$#" -ne 1 ]; then 113 | print_error "No configuration file provided." 114 | echo -e "\nUsage: ./run_udp.sh " 115 | exit 1 116 | else 117 | CONFIG_FILE=$1 118 | if [ ! -f "$CONFIG_FILE" ]; then 119 | print_error "Configuration file '$CONFIG_FILE' does not exist." 120 | exit 1 121 | fi 122 | export CONFIG_FILE 123 | fi 124 | 125 | start_udp_forwarder 126 | start_app_py 127 | 128 | wait 129 | -------------------------------------------------------------------------------- /src/templates/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Register 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 107 | 108 | 109 | 110 |

111 |

Create an Account

112 |
113 | 114 | 115 | 116 | 117 | 118 |
119 |
120 | Already have an account? Login here. 121 |
122 |
123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/node.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include "yaml-cpp/dll.h" 14 | #include "yaml-cpp/emitterstyle.h" 15 | #include "yaml-cpp/mark.h" 16 | #include "yaml-cpp/node/detail/iterator_fwd.h" 17 | #include "yaml-cpp/node/ptr.h" 18 | #include "yaml-cpp/node/type.h" 19 | 20 | namespace YAML { 21 | namespace detail { 22 | class node; 23 | class node_data; 24 | struct iterator_value; 25 | } // namespace detail 26 | } // namespace YAML 27 | 28 | namespace YAML { 29 | class YAML_CPP_API Node { 30 | public: 31 | friend class NodeBuilder; 32 | friend class NodeEvents; 33 | friend struct detail::iterator_value; 34 | friend class detail::node; 35 | friend class detail::node_data; 36 | template 37 | friend class detail::iterator_base; 38 | template 39 | friend struct as_if; 40 | 41 | using iterator = YAML::iterator; 42 | using const_iterator = YAML::const_iterator; 43 | 44 | Node(); 45 | explicit Node(NodeType::value type); 46 | template 47 | explicit Node(const T& rhs); 48 | explicit Node(const detail::iterator_value& rhs); 49 | Node(const Node& rhs); 50 | ~Node(); 51 | 52 | YAML::Mark Mark() const; 53 | NodeType::value Type() const; 54 | bool IsDefined() const; 55 | bool IsNull() const { return Type() == NodeType::Null; } 56 | bool IsScalar() const { return Type() == NodeType::Scalar; } 57 | bool IsSequence() const { return Type() == NodeType::Sequence; } 58 | bool IsMap() const { return Type() == NodeType::Map; } 59 | 60 | // bool conversions 61 | explicit operator bool() const { return IsDefined(); } 62 | bool operator!() const { return !IsDefined(); } 63 | 64 | // access 65 | template 66 | T as() const; 67 | template 68 | T as(const S& fallback) const; 69 | const std::string& Scalar() const; 70 | 71 | const std::string& Tag() const; 72 | void SetTag(const std::string& tag); 73 | 74 | // style 75 | // WARNING: This API might change in future releases. 76 | EmitterStyle::value Style() const; 77 | void SetStyle(EmitterStyle::value style); 78 | 79 | // assignment 80 | bool is(const Node& rhs) const; 81 | template 82 | Node& operator=(const T& rhs); 83 | Node& operator=(const Node& rhs); 84 | void reset(const Node& rhs = Node()); 85 | 86 | // size/iterator 87 | std::size_t size() const; 88 | 89 | const_iterator begin() const; 90 | iterator begin(); 91 | 92 | const_iterator end() const; 93 | iterator end(); 94 | 95 | // sequence 96 | template 97 | void push_back(const T& rhs); 98 | void push_back(const Node& rhs); 99 | 100 | // indexing 101 | template 102 | const Node operator[](const Key& key) const; 103 | template 104 | Node operator[](const Key& key); 105 | template 106 | bool remove(const Key& key); 107 | 108 | const Node operator[](const Node& key) const; 109 | Node operator[](const Node& key); 110 | bool remove(const Node& key); 111 | 112 | // map 113 | template 114 | void force_insert(const Key& key, const Value& value); 115 | 116 | private: 117 | enum Zombie { ZombieNode }; 118 | explicit Node(Zombie); 119 | explicit Node(Zombie, const std::string&); 120 | explicit Node(detail::node& node, detail::shared_memory_holder pMemory); 121 | 122 | void EnsureNodeExists() const; 123 | 124 | template 125 | void Assign(const T& rhs); 126 | void Assign(const char* rhs); 127 | void Assign(char* rhs); 128 | 129 | void AssignData(const Node& rhs); 130 | void AssignNode(const Node& rhs); 131 | 132 | private: 133 | bool m_isValid; 134 | // String representation of invalid key, if the node is invalid. 135 | std::string m_invalidKey; 136 | mutable detail::shared_memory_holder m_pMemory; 137 | mutable detail::node* m_pNode; 138 | }; 139 | 140 | YAML_CPP_API bool operator==(const Node& lhs, const Node& rhs); 141 | 142 | YAML_CPP_API Node Clone(const Node& node); 143 | 144 | template 145 | struct convert; 146 | } 147 | 148 | #endif // NODE_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 149 | -------------------------------------------------------------------------------- /src/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Login 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 139 | 140 | 141 | 142 |
143 |
144 |

Welcome Back

145 |
146 | 147 | 148 | 149 | 150 | 151 |
152 |
153 | Don't have an account? Register here. 154 |
155 |
156 | 157 |
158 | Login Illustration 159 |
160 |
161 | 162 | 163 | -------------------------------------------------------------------------------- /src/static/js/script.js: -------------------------------------------------------------------------------- 1 | function fetchMetrics() { 2 | fetch('/metrics') 3 | .then(response => response.json()) 4 | .then(data => { 5 | document.getElementById('cpu-usage').innerText = data.cpu_usage; 6 | document.getElementById('ram-usage').innerText = data.ram_usage; 7 | document.getElementById('uptime').innerText = data.uptime; 8 | }) 9 | .catch(error => console.error('error in fetching metrics:', error)); 10 | } 11 | 12 | function fetchNetworkStats() { 13 | fetch('/network-stats') 14 | .then(response => response.json()) 15 | .then(data => { 16 | const portSelector = document.getElementById('port-selector'); 17 | const selectedPort = portSelector.value; 18 | const portData = data[selectedPort]; 19 | 20 | if (portData) { 21 | document.getElementById('bytes-sent').innerText = portData.bytes_sent; 22 | document.getElementById('bytes-received').innerText = portData.bytes_received; 23 | document.getElementById('packets-sent').innerText = portData.packets_sent; 24 | document.getElementById('packets-received').innerText = portData.packets_received; 25 | } 26 | }) 27 | .catch(error => console.error('error in fetching network stats:', error)); 28 | } 29 | 30 | function updateNetworkStats() { 31 | fetchNetworkStats(); 32 | } 33 | 34 | function fetchSystemLogs() { 35 | fetch('/system-logs') 36 | .then(response => response.json()) 37 | .then(data => { 38 | document.getElementById('system-logs').innerText = data.logs; 39 | }) 40 | .catch(error => console.error('error in fetching system logs:', error)); 41 | } 42 | 43 | function fetchTunnelLogs() { 44 | fetch('/api/tunnel-logs') 45 | .then(response => response.json()) 46 | .then(data => { 47 | const logsContainer = document.getElementById('tunnel-logs'); 48 | logsContainer.innerHTML = ''; 49 | 50 | const logLines = data.logs.split('\n'); 51 | logLines.forEach(line => { 52 | const logLineElement = document.createElement('div'); 53 | logLineElement.classList.add('log-line'); 54 | 55 | if (line.includes('[INFO]')) { 56 | logLineElement.classList.add('log-info'); 57 | } else if (line.includes('[WARNING]')) { 58 | logLineElement.classList.add('log-warning'); 59 | } else if (line.includes('[ERROR]')) { 60 | logLineElement.classList.add('log-error'); 61 | } else if (line.includes('[CRITICAL]')) { 62 | logLineElement.classList.add('log-critical'); 63 | } 64 | 65 | logLineElement.textContent = line; 66 | logsContainer.appendChild(logLineElement); 67 | }); 68 | }) 69 | .catch(error => console.error('error in fetching tunnel logs:', error)); 70 | } 71 | 72 | function fetchTunnelStatus() { 73 | fetch('/tunnel-status') 74 | .then(response => response.json()) 75 | .then(data => { 76 | document.getElementById('tunnel-status').innerText = `Tunnel Status: ${data.status}`; 77 | }) 78 | .catch(error => console.error('error in fetching tunnel status:', error)); 79 | } 80 | 81 | function banIp(ip) { 82 | fetch('/ban-ip', { 83 | method: 'POST', 84 | headers: { 85 | 'Content-Type': 'application/json' 86 | }, 87 | body: JSON.stringify({ ip: ip }) 88 | }) 89 | .then(response => response.json()) 90 | .then(data => { 91 | alert(`IP ${data.ip} has been ${data.status}`); 92 | document.getElementById(`status-${ip}`).innerText = data.status; 93 | moveIpToBannedList(ip); 94 | }) 95 | .catch(error => console.error('banning IP error:', error)); 96 | } 97 | 98 | function unbanIp(ip) { 99 | fetch('/unban-ip', { 100 | method: 'POST', 101 | headers: { 102 | 'Content-Type': 'application/json' 103 | }, 104 | body: JSON.stringify({ ip: ip }) 105 | }) 106 | .then(response => response.json()) 107 | .then(data => { 108 | alert(`IP ${data.ip} has been ${data.status}`); 109 | document.getElementById(`status-${ip}`).innerText = data.status; 110 | moveIpToConnectedList(ip); 111 | }) 112 | .catch(error => console.error('unbanning IP error:', error)); 113 | } 114 | 115 | function moveIpToBannedList(ip) { 116 | const ipElement = document.querySelector(`#status-${ip}`).closest('li'); 117 | const bannedList = document.querySelector('.banned-ip-list ul'); 118 | if (ipElement && bannedList) { 119 | bannedList.appendChild(ipElement); 120 | } 121 | } 122 | 123 | function moveIpToConnectedList(ip) { 124 | const ipElement = document.querySelector(`#status-${ip}`).closest('li'); 125 | const connectedList = document.querySelector('.connected-ip-list ul'); 126 | if (ipElement && connectedList) { 127 | connectedList.appendChild(ipElement); 128 | } 129 | } 130 | 131 | setInterval(fetchMetrics, 5000); 132 | setInterval(fetchNetworkStats, 5000); 133 | setInterval(fetchSystemLogs, 10000); 134 | setInterval(fetchTunnelLogs, 10000); 135 | setInterval(fetchTunnelStatus, 5000); 136 | 137 | fetchMetrics(); 138 | fetchNetworkStats(); 139 | fetchSystemLogs(); 140 | fetchTunnelLogs(); 141 | fetchTunnelStatus(); 142 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/node_iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include "yaml-cpp/node/ptr.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace YAML { 20 | namespace detail { 21 | struct iterator_type { 22 | enum value { NoneType, Sequence, Map }; 23 | }; 24 | 25 | template 26 | struct node_iterator_value : public std::pair { 27 | using kv = std::pair; 28 | 29 | node_iterator_value() : kv(), pNode(nullptr) {} 30 | explicit node_iterator_value(V& rhs) : kv(), pNode(&rhs) {} 31 | explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(nullptr) {} 32 | 33 | V& operator*() const { return *pNode; } 34 | V& operator->() const { return *pNode; } 35 | 36 | V* pNode; 37 | }; 38 | 39 | using node_seq = std::vector; 40 | using node_map = std::vector>; 41 | 42 | template 43 | struct node_iterator_type { 44 | using seq = node_seq::iterator; 45 | using map = node_map::iterator; 46 | }; 47 | 48 | template 49 | struct node_iterator_type { 50 | using seq = node_seq::const_iterator; 51 | using map = node_map::const_iterator; 52 | }; 53 | 54 | template 55 | class node_iterator_base { 56 | private: 57 | struct enabler {}; 58 | 59 | struct proxy { 60 | explicit proxy(const node_iterator_value& x) : m_ref(x) {} 61 | node_iterator_value* operator->() { return std::addressof(m_ref); } 62 | operator node_iterator_value*() { return std::addressof(m_ref); } 63 | 64 | node_iterator_value m_ref; 65 | }; 66 | 67 | public: 68 | using iterator_category = std::forward_iterator_tag; 69 | using value_type = node_iterator_value; 70 | using difference_type = std::ptrdiff_t; 71 | using pointer = node_iterator_value*; 72 | using reference = node_iterator_value&; 73 | using SeqIter = typename node_iterator_type::seq; 74 | using MapIter = typename node_iterator_type::map; 75 | 76 | node_iterator_base() 77 | : m_type(iterator_type::NoneType), m_seqIt(), m_mapIt(), m_mapEnd() {} 78 | explicit node_iterator_base(SeqIter seqIt) 79 | : m_type(iterator_type::Sequence), 80 | m_seqIt(seqIt), 81 | m_mapIt(), 82 | m_mapEnd() {} 83 | explicit node_iterator_base(MapIter mapIt, MapIter mapEnd) 84 | : m_type(iterator_type::Map), 85 | m_seqIt(), 86 | m_mapIt(mapIt), 87 | m_mapEnd(mapEnd) { 88 | m_mapIt = increment_until_defined(m_mapIt); 89 | } 90 | 91 | template 92 | node_iterator_base(const node_iterator_base& rhs, 93 | typename std::enable_if::value, 94 | enabler>::type = enabler()) 95 | : m_type(rhs.m_type), 96 | m_seqIt(rhs.m_seqIt), 97 | m_mapIt(rhs.m_mapIt), 98 | m_mapEnd(rhs.m_mapEnd) {} 99 | 100 | template 101 | friend class node_iterator_base; 102 | 103 | template 104 | bool operator==(const node_iterator_base& rhs) const { 105 | if (m_type != rhs.m_type) 106 | return false; 107 | 108 | switch (m_type) { 109 | case iterator_type::NoneType: 110 | return true; 111 | case iterator_type::Sequence: 112 | return m_seqIt == rhs.m_seqIt; 113 | case iterator_type::Map: 114 | return m_mapIt == rhs.m_mapIt; 115 | } 116 | return true; 117 | } 118 | 119 | template 120 | bool operator!=(const node_iterator_base& rhs) const { 121 | return !(*this == rhs); 122 | } 123 | 124 | node_iterator_base& operator++() { 125 | switch (m_type) { 126 | case iterator_type::NoneType: 127 | break; 128 | case iterator_type::Sequence: 129 | ++m_seqIt; 130 | break; 131 | case iterator_type::Map: 132 | ++m_mapIt; 133 | m_mapIt = increment_until_defined(m_mapIt); 134 | break; 135 | } 136 | return *this; 137 | } 138 | 139 | node_iterator_base operator++(int) { 140 | node_iterator_base iterator_pre(*this); 141 | ++(*this); 142 | return iterator_pre; 143 | } 144 | 145 | value_type operator*() const { 146 | switch (m_type) { 147 | case iterator_type::NoneType: 148 | return value_type(); 149 | case iterator_type::Sequence: 150 | return value_type(**m_seqIt); 151 | case iterator_type::Map: 152 | return value_type(*m_mapIt->first, *m_mapIt->second); 153 | } 154 | return value_type(); 155 | } 156 | 157 | proxy operator->() const { return proxy(**this); } 158 | 159 | MapIter increment_until_defined(MapIter it) { 160 | while (it != m_mapEnd && !is_defined(it)) 161 | ++it; 162 | return it; 163 | } 164 | 165 | bool is_defined(MapIter it) const { 166 | return it->first->is_defined() && it->second->is_defined(); 167 | } 168 | 169 | private: 170 | typename iterator_type::value m_type; 171 | 172 | SeqIter m_seqIt; 173 | MapIter m_mapIt, m_mapEnd; 174 | }; 175 | 176 | using node_iterator = node_iterator_base; 177 | using const_node_iterator = node_iterator_base; 178 | } 179 | } 180 | 181 | #endif // VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 182 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/node.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/dll.h" 11 | #include "yaml-cpp/emitterstyle.h" 12 | #include "yaml-cpp/node/detail/node_ref.h" 13 | #include "yaml-cpp/node/ptr.h" 14 | #include "yaml-cpp/node/type.h" 15 | #include 16 | #include 17 | 18 | namespace YAML { 19 | namespace detail { 20 | class node { 21 | private: 22 | struct less { 23 | bool operator ()(const node* l, const node* r) const {return l->m_index < r->m_index;} 24 | }; 25 | 26 | public: 27 | node() : m_pRef(new node_ref), m_dependencies{}, m_index{} {} 28 | node(const node&) = delete; 29 | node& operator=(const node&) = delete; 30 | 31 | bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; } 32 | const node_ref* ref() const { return m_pRef.get(); } 33 | 34 | bool is_defined() const { return m_pRef->is_defined(); } 35 | const Mark& mark() const { return m_pRef->mark(); } 36 | NodeType::value type() const { return m_pRef->type(); } 37 | 38 | const std::string& scalar() const { return m_pRef->scalar(); } 39 | const std::string& tag() const { return m_pRef->tag(); } 40 | EmitterStyle::value style() const { return m_pRef->style(); } 41 | 42 | template 43 | bool equals(const T& rhs, shared_memory_holder pMemory); 44 | bool equals(const char* rhs, shared_memory_holder pMemory); 45 | 46 | void mark_defined() { 47 | if (is_defined()) 48 | return; 49 | 50 | m_pRef->mark_defined(); 51 | for (node* dependency : m_dependencies) 52 | dependency->mark_defined(); 53 | m_dependencies.clear(); 54 | } 55 | 56 | void add_dependency(node& rhs) { 57 | if (is_defined()) 58 | rhs.mark_defined(); 59 | else 60 | m_dependencies.insert(&rhs); 61 | } 62 | 63 | void set_ref(const node& rhs) { 64 | if (rhs.is_defined()) 65 | mark_defined(); 66 | m_pRef = rhs.m_pRef; 67 | } 68 | void set_data(const node& rhs) { 69 | if (rhs.is_defined()) 70 | mark_defined(); 71 | m_pRef->set_data(*rhs.m_pRef); 72 | } 73 | 74 | void set_mark(const Mark& mark) { m_pRef->set_mark(mark); } 75 | 76 | void set_type(NodeType::value type) { 77 | if (type != NodeType::Undefined) 78 | mark_defined(); 79 | m_pRef->set_type(type); 80 | } 81 | void set_null() { 82 | mark_defined(); 83 | m_pRef->set_null(); 84 | } 85 | void set_scalar(const std::string& scalar) { 86 | mark_defined(); 87 | m_pRef->set_scalar(scalar); 88 | } 89 | void set_tag(const std::string& tag) { 90 | mark_defined(); 91 | m_pRef->set_tag(tag); 92 | } 93 | 94 | // style 95 | void set_style(EmitterStyle::value style) { 96 | mark_defined(); 97 | m_pRef->set_style(style); 98 | } 99 | 100 | // size/iterator 101 | std::size_t size() const { return m_pRef->size(); } 102 | 103 | const_node_iterator begin() const { 104 | return static_cast(*m_pRef).begin(); 105 | } 106 | node_iterator begin() { return m_pRef->begin(); } 107 | 108 | const_node_iterator end() const { 109 | return static_cast(*m_pRef).end(); 110 | } 111 | node_iterator end() { return m_pRef->end(); } 112 | 113 | // sequence 114 | void push_back(node& input, shared_memory_holder pMemory) { 115 | m_pRef->push_back(input, pMemory); 116 | input.add_dependency(*this); 117 | m_index = m_amount.fetch_add(1); 118 | } 119 | void insert(node& key, node& value, shared_memory_holder pMemory) { 120 | m_pRef->insert(key, value, pMemory); 121 | key.add_dependency(*this); 122 | value.add_dependency(*this); 123 | } 124 | 125 | // indexing 126 | template 127 | node* get(const Key& key, shared_memory_holder pMemory) const { 128 | // NOTE: this returns a non-const node so that the top-level Node can wrap 129 | // it, and returns a pointer so that it can be nullptr (if there is no such 130 | // key). 131 | return static_cast(*m_pRef).get(key, pMemory); 132 | } 133 | template 134 | node& get(const Key& key, shared_memory_holder pMemory) { 135 | node& value = m_pRef->get(key, pMemory); 136 | value.add_dependency(*this); 137 | return value; 138 | } 139 | template 140 | bool remove(const Key& key, shared_memory_holder pMemory) { 141 | return m_pRef->remove(key, pMemory); 142 | } 143 | 144 | node* get(node& key, shared_memory_holder pMemory) const { 145 | // NOTE: this returns a non-const node so that the top-level Node can wrap 146 | // it, and returns a pointer so that it can be nullptr (if there is no such 147 | // key). 148 | return static_cast(*m_pRef).get(key, pMemory); 149 | } 150 | node& get(node& key, shared_memory_holder pMemory) { 151 | node& value = m_pRef->get(key, pMemory); 152 | key.add_dependency(*this); 153 | value.add_dependency(*this); 154 | return value; 155 | } 156 | bool remove(node& key, shared_memory_holder pMemory) { 157 | return m_pRef->remove(key, pMemory); 158 | } 159 | 160 | // map 161 | template 162 | void force_insert(const Key& key, const Value& value, 163 | shared_memory_holder pMemory) { 164 | m_pRef->force_insert(key, value, pMemory); 165 | } 166 | 167 | private: 168 | shared_node_ref m_pRef; 169 | using nodes = std::set; 170 | nodes m_dependencies; 171 | size_t m_index; 172 | static YAML_CPP_API std::atomic m_amount; 173 | }; 174 | } // namespace detail 175 | } // namespace YAML 176 | 177 | #endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 178 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/contrib/graphbuilder.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/mark.h" 11 | #include 12 | 13 | namespace YAML { 14 | class Parser; 15 | 16 | // GraphBuilderInterface 17 | // . Abstraction of node creation 18 | // . pParentNode is always nullptr or the return value of one of the NewXXX() 19 | // functions. 20 | class GraphBuilderInterface { 21 | public: 22 | virtual ~GraphBuilderInterface() = 0; 23 | 24 | // Create and return a new node with a null value. 25 | virtual void *NewNull(const Mark &mark, void *pParentNode) = 0; 26 | 27 | // Create and return a new node with the given tag and value. 28 | virtual void *NewScalar(const Mark &mark, const std::string &tag, 29 | void *pParentNode, const std::string &value) = 0; 30 | 31 | // Create and return a new sequence node 32 | virtual void *NewSequence(const Mark &mark, const std::string &tag, 33 | void *pParentNode) = 0; 34 | 35 | // Add pNode to pSequence. pNode was created with one of the NewXxx() 36 | // functions and pSequence with NewSequence(). 37 | virtual void AppendToSequence(void *pSequence, void *pNode) = 0; 38 | 39 | // Note that no moew entries will be added to pSequence 40 | virtual void SequenceComplete(void *pSequence) { (void)pSequence; } 41 | 42 | // Create and return a new map node 43 | virtual void *NewMap(const Mark &mark, const std::string &tag, 44 | void *pParentNode) = 0; 45 | 46 | // Add the pKeyNode => pValueNode mapping to pMap. pKeyNode and pValueNode 47 | // were created with one of the NewXxx() methods and pMap with NewMap(). 48 | virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) = 0; 49 | 50 | // Note that no more assignments will be made in pMap 51 | virtual void MapComplete(void *pMap) { (void)pMap; } 52 | 53 | // Return the node that should be used in place of an alias referencing 54 | // pNode (pNode by default) 55 | virtual void *AnchorReference(const Mark &mark, void *pNode) { 56 | (void)mark; 57 | return pNode; 58 | } 59 | }; 60 | 61 | // Typesafe wrapper for GraphBuilderInterface. Assumes that Impl defines 62 | // Node, Sequence, and Map types. Sequence and Map must derive from Node 63 | // (unless Node is defined as void). Impl must also implement function with 64 | // all of the same names as the virtual functions in GraphBuilderInterface 65 | // -- including the ones with default implementations -- but with the 66 | // prototypes changed to accept an explicit Node*, Sequence*, or Map* where 67 | // appropriate. 68 | template 69 | class GraphBuilder : public GraphBuilderInterface { 70 | public: 71 | typedef typename Impl::Node Node; 72 | typedef typename Impl::Sequence Sequence; 73 | typedef typename Impl::Map Map; 74 | 75 | GraphBuilder(Impl &impl) : m_impl(impl) { 76 | Map *pMap = nullptr; 77 | Sequence *pSeq = nullptr; 78 | Node *pNode = nullptr; 79 | 80 | // Type consistency checks 81 | pNode = pMap; 82 | pNode = pSeq; 83 | } 84 | 85 | GraphBuilderInterface &AsBuilderInterface() { return *this; } 86 | 87 | virtual void *NewNull(const Mark &mark, void *pParentNode) { 88 | return CheckType(m_impl.NewNull(mark, AsNode(pParentNode))); 89 | } 90 | 91 | virtual void *NewScalar(const Mark &mark, const std::string &tag, 92 | void *pParentNode, const std::string &value) { 93 | return CheckType( 94 | m_impl.NewScalar(mark, tag, AsNode(pParentNode), value)); 95 | } 96 | 97 | virtual void *NewSequence(const Mark &mark, const std::string &tag, 98 | void *pParentNode) { 99 | return CheckType( 100 | m_impl.NewSequence(mark, tag, AsNode(pParentNode))); 101 | } 102 | virtual void AppendToSequence(void *pSequence, void *pNode) { 103 | m_impl.AppendToSequence(AsSequence(pSequence), AsNode(pNode)); 104 | } 105 | virtual void SequenceComplete(void *pSequence) { 106 | m_impl.SequenceComplete(AsSequence(pSequence)); 107 | } 108 | 109 | virtual void *NewMap(const Mark &mark, const std::string &tag, 110 | void *pParentNode) { 111 | return CheckType(m_impl.NewMap(mark, tag, AsNode(pParentNode))); 112 | } 113 | virtual void AssignInMap(void *pMap, void *pKeyNode, void *pValueNode) { 114 | m_impl.AssignInMap(AsMap(pMap), AsNode(pKeyNode), AsNode(pValueNode)); 115 | } 116 | virtual void MapComplete(void *pMap) { m_impl.MapComplete(AsMap(pMap)); } 117 | 118 | virtual void *AnchorReference(const Mark &mark, void *pNode) { 119 | return CheckType(m_impl.AnchorReference(mark, AsNode(pNode))); 120 | } 121 | 122 | private: 123 | Impl &m_impl; 124 | 125 | // Static check for pointer to T 126 | template 127 | static T *CheckType(U *p) { 128 | return p; 129 | } 130 | 131 | static Node *AsNode(void *pNode) { return static_cast(pNode); } 132 | static Sequence *AsSequence(void *pSeq) { 133 | return static_cast(pSeq); 134 | } 135 | static Map *AsMap(void *pMap) { return static_cast(pMap); } 136 | }; 137 | 138 | void *BuildGraphOfNextDocument(Parser &parser, 139 | GraphBuilderInterface &graphBuilder); 140 | 141 | template 142 | typename Impl::Node *BuildGraphOfNextDocument(Parser &parser, Impl &impl) { 143 | GraphBuilder graphBuilder(impl); 144 | return static_cast( 145 | BuildGraphOfNextDocument(parser, graphBuilder)); 146 | } 147 | } 148 | 149 | #endif // GRAPHBUILDER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 150 | -------------------------------------------------------------------------------- /src/templates/api.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | API Key Management 6 | 7 | 144 | 145 | 146 | 147 |
148 | 162 | 163 |
164 |

API Key Management

165 | 166 |
167 |
    Loading keys...
168 |
169 |
170 |
171 | 172 | 200 | 201 | 202 | -------------------------------------------------------------------------------- /src/templates/tunnel_logs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Tunnel Logs 6 | 7 | 143 | 144 | 145 | 146 |
147 | 161 | 162 |
163 |

Tunnel Logs

164 | 165 |
166 |
    Loading logs...
167 |
168 |
169 |
170 | 171 | 207 | 208 | 209 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/detail/impl.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/node/detail/node.h" 11 | #include "yaml-cpp/node/detail/node_data.h" 12 | 13 | #include 14 | #include 15 | 16 | namespace YAML { 17 | namespace detail { 18 | template 19 | struct get_idx { 20 | static node* get(const std::vector& /* sequence */, 21 | const Key& /* key */, shared_memory_holder /* pMemory */) { 22 | return nullptr; 23 | } 24 | }; 25 | 26 | template 27 | struct get_idx::value && 29 | !std::is_same::value>::type> { 30 | static node* get(const std::vector& sequence, const Key& key, 31 | shared_memory_holder /* pMemory */) { 32 | return key < sequence.size() ? sequence[key] : nullptr; 33 | } 34 | 35 | static node* get(std::vector& sequence, const Key& key, 36 | shared_memory_holder pMemory) { 37 | if (key > sequence.size() || (key > 0 && !sequence[key - 1]->is_defined())) 38 | return nullptr; 39 | if (key == sequence.size()) 40 | sequence.push_back(&pMemory->create_node()); 41 | return sequence[key]; 42 | } 43 | }; 44 | 45 | template 46 | struct get_idx::value>::type> { 47 | static node* get(const std::vector& sequence, const Key& key, 48 | shared_memory_holder pMemory) { 49 | return key >= 0 ? get_idx::get( 50 | sequence, static_cast(key), pMemory) 51 | : nullptr; 52 | } 53 | static node* get(std::vector& sequence, const Key& key, 54 | shared_memory_holder pMemory) { 55 | return key >= 0 ? get_idx::get( 56 | sequence, static_cast(key), pMemory) 57 | : nullptr; 58 | } 59 | }; 60 | 61 | template 62 | struct remove_idx { 63 | static bool remove(std::vector&, const Key&, std::size_t&) { 64 | return false; 65 | } 66 | }; 67 | 68 | template 69 | struct remove_idx< 70 | Key, typename std::enable_if::value && 71 | !std::is_same::value>::type> { 72 | 73 | static bool remove(std::vector& sequence, const Key& key, 74 | std::size_t& seqSize) { 75 | if (key >= sequence.size()) { 76 | return false; 77 | } else { 78 | sequence.erase(sequence.begin() + key); 79 | if (seqSize > key) { 80 | --seqSize; 81 | } 82 | return true; 83 | } 84 | } 85 | }; 86 | 87 | template 88 | struct remove_idx::value>::type> { 90 | 91 | static bool remove(std::vector& sequence, const Key& key, 92 | std::size_t& seqSize) { 93 | return key >= 0 ? remove_idx::remove( 94 | sequence, static_cast(key), seqSize) 95 | : false; 96 | } 97 | }; 98 | 99 | template 100 | inline bool node::equals(const T& rhs, shared_memory_holder pMemory) { 101 | T lhs; 102 | if (convert::decode(Node(*this, pMemory), lhs)) { 103 | return lhs == rhs; 104 | } 105 | return false; 106 | } 107 | 108 | inline bool node::equals(const char* rhs, shared_memory_holder pMemory) { 109 | std::string lhs; 110 | if (convert::decode(Node(*this, std::move(pMemory)), lhs)) { 111 | return lhs == rhs; 112 | } 113 | return false; 114 | } 115 | 116 | // indexing 117 | template 118 | inline node* node_data::get(const Key& key, 119 | shared_memory_holder pMemory) const { 120 | switch (m_type) { 121 | case NodeType::Map: 122 | break; 123 | case NodeType::Undefined: 124 | case NodeType::Null: 125 | return nullptr; 126 | case NodeType::Sequence: 127 | if (node* pNode = get_idx::get(m_sequence, key, pMemory)) 128 | return pNode; 129 | return nullptr; 130 | case NodeType::Scalar: 131 | throw BadSubscript(m_mark, key); 132 | } 133 | 134 | auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { 135 | return m.first->equals(key, pMemory); 136 | }); 137 | 138 | return it != m_map.end() ? it->second : nullptr; 139 | } 140 | 141 | template 142 | inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { 143 | switch (m_type) { 144 | case NodeType::Map: 145 | break; 146 | case NodeType::Undefined: 147 | case NodeType::Null: 148 | case NodeType::Sequence: 149 | if (node* pNode = get_idx::get(m_sequence, key, pMemory)) { 150 | m_type = NodeType::Sequence; 151 | return *pNode; 152 | } 153 | 154 | convert_to_map(pMemory); 155 | break; 156 | case NodeType::Scalar: 157 | throw BadSubscript(m_mark, key); 158 | } 159 | 160 | auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { 161 | return m.first->equals(key, pMemory); 162 | }); 163 | 164 | if (it != m_map.end()) { 165 | return *it->second; 166 | } 167 | 168 | node& k = convert_to_node(key, pMemory); 169 | node& v = pMemory->create_node(); 170 | insert_map_pair(k, v); 171 | return v; 172 | } 173 | 174 | template 175 | inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { 176 | if (m_type == NodeType::Sequence) { 177 | return remove_idx::remove(m_sequence, key, m_seqSize); 178 | } 179 | 180 | if (m_type == NodeType::Map) { 181 | kv_pairs::iterator it = m_undefinedPairs.begin(); 182 | while (it != m_undefinedPairs.end()) { 183 | kv_pairs::iterator jt = std::next(it); 184 | if (it->first->equals(key, pMemory)) { 185 | m_undefinedPairs.erase(it); 186 | } 187 | it = jt; 188 | } 189 | 190 | auto iter = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { 191 | return m.first->equals(key, pMemory); 192 | }); 193 | 194 | if (iter != m_map.end()) { 195 | m_map.erase(iter); 196 | return true; 197 | } 198 | } 199 | 200 | return false; 201 | } 202 | 203 | // map 204 | template 205 | inline void node_data::force_insert(const Key& key, const Value& value, 206 | shared_memory_holder pMemory) { 207 | switch (m_type) { 208 | case NodeType::Map: 209 | break; 210 | case NodeType::Undefined: 211 | case NodeType::Null: 212 | case NodeType::Sequence: 213 | convert_to_map(pMemory); 214 | break; 215 | case NodeType::Scalar: 216 | throw BadInsert(); 217 | } 218 | 219 | node& k = convert_to_node(key, pMemory); 220 | node& v = convert_to_node(value, pMemory); 221 | insert_map_pair(k, v); 222 | } 223 | 224 | template 225 | inline node& node_data::convert_to_node(const T& rhs, 226 | shared_memory_holder pMemory) { 227 | Node value = convert::encode(rhs); 228 | value.EnsureNodeExists(); 229 | pMemory->merge(*value.m_pMemory); 230 | return *value.m_pNode; 231 | } 232 | } 233 | } 234 | 235 | #endif // NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 236 | -------------------------------------------------------------------------------- /src/templates/public_ip_settings.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Public IP Settings 6 | 7 | 152 | 153 | 154 | 155 |
156 | 176 | 177 | 178 |
179 |

Public IP Settings

180 | 181 |
182 |

Connected Public IPs

183 |
    184 | {% for ip, status in ip_status.items() %} 185 |
  • 186 | IP: {{ ip }} - Status: {{ status }} 187 | {% if status == "banned" %} 188 | 189 | {% else %} 190 | 191 | {% endif %} 192 |
  • 193 | {% endfor %} 194 |
195 |
196 | 197 |
198 |

Banned IPs

199 |
    200 | {% for ip in banned_ips %} 201 |
  • 202 | IP: {{ ip }} 203 | 204 |
  • 205 | {% endfor %} 206 |
207 |
208 |
209 |
210 | 211 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/emitter.h: -------------------------------------------------------------------------------- 1 | #ifndef EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "yaml-cpp/binary.h" 19 | #include "yaml-cpp/dll.h" 20 | #include "yaml-cpp/emitterdef.h" 21 | #include "yaml-cpp/emittermanip.h" 22 | #include "yaml-cpp/null.h" 23 | #include "yaml-cpp/ostream_wrapper.h" 24 | 25 | namespace YAML { 26 | class Binary; 27 | struct _Null; 28 | } // namespace YAML 29 | 30 | namespace YAML { 31 | class EmitterState; 32 | 33 | class YAML_CPP_API Emitter { 34 | public: 35 | Emitter(); 36 | explicit Emitter(std::ostream& stream); 37 | Emitter(const Emitter&) = delete; 38 | Emitter& operator=(const Emitter&) = delete; 39 | ~Emitter(); 40 | 41 | // output 42 | const char* c_str() const; 43 | std::size_t size() const; 44 | 45 | // state checking 46 | bool good() const; 47 | const std::string GetLastError() const; 48 | 49 | // global setters 50 | bool SetOutputCharset(EMITTER_MANIP value); 51 | bool SetStringFormat(EMITTER_MANIP value); 52 | bool SetBoolFormat(EMITTER_MANIP value); 53 | bool SetNullFormat(EMITTER_MANIP value); 54 | bool SetIntBase(EMITTER_MANIP value); 55 | bool SetSeqFormat(EMITTER_MANIP value); 56 | bool SetMapFormat(EMITTER_MANIP value); 57 | bool SetIndent(std::size_t n); 58 | bool SetPreCommentIndent(std::size_t n); 59 | bool SetPostCommentIndent(std::size_t n); 60 | bool SetFloatPrecision(std::size_t n); 61 | bool SetDoublePrecision(std::size_t n); 62 | void RestoreGlobalModifiedSettings(); 63 | 64 | // local setters 65 | Emitter& SetLocalValue(EMITTER_MANIP value); 66 | Emitter& SetLocalIndent(const _Indent& indent); 67 | Emitter& SetLocalPrecision(const _Precision& precision); 68 | 69 | // overloads of write 70 | Emitter& Write(const std::string& str); 71 | Emitter& Write(bool b); 72 | Emitter& Write(char ch); 73 | Emitter& Write(const _Alias& alias); 74 | Emitter& Write(const _Anchor& anchor); 75 | Emitter& Write(const _Tag& tag); 76 | Emitter& Write(const _Comment& comment); 77 | Emitter& Write(const _Null& n); 78 | Emitter& Write(const Binary& binary); 79 | 80 | template 81 | Emitter& WriteIntegralType(T value); 82 | 83 | template 84 | Emitter& WriteStreamable(T value); 85 | 86 | private: 87 | template 88 | void SetStreamablePrecision(std::stringstream&) {} 89 | std::size_t GetFloatPrecision() const; 90 | std::size_t GetDoublePrecision() const; 91 | 92 | void PrepareIntegralStream(std::stringstream& stream) const; 93 | void StartedScalar(); 94 | 95 | private: 96 | void EmitBeginDoc(); 97 | void EmitEndDoc(); 98 | void EmitBeginSeq(); 99 | void EmitEndSeq(); 100 | void EmitBeginMap(); 101 | void EmitEndMap(); 102 | void EmitNewline(); 103 | void EmitKindTag(); 104 | void EmitTag(bool verbatim, const _Tag& tag); 105 | 106 | void PrepareNode(EmitterNodeType::value child); 107 | void PrepareTopNode(EmitterNodeType::value child); 108 | void FlowSeqPrepareNode(EmitterNodeType::value child); 109 | void BlockSeqPrepareNode(EmitterNodeType::value child); 110 | 111 | void FlowMapPrepareNode(EmitterNodeType::value child); 112 | 113 | void FlowMapPrepareLongKey(EmitterNodeType::value child); 114 | void FlowMapPrepareLongKeyValue(EmitterNodeType::value child); 115 | void FlowMapPrepareSimpleKey(EmitterNodeType::value child); 116 | void FlowMapPrepareSimpleKeyValue(EmitterNodeType::value child); 117 | 118 | void BlockMapPrepareNode(EmitterNodeType::value child); 119 | 120 | void BlockMapPrepareLongKey(EmitterNodeType::value child); 121 | void BlockMapPrepareLongKeyValue(EmitterNodeType::value child); 122 | void BlockMapPrepareSimpleKey(EmitterNodeType::value child); 123 | void BlockMapPrepareSimpleKeyValue(EmitterNodeType::value child); 124 | 125 | void SpaceOrIndentTo(bool requireSpace, std::size_t indent); 126 | 127 | const char* ComputeFullBoolName(bool b) const; 128 | const char* ComputeNullName() const; 129 | bool CanEmitNewline() const; 130 | 131 | private: 132 | std::unique_ptr m_pState; 133 | ostream_wrapper m_stream; 134 | }; 135 | 136 | template 137 | inline Emitter& Emitter::WriteIntegralType(T value) { 138 | if (!good()) 139 | return *this; 140 | 141 | PrepareNode(EmitterNodeType::Scalar); 142 | 143 | std::stringstream stream; 144 | stream.imbue(std::locale("C")); 145 | PrepareIntegralStream(stream); 146 | stream << value; 147 | m_stream << stream.str(); 148 | 149 | StartedScalar(); 150 | 151 | return *this; 152 | } 153 | 154 | template 155 | inline Emitter& Emitter::WriteStreamable(T value) { 156 | if (!good()) 157 | return *this; 158 | 159 | PrepareNode(EmitterNodeType::Scalar); 160 | 161 | std::stringstream stream; 162 | stream.imbue(std::locale("C")); 163 | SetStreamablePrecision(stream); 164 | 165 | bool special = false; 166 | if (std::is_floating_point::value) { 167 | if ((std::numeric_limits::has_quiet_NaN || 168 | std::numeric_limits::has_signaling_NaN) && 169 | std::isnan(value)) { 170 | special = true; 171 | stream << ".nan"; 172 | } else if (std::numeric_limits::has_infinity && std::isinf(value)) { 173 | special = true; 174 | if (std::signbit(value)) { 175 | stream << "-.inf"; 176 | } else { 177 | stream << ".inf"; 178 | } 179 | } 180 | } 181 | 182 | if (!special) { 183 | stream << value; 184 | } 185 | m_stream << stream.str(); 186 | 187 | StartedScalar(); 188 | 189 | return *this; 190 | } 191 | 192 | template <> 193 | inline void Emitter::SetStreamablePrecision(std::stringstream& stream) { 194 | stream.precision(static_cast(GetFloatPrecision())); 195 | } 196 | 197 | template <> 198 | inline void Emitter::SetStreamablePrecision(std::stringstream& stream) { 199 | stream.precision(static_cast(GetDoublePrecision())); 200 | } 201 | 202 | // overloads of insertion 203 | inline Emitter& operator<<(Emitter& emitter, const std::string& v) { 204 | return emitter.Write(v); 205 | } 206 | inline Emitter& operator<<(Emitter& emitter, bool v) { 207 | return emitter.Write(v); 208 | } 209 | inline Emitter& operator<<(Emitter& emitter, char v) { 210 | return emitter.Write(v); 211 | } 212 | inline Emitter& operator<<(Emitter& emitter, unsigned char v) { 213 | return emitter.Write(static_cast(v)); 214 | } 215 | inline Emitter& operator<<(Emitter& emitter, const _Alias& v) { 216 | return emitter.Write(v); 217 | } 218 | inline Emitter& operator<<(Emitter& emitter, const _Anchor& v) { 219 | return emitter.Write(v); 220 | } 221 | inline Emitter& operator<<(Emitter& emitter, const _Tag& v) { 222 | return emitter.Write(v); 223 | } 224 | inline Emitter& operator<<(Emitter& emitter, const _Comment& v) { 225 | return emitter.Write(v); 226 | } 227 | inline Emitter& operator<<(Emitter& emitter, const _Null& v) { 228 | return emitter.Write(v); 229 | } 230 | inline Emitter& operator<<(Emitter& emitter, const Binary& b) { 231 | return emitter.Write(b); 232 | } 233 | 234 | inline Emitter& operator<<(Emitter& emitter, const char* v) { 235 | return emitter.Write(std::string(v)); 236 | } 237 | 238 | inline Emitter& operator<<(Emitter& emitter, int v) { 239 | return emitter.WriteIntegralType(v); 240 | } 241 | inline Emitter& operator<<(Emitter& emitter, unsigned int v) { 242 | return emitter.WriteIntegralType(v); 243 | } 244 | inline Emitter& operator<<(Emitter& emitter, short v) { 245 | return emitter.WriteIntegralType(v); 246 | } 247 | inline Emitter& operator<<(Emitter& emitter, unsigned short v) { 248 | return emitter.WriteIntegralType(v); 249 | } 250 | inline Emitter& operator<<(Emitter& emitter, long v) { 251 | return emitter.WriteIntegralType(v); 252 | } 253 | inline Emitter& operator<<(Emitter& emitter, unsigned long v) { 254 | return emitter.WriteIntegralType(v); 255 | } 256 | inline Emitter& operator<<(Emitter& emitter, long long v) { 257 | return emitter.WriteIntegralType(v); 258 | } 259 | inline Emitter& operator<<(Emitter& emitter, unsigned long long v) { 260 | return emitter.WriteIntegralType(v); 261 | } 262 | 263 | inline Emitter& operator<<(Emitter& emitter, float v) { 264 | return emitter.WriteStreamable(v); 265 | } 266 | inline Emitter& operator<<(Emitter& emitter, double v) { 267 | return emitter.WriteStreamable(v); 268 | } 269 | 270 | inline Emitter& operator<<(Emitter& emitter, EMITTER_MANIP value) { 271 | return emitter.SetLocalValue(value); 272 | } 273 | 274 | inline Emitter& operator<<(Emitter& emitter, _Indent indent) { 275 | return emitter.SetLocalIndent(indent); 276 | } 277 | 278 | inline Emitter& operator<<(Emitter& emitter, _Precision precision) { 279 | return emitter.SetLocalPrecision(precision); 280 | } 281 | } // namespace YAML 282 | 283 | #endif // EMITTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66 284 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/impl.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/exceptions.h" 11 | #include "yaml-cpp/node/detail/memory.h" 12 | #include "yaml-cpp/node/detail/node.h" 13 | #include "yaml-cpp/node/iterator.h" 14 | #include "yaml-cpp/node/node.h" 15 | #include 16 | #include 17 | 18 | namespace YAML { 19 | inline Node::Node() 20 | : m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {} 21 | 22 | inline Node::Node(NodeType::value type) 23 | : m_isValid(true), 24 | m_invalidKey{}, 25 | m_pMemory(new detail::memory_holder), 26 | m_pNode(&m_pMemory->create_node()) { 27 | m_pNode->set_type(type); 28 | } 29 | 30 | template 31 | inline Node::Node(const T& rhs) 32 | : m_isValid(true), 33 | m_invalidKey{}, 34 | m_pMemory(new detail::memory_holder), 35 | m_pNode(&m_pMemory->create_node()) { 36 | Assign(rhs); 37 | } 38 | 39 | inline Node::Node(const detail::iterator_value& rhs) 40 | : m_isValid(rhs.m_isValid), 41 | m_invalidKey(rhs.m_invalidKey), 42 | m_pMemory(rhs.m_pMemory), 43 | m_pNode(rhs.m_pNode) {} 44 | 45 | inline Node::Node(const Node&) = default; 46 | 47 | inline Node::Node(Zombie) 48 | : m_isValid(false), m_invalidKey{}, m_pMemory{}, m_pNode(nullptr) {} 49 | 50 | inline Node::Node(Zombie, const std::string& key) 51 | : m_isValid(false), m_invalidKey(key), m_pMemory{}, m_pNode(nullptr) {} 52 | 53 | inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory) 54 | : m_isValid(true), m_invalidKey{}, m_pMemory(pMemory), m_pNode(&node) {} 55 | 56 | inline Node::~Node() = default; 57 | 58 | inline void Node::EnsureNodeExists() const { 59 | if (!m_isValid) 60 | throw InvalidNode(m_invalidKey); 61 | if (!m_pNode) { 62 | m_pMemory.reset(new detail::memory_holder); 63 | m_pNode = &m_pMemory->create_node(); 64 | m_pNode->set_null(); 65 | } 66 | } 67 | 68 | inline bool Node::IsDefined() const { 69 | if (!m_isValid) { 70 | return false; 71 | } 72 | return m_pNode ? m_pNode->is_defined() : true; 73 | } 74 | 75 | inline Mark Node::Mark() const { 76 | if (!m_isValid) { 77 | throw InvalidNode(m_invalidKey); 78 | } 79 | return m_pNode ? m_pNode->mark() : Mark::null_mark(); 80 | } 81 | 82 | inline NodeType::value Node::Type() const { 83 | if (!m_isValid) 84 | throw InvalidNode(m_invalidKey); 85 | return m_pNode ? m_pNode->type() : NodeType::Null; 86 | } 87 | 88 | // access 89 | 90 | // template helpers 91 | template 92 | struct as_if { 93 | explicit as_if(const Node& node_) : node(node_) {} 94 | const Node& node; 95 | 96 | T operator()(const S& fallback) const { 97 | if (!node.m_pNode) 98 | return fallback; 99 | 100 | T t = fallback; 101 | if (convert::decode(node, t)) 102 | return t; 103 | return fallback; 104 | } 105 | }; 106 | 107 | template 108 | struct as_if { 109 | explicit as_if(const Node& node_) : node(node_) {} 110 | const Node& node; 111 | 112 | std::string operator()(const S& fallback) const { 113 | if (node.Type() == NodeType::Null) 114 | return "null"; 115 | if (node.Type() != NodeType::Scalar) 116 | return fallback; 117 | return node.Scalar(); 118 | } 119 | }; 120 | 121 | template 122 | struct as_if { 123 | explicit as_if(const Node& node_) : node(node_) {} 124 | const Node& node; 125 | 126 | T operator()() const { 127 | if (!node.m_pNode) 128 | throw TypedBadConversion(node.Mark()); 129 | 130 | T t; 131 | if (convert::decode(node, t)) 132 | return t; 133 | throw TypedBadConversion(node.Mark()); 134 | } 135 | }; 136 | 137 | template <> 138 | struct as_if { 139 | explicit as_if(const Node& node_) : node(node_) {} 140 | const Node& node; 141 | 142 | std::string operator()() const { 143 | if (node.Type() == NodeType::Null) 144 | return "null"; 145 | if (node.Type() != NodeType::Scalar) 146 | throw TypedBadConversion(node.Mark()); 147 | return node.Scalar(); 148 | } 149 | }; 150 | 151 | // access functions 152 | template 153 | inline T Node::as() const { 154 | if (!m_isValid) 155 | throw InvalidNode(m_invalidKey); 156 | return as_if(*this)(); 157 | } 158 | 159 | template 160 | inline T Node::as(const S& fallback) const { 161 | if (!m_isValid) 162 | return fallback; 163 | return as_if(*this)(fallback); 164 | } 165 | 166 | inline const std::string& Node::Scalar() const { 167 | if (!m_isValid) 168 | throw InvalidNode(m_invalidKey); 169 | return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar(); 170 | } 171 | 172 | inline const std::string& Node::Tag() const { 173 | if (!m_isValid) 174 | throw InvalidNode(m_invalidKey); 175 | return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar(); 176 | } 177 | 178 | inline void Node::SetTag(const std::string& tag) { 179 | EnsureNodeExists(); 180 | m_pNode->set_tag(tag); 181 | } 182 | 183 | inline EmitterStyle::value Node::Style() const { 184 | if (!m_isValid) 185 | throw InvalidNode(m_invalidKey); 186 | return m_pNode ? m_pNode->style() : EmitterStyle::Default; 187 | } 188 | 189 | inline void Node::SetStyle(EmitterStyle::value style) { 190 | EnsureNodeExists(); 191 | m_pNode->set_style(style); 192 | } 193 | 194 | // assignment 195 | inline bool Node::is(const Node& rhs) const { 196 | if (!m_isValid || !rhs.m_isValid) 197 | throw InvalidNode(m_invalidKey); 198 | if (!m_pNode || !rhs.m_pNode) 199 | return false; 200 | return m_pNode->is(*rhs.m_pNode); 201 | } 202 | 203 | template 204 | inline Node& Node::operator=(const T& rhs) { 205 | Assign(rhs); 206 | return *this; 207 | } 208 | 209 | inline Node& Node::operator=(const Node& rhs) { 210 | if (is(rhs)) 211 | return *this; 212 | AssignNode(rhs); 213 | return *this; 214 | } 215 | 216 | inline void Node::reset(const YAML::Node& rhs) { 217 | if (!m_isValid || !rhs.m_isValid) 218 | throw InvalidNode(m_invalidKey); 219 | m_pMemory = rhs.m_pMemory; 220 | m_pNode = rhs.m_pNode; 221 | } 222 | 223 | template 224 | inline void Node::Assign(const T& rhs) { 225 | if (!m_isValid) 226 | throw InvalidNode(m_invalidKey); 227 | AssignData(convert::encode(rhs)); 228 | } 229 | 230 | template <> 231 | inline void Node::Assign(const std::string& rhs) { 232 | EnsureNodeExists(); 233 | m_pNode->set_scalar(rhs); 234 | } 235 | 236 | inline void Node::Assign(const char* rhs) { 237 | EnsureNodeExists(); 238 | m_pNode->set_scalar(rhs); 239 | } 240 | 241 | inline void Node::Assign(char* rhs) { 242 | EnsureNodeExists(); 243 | m_pNode->set_scalar(rhs); 244 | } 245 | 246 | inline void Node::AssignData(const Node& rhs) { 247 | EnsureNodeExists(); 248 | rhs.EnsureNodeExists(); 249 | 250 | m_pNode->set_data(*rhs.m_pNode); 251 | m_pMemory->merge(*rhs.m_pMemory); 252 | } 253 | 254 | inline void Node::AssignNode(const Node& rhs) { 255 | if (!m_isValid) 256 | throw InvalidNode(m_invalidKey); 257 | rhs.EnsureNodeExists(); 258 | 259 | if (!m_pNode) { 260 | m_pNode = rhs.m_pNode; 261 | m_pMemory = rhs.m_pMemory; 262 | return; 263 | } 264 | 265 | m_pNode->set_ref(*rhs.m_pNode); 266 | m_pMemory->merge(*rhs.m_pMemory); 267 | m_pNode = rhs.m_pNode; 268 | } 269 | 270 | // size/iterator 271 | inline std::size_t Node::size() const { 272 | if (!m_isValid) 273 | throw InvalidNode(m_invalidKey); 274 | return m_pNode ? m_pNode->size() : 0; 275 | } 276 | 277 | inline const_iterator Node::begin() const { 278 | if (!m_isValid) 279 | return const_iterator(); 280 | return m_pNode ? const_iterator(m_pNode->begin(), m_pMemory) 281 | : const_iterator(); 282 | } 283 | 284 | inline iterator Node::begin() { 285 | if (!m_isValid) 286 | return iterator(); 287 | return m_pNode ? iterator(m_pNode->begin(), m_pMemory) : iterator(); 288 | } 289 | 290 | inline const_iterator Node::end() const { 291 | if (!m_isValid) 292 | return const_iterator(); 293 | return m_pNode ? const_iterator(m_pNode->end(), m_pMemory) : const_iterator(); 294 | } 295 | 296 | inline iterator Node::end() { 297 | if (!m_isValid) 298 | return iterator(); 299 | return m_pNode ? iterator(m_pNode->end(), m_pMemory) : iterator(); 300 | } 301 | 302 | // sequence 303 | template 304 | inline void Node::push_back(const T& rhs) { 305 | if (!m_isValid) 306 | throw InvalidNode(m_invalidKey); 307 | push_back(Node(rhs)); 308 | } 309 | 310 | inline void Node::push_back(const Node& rhs) { 311 | EnsureNodeExists(); 312 | rhs.EnsureNodeExists(); 313 | 314 | m_pNode->push_back(*rhs.m_pNode, m_pMemory); 315 | m_pMemory->merge(*rhs.m_pMemory); 316 | } 317 | 318 | template 319 | std::string key_to_string(const Key& key) { 320 | return streamable_to_string::value>().impl(key); 321 | } 322 | 323 | // indexing 324 | template 325 | inline const Node Node::operator[](const Key& key) const { 326 | EnsureNodeExists(); 327 | detail::node* value = 328 | static_cast(*m_pNode).get(key, m_pMemory); 329 | if (!value) { 330 | return Node(ZombieNode, key_to_string(key)); 331 | } 332 | return Node(*value, m_pMemory); 333 | } 334 | 335 | template 336 | inline Node Node::operator[](const Key& key) { 337 | EnsureNodeExists(); 338 | detail::node& value = m_pNode->get(key, m_pMemory); 339 | return Node(value, m_pMemory); 340 | } 341 | 342 | template 343 | inline bool Node::remove(const Key& key) { 344 | EnsureNodeExists(); 345 | return m_pNode->remove(key, m_pMemory); 346 | } 347 | 348 | inline const Node Node::operator[](const Node& key) const { 349 | EnsureNodeExists(); 350 | key.EnsureNodeExists(); 351 | m_pMemory->merge(*key.m_pMemory); 352 | detail::node* value = 353 | static_cast(*m_pNode).get(*key.m_pNode, m_pMemory); 354 | if (!value) { 355 | return Node(ZombieNode, key_to_string(key)); 356 | } 357 | return Node(*value, m_pMemory); 358 | } 359 | 360 | inline Node Node::operator[](const Node& key) { 361 | EnsureNodeExists(); 362 | key.EnsureNodeExists(); 363 | m_pMemory->merge(*key.m_pMemory); 364 | detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory); 365 | return Node(value, m_pMemory); 366 | } 367 | 368 | inline bool Node::remove(const Node& key) { 369 | EnsureNodeExists(); 370 | key.EnsureNodeExists(); 371 | return m_pNode->remove(*key.m_pNode, m_pMemory); 372 | } 373 | 374 | // map 375 | template 376 | inline void Node::force_insert(const Key& key, const Value& value) { 377 | EnsureNodeExists(); 378 | m_pNode->force_insert(key, value, m_pMemory); 379 | } 380 | 381 | // free functions 382 | inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); } 383 | } // namespace YAML 384 | 385 | #endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 386 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/exceptions.h: -------------------------------------------------------------------------------- 1 | #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include "yaml-cpp/mark.h" 11 | #include "yaml-cpp/noexcept.h" 12 | #include "yaml-cpp/traits.h" 13 | #include 14 | #include 15 | #include 16 | 17 | namespace YAML { 18 | // error messages 19 | namespace ErrorMsg { 20 | const char* const YAML_DIRECTIVE_ARGS = 21 | "YAML directives must have exactly one argument"; 22 | const char* const YAML_VERSION = "bad YAML version: "; 23 | const char* const YAML_MAJOR_VERSION = "YAML major version too large"; 24 | const char* const REPEATED_YAML_DIRECTIVE = "repeated YAML directive"; 25 | const char* const TAG_DIRECTIVE_ARGS = 26 | "TAG directives must have exactly two arguments"; 27 | const char* const REPEATED_TAG_DIRECTIVE = "repeated TAG directive"; 28 | const char* const CHAR_IN_TAG_HANDLE = 29 | "illegal character found while scanning tag handle"; 30 | const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix"; 31 | const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found"; 32 | const char* const END_OF_MAP = "end of map not found"; 33 | const char* const END_OF_MAP_FLOW = "end of map flow not found"; 34 | const char* const END_OF_SEQ = "end of sequence not found"; 35 | const char* const END_OF_SEQ_FLOW = "end of sequence flow not found"; 36 | const char* const MULTIPLE_TAGS = 37 | "cannot assign multiple tags to the same node"; 38 | const char* const MULTIPLE_ANCHORS = 39 | "cannot assign multiple anchors to the same node"; 40 | const char* const MULTIPLE_ALIASES = 41 | "cannot assign multiple aliases to the same node"; 42 | const char* const ALIAS_CONTENT = 43 | "aliases can't have any content, *including* tags"; 44 | const char* const INVALID_HEX = "bad character found while scanning hex number"; 45 | const char* const INVALID_UNICODE = "invalid unicode: "; 46 | const char* const INVALID_ESCAPE = "unknown escape character: "; 47 | const char* const UNKNOWN_TOKEN = "unknown token"; 48 | const char* const DOC_IN_SCALAR = "illegal document indicator in scalar"; 49 | const char* const EOF_IN_SCALAR = "illegal EOF in scalar"; 50 | const char* const CHAR_IN_SCALAR = "illegal character in scalar"; 51 | const char* const UNEXPECTED_SCALAR = "unexpected scalar"; 52 | const char* const UNEXPECTED_FLOW = "plain value cannot start with flow indicator character"; 53 | const char* const TAB_IN_INDENTATION = 54 | "illegal tab when looking for indentation"; 55 | const char* const FLOW_END = "illegal flow end"; 56 | const char* const BLOCK_ENTRY = "illegal block entry"; 57 | const char* const MAP_KEY = "illegal map key"; 58 | const char* const MAP_VALUE = "illegal map value"; 59 | const char* const ALIAS_NOT_FOUND = "alias not found after *"; 60 | const char* const ANCHOR_NOT_FOUND = "anchor not found after &"; 61 | const char* const CHAR_IN_ALIAS = 62 | "illegal character found while scanning alias"; 63 | const char* const CHAR_IN_ANCHOR = 64 | "illegal character found while scanning anchor"; 65 | const char* const ZERO_INDENT_IN_BLOCK = 66 | "cannot set zero indentation for a block scalar"; 67 | const char* const CHAR_IN_BLOCK = "unexpected character in block scalar"; 68 | const char* const AMBIGUOUS_ANCHOR = 69 | "cannot assign the same alias to multiple nodes"; 70 | const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined: "; 71 | 72 | const char* const INVALID_NODE = 73 | "invalid node; this may result from using a map iterator as a sequence " 74 | "iterator, or vice-versa"; 75 | const char* const INVALID_SCALAR = "invalid scalar"; 76 | const char* const KEY_NOT_FOUND = "key not found"; 77 | const char* const BAD_CONVERSION = "bad conversion"; 78 | const char* const BAD_DEREFERENCE = "bad dereference"; 79 | const char* const BAD_SUBSCRIPT = "operator[] call on a scalar"; 80 | const char* const BAD_PUSHBACK = "appending to a non-sequence"; 81 | const char* const BAD_INSERT = "inserting in a non-convertible-to-map"; 82 | 83 | const char* const UNMATCHED_GROUP_TAG = "unmatched group tag"; 84 | const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token"; 85 | const char* const UNEXPECTED_END_MAP = "unexpected end map token"; 86 | const char* const SINGLE_QUOTED_CHAR = 87 | "invalid character in single-quoted string"; 88 | const char* const INVALID_ANCHOR = "invalid anchor"; 89 | const char* const INVALID_ALIAS = "invalid alias"; 90 | const char* const INVALID_TAG = "invalid tag"; 91 | const char* const BAD_FILE = "bad file"; 92 | 93 | template 94 | inline const std::string KEY_NOT_FOUND_WITH_KEY( 95 | const T&, typename disable_if>::type* = 0) { 96 | return KEY_NOT_FOUND; 97 | } 98 | 99 | inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) { 100 | std::stringstream stream; 101 | stream << KEY_NOT_FOUND << ": " << key; 102 | return stream.str(); 103 | } 104 | 105 | inline const std::string KEY_NOT_FOUND_WITH_KEY(const char* key) { 106 | std::stringstream stream; 107 | stream << KEY_NOT_FOUND << ": " << key; 108 | return stream.str(); 109 | } 110 | 111 | template 112 | inline const std::string KEY_NOT_FOUND_WITH_KEY( 113 | const T& key, typename enable_if>::type* = 0) { 114 | std::stringstream stream; 115 | stream << KEY_NOT_FOUND << ": " << key; 116 | return stream.str(); 117 | } 118 | 119 | template 120 | inline const std::string BAD_SUBSCRIPT_WITH_KEY( 121 | const T&, typename disable_if>::type* = nullptr) { 122 | return BAD_SUBSCRIPT; 123 | } 124 | 125 | inline const std::string BAD_SUBSCRIPT_WITH_KEY(const std::string& key) { 126 | std::stringstream stream; 127 | stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")"; 128 | return stream.str(); 129 | } 130 | 131 | inline const std::string BAD_SUBSCRIPT_WITH_KEY(const char* key) { 132 | std::stringstream stream; 133 | stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")"; 134 | return stream.str(); 135 | } 136 | 137 | template 138 | inline const std::string BAD_SUBSCRIPT_WITH_KEY( 139 | const T& key, typename enable_if>::type* = nullptr) { 140 | std::stringstream stream; 141 | stream << BAD_SUBSCRIPT << " (key: \"" << key << "\")"; 142 | return stream.str(); 143 | } 144 | 145 | inline const std::string INVALID_NODE_WITH_KEY(const std::string& key) { 146 | std::stringstream stream; 147 | if (key.empty()) { 148 | return INVALID_NODE; 149 | } 150 | stream << "invalid node; first invalid key: \"" << key << "\""; 151 | return stream.str(); 152 | } 153 | } // namespace ErrorMsg 154 | 155 | class YAML_CPP_API Exception : public std::runtime_error { 156 | public: 157 | Exception(const Mark& mark_, const std::string& msg_) 158 | : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {} 159 | ~Exception() YAML_CPP_NOEXCEPT override; 160 | 161 | Exception(const Exception&) = default; 162 | 163 | Mark mark; 164 | std::string msg; 165 | 166 | private: 167 | static const std::string build_what(const Mark& mark, 168 | const std::string& msg) { 169 | if (mark.is_null()) { 170 | return msg; 171 | } 172 | 173 | std::stringstream output; 174 | output << "yaml-cpp: error at line " << mark.line + 1 << ", column " 175 | << mark.column + 1 << ": " << msg; 176 | return output.str(); 177 | } 178 | }; 179 | 180 | class YAML_CPP_API ParserException : public Exception { 181 | public: 182 | ParserException(const Mark& mark_, const std::string& msg_) 183 | : Exception(mark_, msg_) {} 184 | ParserException(const ParserException&) = default; 185 | ~ParserException() YAML_CPP_NOEXCEPT override; 186 | }; 187 | 188 | class YAML_CPP_API RepresentationException : public Exception { 189 | public: 190 | RepresentationException(const Mark& mark_, const std::string& msg_) 191 | : Exception(mark_, msg_) {} 192 | RepresentationException(const RepresentationException&) = default; 193 | ~RepresentationException() YAML_CPP_NOEXCEPT override; 194 | }; 195 | 196 | // representation exceptions 197 | class YAML_CPP_API InvalidScalar : public RepresentationException { 198 | public: 199 | InvalidScalar(const Mark& mark_) 200 | : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {} 201 | InvalidScalar(const InvalidScalar&) = default; 202 | ~InvalidScalar() YAML_CPP_NOEXCEPT override; 203 | }; 204 | 205 | class YAML_CPP_API KeyNotFound : public RepresentationException { 206 | public: 207 | template 208 | KeyNotFound(const Mark& mark_, const T& key_) 209 | : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) { 210 | } 211 | KeyNotFound(const KeyNotFound&) = default; 212 | ~KeyNotFound() YAML_CPP_NOEXCEPT override; 213 | }; 214 | 215 | template 216 | class YAML_CPP_API TypedKeyNotFound : public KeyNotFound { 217 | public: 218 | TypedKeyNotFound(const Mark& mark_, const T& key_) 219 | : KeyNotFound(mark_, key_), key(key_) {} 220 | ~TypedKeyNotFound() YAML_CPP_NOEXCEPT override = default; 221 | 222 | T key; 223 | }; 224 | 225 | template 226 | inline TypedKeyNotFound MakeTypedKeyNotFound(const Mark& mark, 227 | const T& key) { 228 | return TypedKeyNotFound(mark, key); 229 | } 230 | 231 | class YAML_CPP_API InvalidNode : public RepresentationException { 232 | public: 233 | InvalidNode(const std::string& key) 234 | : RepresentationException(Mark::null_mark(), 235 | ErrorMsg::INVALID_NODE_WITH_KEY(key)) {} 236 | InvalidNode(const InvalidNode&) = default; 237 | ~InvalidNode() YAML_CPP_NOEXCEPT override; 238 | }; 239 | 240 | class YAML_CPP_API BadConversion : public RepresentationException { 241 | public: 242 | explicit BadConversion(const Mark& mark_) 243 | : RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {} 244 | BadConversion(const BadConversion&) = default; 245 | ~BadConversion() YAML_CPP_NOEXCEPT override; 246 | }; 247 | 248 | template 249 | class TypedBadConversion : public BadConversion { 250 | public: 251 | explicit TypedBadConversion(const Mark& mark_) : BadConversion(mark_) {} 252 | }; 253 | 254 | class YAML_CPP_API BadDereference : public RepresentationException { 255 | public: 256 | BadDereference() 257 | : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {} 258 | BadDereference(const BadDereference&) = default; 259 | ~BadDereference() YAML_CPP_NOEXCEPT override; 260 | }; 261 | 262 | class YAML_CPP_API BadSubscript : public RepresentationException { 263 | public: 264 | template 265 | BadSubscript(const Mark& mark_, const Key& key) 266 | : RepresentationException(mark_, ErrorMsg::BAD_SUBSCRIPT_WITH_KEY(key)) {} 267 | BadSubscript(const BadSubscript&) = default; 268 | ~BadSubscript() YAML_CPP_NOEXCEPT override; 269 | }; 270 | 271 | class YAML_CPP_API BadPushback : public RepresentationException { 272 | public: 273 | BadPushback() 274 | : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {} 275 | BadPushback(const BadPushback&) = default; 276 | ~BadPushback() YAML_CPP_NOEXCEPT override; 277 | }; 278 | 279 | class YAML_CPP_API BadInsert : public RepresentationException { 280 | public: 281 | BadInsert() 282 | : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {} 283 | BadInsert(const BadInsert&) = default; 284 | ~BadInsert() YAML_CPP_NOEXCEPT override; 285 | }; 286 | 287 | class YAML_CPP_API EmitterException : public Exception { 288 | public: 289 | EmitterException(const std::string& msg_) 290 | : Exception(Mark::null_mark(), msg_) {} 291 | EmitterException(const EmitterException&) = default; 292 | ~EmitterException() YAML_CPP_NOEXCEPT override; 293 | }; 294 | 295 | class YAML_CPP_API BadFile : public Exception { 296 | public: 297 | explicit BadFile(const std::string& filename) 298 | : Exception(Mark::null_mark(), 299 | std::string(ErrorMsg::BAD_FILE) + ": " + filename) {} 300 | BadFile(const BadFile&) = default; 301 | ~BadFile() YAML_CPP_NOEXCEPT override; 302 | }; 303 | } // namespace YAML 304 | 305 | #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 306 | -------------------------------------------------------------------------------- /src/forwarder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Azumi art logo 4 | logo=$(cat << "EOF" 5 | \033[1;96m 6 | 7 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠀⢀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 8 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠀⡀⠤⠒⠊⠉⠀⠀⠀⠀⠈⠁⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 9 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀\033[1;93m⠀⢀⠔⠉⠀⠀⠀⠀⢀⡠⠤⠐⠒⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 10 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠀⣀⡠⠤⠤⠀⠀⠂⠐\033[1;96m⠀⠠⢤⠎⢑⡭⣽⣳⠶⣖⡶⣤⣖⣬⡽⡭⣥⣄\033[1;93m⠒⠒⠀⠐⠁⠑⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 11 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⢀⠴⠊⠁⠀⠀⠀⠀⡀⠀\033[1;96m⣠⣴⡶⣿⢏⡿⣝⡳⢧⡻⣟⡻⣞⠿⣾⡽⣳⣯⣳⣞⡻⣦⡀⠀⠀\033[1;93m⠀⠈⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 12 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⢨⠀⠀⠀⢀⠤⠂⠁\033[1;96m⢠⣾⡟⣧⠿⣝⣮⣽⢺⣝⣳⡽⣎⢷⣫⡟⡵⡿⣵⢫⡷⣾⢷⣭⢻⣦⡄\033[1;93m⠤⡸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 13 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠘⡄⠀⠀⠓⠂⠀\033[1;96m⣴⣿⢷⡿⣝⣻⣏⡷⣾⣟⡼⣣⢟⣼⣣⢟⣯⢗⣻⣽⣏⡾⡽⣟⣧⠿⡼⣿⣦\033[1;93m⣃⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 14 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⢀⠇⠀⠀⠀⠀\033[1;96m⣼⣿⢿⣼⡻⣼⡟⣼⣧⢿⣿⣸⡧⠿⠃⢿⣜⣻⢿⣤⣛⣿⢧⣻⢻⢿⡿⢧⣛⣿⣧⠀\033[1;93m⠛⠤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 15 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⢸⠁⠀⠀⠀⠀\033[1;96m⣼⣻⡿⣾⣳⡽⣾⣽⡷⣻⣞⢿⣫⠕⣫⣫⣸⢮⣝⡇⠱⣏⣾⣻⡽⣻⣮⣿⣻⡜⣞⡿⣷\033[1;93m⢀⠀⠀⠑⠢⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ 16 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠘⣧⠀⠀⠀\033[1;96m⣼⣳⢯⣿⣗⣿⣏⣿⠆⣟⣿⣵⢛⣵⡿⣿⣏⣟⡾⣜⣻⠀⢻⡖⣷⢳⣏⡶⣻⡧⣟⡼⣻⡽⣇\033[1;93m⠁⠢⡀⠠⡀⠑⡄⠀⠀⠀⠀⠀⠀⠀ 17 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠈⢦⠀\033[1;96m⣰⣯⣟⢯⣿⢾⣹⢾⡟⠰⣏⡾⣾⣟⡷⣿⣻⣽⣷⡶⣟⠿⡆⠀⢻⣝⣯⢷⣹⢧⣿⢧⡻⣽⣳⢽⡀\033[1;93m⠀⠈⠀⠈⠂⡼⠀⠀⠀⠀⠀⠀⠀ 18 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠀⡀⢵\033[1;96m⣟⣾⡟⣾⣿⣻⢽⣺⠇⠀⣿⡱⢿⡞⣵⡳⣭⣿⡜⣿⣭⣻⣷⠲⠤⢿⣾⢯⢯⣛⢿⣳⡝⣾⣿⢭⡇⠀\033[1;93m⠀⠀⠀⡰⠁⠀⠀⠀⠀⠀⠀⠀ 19 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⢀⠤⠊⠀\033[1;96m⣼⢻⣿⢞⣯⢿⡽⣸⣹⡆⠀⢷⣏⢯⣿⣧⣛⠶⣯⢿⣽⣷⣧⣛⣦⠀⠀⠙⢿⣳⣽⣿⣣⢟⡶⣿⣫⡇⠀⠀\033[1;93m⠀⠰⠁⠀⠀⠀⠀⠀⠀⠀⠀ 20 | ⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⣠⠖⠁⠀⠀⡄\033[1;96m⡿⣯⣷⣻⡽⣞⡟⣿⣿⣟⠉⠈⢯⣗⣻⣕⢯⣛⡞⣯⢮⣷⣭⡚⠓⠋⠀⠀⠀⠈⠉⣿⡽⣎⠷⡏⡷⣷⠀⠀⠀\033[1;93m⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀ 21 | ⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠐⣇⠀⠀⢀⠊\033[1;96m⣼⣇⣿⡗⣿⣽⣷⡿⣿⣱⡿⣆⠀⠀⠙⠒⠛⠓⠋⠉⠉⠀⠀⠀\033[1;91m⢠⣴⣯⣶⣶⣤⡀\033[1;96m ⠀⣿⣟⡼⣛⡇⣟⣿⡆\033[1;93m⡀⠀⢀⠇⠀⠀⠀⠀⠀⠀⠀⠀ 22 | ⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠘⢤⠀⠃⠌\033[1;96m⣸⣿⢾⡽⣹⣾⠹⣞⡵⣳⣽⡽⣖⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀\033[1;91m⣤⣖⣻⣾⣝⢿⡄\033[1;96m ⢸⣯⢳⣏⡿⣏⣾⢧\033[1;93m⠈⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀ 23 | ⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠘⠀⠈⠀\033[1;96m⡿⣿⣻⡽⣽⣿⢧⠌⠉\033[1;91m⠉⣴⣿⣿⣫⣅⡀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣛⠿⠿⢟⢙⡄⠙\033[1;96m ⠘⣯⢳⣞⡟⣯⢾⣻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 24 | ⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⡇⠀⠀⠀\033[1;96m⡿⣿⣿⢵⣫⣿⣆⠁⠂\033[1;91m⣼⡿⢹⣿⡿⠽⠟⢢⠀⠀⠀⠀⠀⠀⠀⢹⠀⢄⢀⠀⡿⠀⠀\033[1;96m ⢰⣯⢷⣺⣏⣯⢻⡽⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 25 | ⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⡇⠀⢀⠠\033[1;96m⣿⣿⢾⣛⡶⣽⠈⢓⠀\033[1;91m⢻⠁⢸⠇⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠑⠠⠤⠔⠂⠀⠀\033[1;96m ⢸⣿⢮⣽⠿⣜⣻⡝⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 26 | ⠀⠀⠀⠀⠀⠀⠀⠀\033[1;93m⠀⠑⠊⠁\033[1;96m⢠⡷⡇⣿⣿⢼⣹⡀⠀⠑⢄⠀\033[1;91m⠀⠃⠌⣁⠦⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠂⠀⠀\033[1;96m⢀⣿⢾⡝⣾⡽⣺⢽⣹⣽⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 27 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣻⢽⣻⡟⣮⣝⡷⢦⣄⣄⣢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⣯⢿⡺⣟⢷⡹⢾⣷⡞⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 28 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣟⡿⣎⢿⡽⣳⢮⣿⣹⣾⣯⡝⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠃⠀⠀⠀⠀⠀⠀⣀⣴⡟⣿⢧⣏⢷⡟⣮⠝⢿⣹⣯⡽⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀ 29 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣯⡷⣏⣾⡳⣽⢺⣷⡹⣟⢶⡹⣾⡽⣷⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠔⣾⢯⣷⡇⣿⢳⣎⢿⡞⣽⢦⣼⡽⣧⢻⡽⣆⠀⠀⠀⠀⠀⠀⠀⠀ 30 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣟⢾⡷⣭⣿⢳⣭⢻⣷⡻⣜⣻⡵⣻⡼⣿⠾⠫\033[1;96m⣽⣟⣶⣶⣶⠒⠒⠂⠉⠀\033[1;96m⢸⣽⢺⡷⣷⣯⢗⣮⣟⢾⢧⣻⠼⡿⣿⢣⡟⣼⣆⠀⠀⠀⠀⠀⠀⠀ 31 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡾⣝⣾⢳⢧⣟⡳⣎⣿⣿⣱⢏⣾⣽⣳⠟\033[1;92m⠁⠀⡌⠈\033[1;96m⢹⡯⠟⠛⠀⠀⠀⠀⠀⠈\033[1;96m⣷⢻⣼⣽⣿⡾⣼⣏⣾⣻⡜⣯⣷⢿⣟⣼⡳⣞⣦⠀⠀⠀⠀⠀⠀ 32 | ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⢿⡸⣎⠿⣾⡏⣷⣉⣷⣿⢹⣎⡿\033[1;92m⠎⡎⠀⠀⠀⡇⠀⣾⠱⡀⠀⠀⠀⠀⠀⠀⠀⠈⣹⠉⡏⠀\033[1;96m⠹⣾⣏⢹⣶⢹⣶⢿⡾⣿⢶⣿⣸⠾⣇⠀⠀⠀⠀⠀ 33 | ⠀⠀⠀⠀⠀⠀⠀⣠⣾⢫⣞⡽⣯⢿⣹⡟⣶⣹⢷⣻\033[1;92m⡷⠊⠀⡜⠀⠀⠀⠀⢱⠀⣿⡀⠈⠢⢀⣀⣀⠠⠄⠒⢈⡏⡰⠀⠀⠀\033[1;96m⠀⣿⡜⣮⢟⡼⣻⡵⣻⣗⠾⣟⣯⢻⣆⠀⠀⠀⠀ 34 | ⠀⠀⠀⠀⠀⢀⣴⣿⢣⣟⡾⣽⣯⢳⣿⡹⣖⣿⡳\033[1;92m⠋⠀⠀⡸⠀⠀⠀⠀⠀⢸⠀⢺⢂⠀⠀⠀⠀⠀⠀⠀⢠⡺⡱⠁⠀⠀⠀⠀\033[1;96m⢹⣧⣻⢮⡳⣝⡷⢧⣻⢯⢿⣻⣳⢞⡆⠀⠀⠀ 35 | ⠀⠀⠀⠀⢀⡾⣽⣣⡿⣼⣏⡿⣼⣳⡯⢷⣹⣯⠇\033[1;92m⠀⠀⢠⠁⠀⠀⠀⠀⠀⠈⡆⠈⢹⡰⠤⡀⠀⠀⠀⢠⡼⢱⠁⠀⠀⠀⠀⠀⠀\033[1;96m⠹⣿⣿⣱⣻⣼⣏⢷⣯⣿⡳⣿⣎⢿⡀⠀⠀ 36 | ⠀⠀⠀⠀⣾⣽⠷⣿⣵⡿⣼⡟⣭⣷⡟⣿⢯⡏⠀\033[1;92m⠀⠀⠘⠀⠀⠒⠈⢡⠀⠀⢗⢄⠀⠃⠀⠺⢁⢈⠥⠋⣀⠇⠀⠀⠀⠀⠀⠀⡀⠀\033[1;96m⠈⠙⢿⣳⢞⣽⢯⣞⣾⣯⡝⣿⡾⡇⠀ 37 | \033[96m __ \033[1;94m ________ \033[1;92m ____ ____ \033[1;93m ___ ___ \033[1;91m __ 38 | \033[96m /""\ \033[1;94m (" "\ \033[1;92m(" _||_ " |\033[1;93m|" \ /" | \033[1;91m|" \ 39 | \033[96m / \ \033[1;94m \___/ :)\033[1;92m| ( ) : |\033[1;93m \ \ // | \033[1;91m|| | 40 | \033[96m /' /\ \ \033[1;94m / ___/ \033[1;92m(: | | . )\033[1;93m /\ \/. |\033[1;91m |: | 41 | \033[96m // __' \ \033[1;94m // \__ \033[1;92m \ \__/ / \033[1;93m|: \. | \033[1;91m|. | 42 | \033[96m / / \ \ \033[1;94m(: / "\ \033[1;92m /\ __ /\ \033[1;93m|. \ /: |\033[1;91m /\ |\ 43 | \033[96m(___/ \___) \033[1;94m\_______)\033[1;92m(__________)\033[1;93m|___|\__/|___|\033[1;91m(__\_|_) \033[1;92mSCRIPT Author: github.com/Azumi67 \033[0m 44 | EOF 45 | ) 46 | 47 | RESET="\033[0m" 48 | BOLD="\033[1m" 49 | CYAN="\033[1;36m" 50 | BLUE="\033[1;34m" 51 | GREEN="\033[1;32m" 52 | YELLOW="\033[1;33m" 53 | RED="\033[1;31m" 54 | 55 | function display_logo() { 56 | echo -e "$logo" 57 | } 58 | 59 | function check_ulimits() { 60 | print_info "Checking and updating file descriptor limits..." 61 | current_limit=$(ulimit -n) 62 | if [ "$current_limit" -lt 65536 ]; then 63 | print_info "Current limit ($current_limit) is less than 65536. Updating..." 64 | ulimit -n 65536 65 | print_success "Temporary limit set to 65536." 66 | 67 | print_info "Updating /etc/security/limits.conf for permanent change..." 68 | if ! grep -q "hard nofile 65536" /etc/security/limits.conf; then 69 | echo -e "$(whoami)\thard\tnofile\t65536" | sudo tee -a /etc/security/limits.conf 70 | echo -e "$(whoami)\tsoft\tnofile\t65536" | sudo tee -a /etc/security/limits.conf 71 | print_success "/etc/security/limits.conf updated." 72 | else 73 | print_info "File descriptor limits already set in /etc/security/limits.conf." 74 | fi 75 | else 76 | print_success "File descriptor limit is sufficient ($current_limit)." 77 | fi 78 | } 79 | 80 | function install_yaml_cpp_json() { 81 | print_info "Installing json.hpp..." 82 | 83 | if [ ! -f "json.hpp" ]; then 84 | wget -O json.hpp https://github.com/nlohmann/json/releases/latest/download/json.hpp || { print_error "Failed to download json.hpp"; exit 1; } 85 | print_success "json.hpp downloaded." 86 | else 87 | print_info "json.hpp already exists." 88 | fi 89 | } 90 | 91 | function display_menu() { 92 | echo -e "${CYAN}${BOLD}=========================================${RESET}" 93 | echo -e "${BOLD}${BLUE} TCP/UDP Forwarder Setup Script ${RESET}" 94 | echo -e "${CYAN}${BOLD}=========================================${RESET}" 95 | echo -e "1) ${GREEN}Install Dependencies${RESET}" 96 | echo -e "2) ${GREEN}Set Up Virtual Environment${RESET}" 97 | echo -e "3) ${GREEN}Compile ${YELLOW}TCP${GREEN} Forwarder${RESET}" 98 | echo -e "4) ${GREEN}Compile ${YELLOW}UDP${GREEN} Forwarder${RESET}" 99 | echo -e "5) ${GREEN}Run Forwarder & Flask Server${RESET}" 100 | echo -e "6) ${GREEN}Run All Steps${RESET}" 101 | echo -e "7) ${RED}Quit${RESET}" 102 | echo -e "${CYAN}${BOLD}=========================================${RESET}" 103 | } 104 | 105 | function print_info() { echo -e "${BLUE}[INFO]${RESET} $1"; } 106 | function print_success() { echo -e "${GREEN}[SUCCESS]${RESET} $1"; } 107 | function print_warning() { echo -e "${YELLOW}[WARNING]${RESET} $1"; } 108 | function print_error() { echo -e "${RED}[ERROR]${RESET} $1"; } 109 | 110 | function install_stuff() { 111 | print_info "Detecting Linux & architecture..." 112 | . /etc/os-release 113 | OS_TYPE=$NAME 114 | ARCH=$(uname -m) 115 | 116 | print_info "Detected OS: $OS_TYPE, Architecture: $ARCH" 117 | 118 | if [ "$EUID" -ne 0 ]; then 119 | print_error "Please run as root." 120 | exit 1 121 | fi 122 | 123 | print_info "Updating Stuff..." 124 | sudo apt-get update -y 125 | 126 | print_info "Installing required stuff..." 127 | sudo apt-get install -y g++ libboost-all-dev libyaml-cpp-dev python3 python3-venv python3-pip net-tools iptables-persistent 128 | print_success "Packages installed successfully." 129 | } 130 | 131 | function setup_virtualenv() { 132 | local venv_dir="$(pwd)/venv" 133 | 134 | if [ ! -d "$venv_dir" ]; then 135 | print_info "Creating Python virtual environment..." 136 | python3 -m venv "$venv_dir" || { print_error "Couldn't create virtual environment."; exit 1; } 137 | print_success "Virtual environment created." 138 | else 139 | print_success "Virtual environment already exists." 140 | fi 141 | 142 | print_info "Activating virtual environment..." 143 | source "$venv_dir/bin/activate" || { print_error "Couldn't activate virtual environment."; exit 1; } 144 | print_success "Virtual environment activated." 145 | 146 | print_info "Installing Python packages..." 147 | pip install --upgrade pip 148 | pip install Flask Flask-Caching Flask-Login bcrypt pyotp pyyaml psutil scapy python-telegram-bot || { 149 | print_error "Couldn't install some Python packages."; exit 1; 150 | } 151 | print_success "Python packages installed successfully." 152 | } 153 | 154 | 155 | function install_python_stuff() { 156 | print_info "Installing Python packages..." 157 | pip install --upgrade pip 158 | pip install Flask Flask-Caching Flask-Login bcrypt pyotp pyyaml psutil scapy python-telegram-bot || { 159 | print_error "Coudln't install some Python packages."; exit 1; } 160 | print_success "Python packages installed successfully." 161 | } 162 | 163 | function compile_tcp_forwarder() { 164 | if [ ! -f "tcp_forwarder" ] || [ main.cpp -nt tcp_forwarder ]; then 165 | print_info "Compiling the TCP forwarder..." 166 | g++ tcp_forwarder.cpp -o tcp_forwarder -lboost_system -lyaml-cpp -pthread 167 | if [ $? -eq 0 ]; then 168 | print_success "TCP forwarder compiled successfully." 169 | else 170 | print_error "Failed to compile TCP forwarder." 171 | exit 1 172 | fi 173 | else 174 | print_success "TCP forwarder is already compiled." 175 | fi 176 | } 177 | 178 | function compile_udp_forwarder() { 179 | if [ ! -f "udp_forwarder" ] || [ main.cpp -nt udp_forwarder ]; then 180 | print_info "Compiling the UDP forwarder..." 181 | g++ udp_forwarder.cpp -o udp_forwarder -lboost_system -lyaml-cpp -pthread 182 | if [ $? -eq 0 ]; then 183 | print_success "UDP forwarder compiled successfully." 184 | else 185 | print_error "Failed to compile UDP forwarder." 186 | exit 1 187 | fi 188 | else 189 | print_success "UDP forwarder is already compiled." 190 | fi 191 | } 192 | 193 | function kill_forwarder() { 194 | print_info "Checking for existing forwarder processes..." 195 | existing_pid=$(pgrep -f "tcp_forwarder|udp_forwarder") 196 | if [ -n "$existing_pid" ]; then 197 | print_warning "Existing forwarder process found (PID: $existing_pid). Killing it..." 198 | kill -9 "$existing_pid" 199 | print_success "Existing forwarder process terminated." 200 | else 201 | print_info "No existing forwarder process found." 202 | fi 203 | } 204 | 205 | function start_services() { 206 | echo -e "${CYAN}${BOLD}=========================================${RESET}" 207 | echo -e "${BOLD}${BLUE} Choose Forwarder to Run ${RESET}" 208 | echo -e "${CYAN}${BOLD}=========================================${RESET}" 209 | echo -e "1) ${GREEN}Run TCP Forwarder${RESET}" 210 | echo -e "2) ${GREEN}Run UDP Forwarder${RESET}" 211 | echo -e "3) ${YELLOW}Back to main menu${RESET}" 212 | echo -e "${CYAN}${BOLD}=========================================${RESET}" 213 | 214 | while true; do 215 | read -p "Select an option: " forwarder_choice 216 | case $forwarder_choice in 217 | 1) 218 | FORWARDER_EXEC="./tcp_forwarder" 219 | print_info "Selected TCP forwarder." 220 | break 221 | ;; 222 | 2) 223 | FORWARDER_EXEC="./udp_forwarder" 224 | print_info "Selected UDP forwarder." 225 | break 226 | ;; 227 | 3) 228 | print_info "Cancelled. Returning to main menu." 229 | return 230 | ;; 231 | *) 232 | print_error "Invalid choice. Please select 1, 2, or 3." 233 | ;; 234 | esac 235 | done 236 | 237 | kill_forwarder 238 | 239 | print_info "Activating virtual environment..." 240 | source "$(pwd)/venv/bin/activate" || { print_error "Couldn't activate virtual environment."; exit 1; } 241 | 242 | print_info "Starting Flask server..." 243 | "$(pwd)/venv/bin/python" app.py > flask.log 2>&1 & 244 | FLASK_PID=$! 245 | 246 | print_info "Starting Forwarder..." 247 | $FORWARDER_EXEC "$CONFIG_FILE" > forwarder.log 2>&1 & 248 | FORWARDER_PID=$! 249 | 250 | print_success "Both services are now running. Logs: flask.log, forwarder.log" 251 | print_info "Flask PID: $FLASK_PID, Forwarder PID: $FORWARDER_PID" 252 | 253 | sleep 2 254 | wait $FORWARDER_PID $FLASK_PID 255 | } 256 | 257 | 258 | function run_all_steps() { 259 | check_ulimits 260 | install_stuff 261 | install_yaml_cpp_json 262 | setup_virtualenv 263 | install_python_stuff 264 | compile_tcp_forwarder 265 | compile_udp_forwarder 266 | start_services 267 | } 268 | 269 | function main() { 270 | while true; do 271 | display_menu 272 | read -p "Select an option: " choice 273 | case $choice in 274 | 1) check_ulimits && install_stuff && install_yaml_cpp_json ;; 275 | 2) 276 | setup_virtualenv 277 | install_python_stuff 278 | ;; 279 | 3) compile_tcp_forwarder ;; 280 | 4) compile_udp_forwarder ;; 281 | 5) 282 | setup_virtualenv 283 | start_services 284 | ;; 285 | 6) 286 | run_all_steps 287 | ;; 288 | 7) 289 | print_info "quiting.." 290 | exit 0 291 | ;; 292 | *) 293 | print_error "Wrong choice. Plz try again." 294 | ;; 295 | esac 296 | done 297 | } 298 | 299 | if [ "$#" -ne 1 ]; then 300 | print_error "No configuration file provided." 301 | echo -e "\nUsage: ./script.sh " 302 | exit 1 303 | else 304 | CONFIG_FILE=$1 305 | export CONFIG_FILE 306 | fi 307 | 308 | 309 | display_logo 310 | main 311 | -------------------------------------------------------------------------------- /telegramBot/robot.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import os 3 | import json 4 | import requests 5 | from requests.adapters import HTTPAdapter 6 | from requests.packages.urllib3.util.retry import Retry 7 | from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup 8 | from telegram.ext import Application, CommandHandler, CallbackContext, CallbackQueryHandler 9 | 10 | def load_config(): 11 | config_path = "config.json" 12 | config = {} 13 | if os.path.exists(config_path): 14 | with open(config_path, "r") as config_file: 15 | try: 16 | config = json.load(config_file) 17 | except json.JSONDecodeError: 18 | print("JSON is invalid. Recreating...") 19 | 20 | if not config.get("telegram_bot_token") or config["telegram_bot_token"] == "YOUR_TELEGRAM_BOT_TOKEN": 21 | config["telegram_bot_token"] = input("Enter your Telegram Bot Token: ") 22 | if not config.get("api_base_url") or config["api_base_url"] == "http://localhost:8080": 23 | config["api_base_url"] = input("Enter your API Base URL (e.g., http://localhost:8080): ") 24 | if not config.get("api_key") or config["api_key"] == "YOUR_API_KEY": 25 | config["api_key"] = input("Enter your API Key: ") 26 | 27 | with open(config_path, "w") as config_file: 28 | json.dump(config, config_file, indent=4) 29 | 30 | return config 31 | 32 | config = load_config() 33 | 34 | TELEGRAM_BOT_TOKEN = config.get("telegram_bot_token") 35 | API_BASE_URL = config.get("api_base_url") 36 | API_KEY = config.get("api_key") 37 | 38 | def api_request(endpoint, method="GET", data=None): 39 | headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"} 40 | url = f"{API_BASE_URL}/{endpoint}" 41 | try: 42 | if method == "POST": 43 | response = requests.post(url, headers=headers, json=data, timeout=30) 44 | else: 45 | response = requests.get(url, headers=headers, timeout=30) 46 | 47 | print(f"API call to {url} returned status {response.status_code}: {response.text}") 48 | 49 | if response.status_code == 200: 50 | try: 51 | return response.json() 52 | except json.JSONDecodeError: 53 | return {"message": response.text} 54 | else: 55 | return {"error": response.text} 56 | 57 | except requests.exceptions.RequestException as e: 58 | return {"error": str(e)} 59 | 60 | 61 | async def start(update: Update, context: CallbackContext): 62 | chat_id = update.effective_chat.id 63 | message = u"🤖 به ربات مانیتورینگ Azumi خوش آمدید! لطفاً یکی از گزینه‌های زیر را انتخاب کنید:" 64 | 65 | keyboard = [ 66 | [InlineKeyboardButton(u"📊 آمار ترافیک", callback_data="traffic_stats")], 67 | [InlineKeyboardButton(u"💻 وضعیت سیستم", callback_data="system_metrics")], 68 | [InlineKeyboardButton(u"🌐 ایپی‌های متصل", callback_data="connected_ips")], 69 | [InlineKeyboardButton(u"📝 مشاهده لاگ‌ها", callback_data="tunnel_logs")], 70 | [InlineKeyboardButton(u"🔍 وضعیت فورواردرها", callback_data="tunnel_status")], 71 | [InlineKeyboardButton(u"⚙️ تنظیمات TCP", callback_data="tcp_menu")], 72 | [InlineKeyboardButton(u"⚙️ تنظیمات UDP", callback_data="udp_menu")], 73 | [InlineKeyboardButton(u"🚪 خروج", callback_data="exit_bot")], 74 | ] 75 | 76 | reply_markup = InlineKeyboardMarkup(keyboard) 77 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 78 | 79 | async def button_handler(update: Update, context: CallbackContext): 80 | query = update.callback_query 81 | await query.answer() 82 | chat_id = query.message.chat_id 83 | 84 | if query.data == "traffic_stats": 85 | await traffic_stats(update, context) 86 | elif query.data == "system_metrics": 87 | await system_metrics(update, context) 88 | elif query.data == "connected_ips": 89 | await connected_ips(update, context) 90 | elif query.data == "tunnel_logs": 91 | await tunnel_logs(update, context) 92 | elif query.data == "tcp_menu": 93 | await tcp_menu(update, context) 94 | elif query.data == "udp_menu": 95 | await udp_menu(update, context) 96 | elif query.data == "restart_tcp": 97 | await restart_tcp(update, context) 98 | elif query.data == "restart_udp": 99 | await restart_udp(update, context) 100 | elif query.data == "stop_tcp": 101 | await stop_tcp(update, context) 102 | elif query.data == "stop_udp": 103 | await stop_udp(update, context) 104 | elif query.data == "tunnel_status": 105 | await fetch_forwarder_status(update, context) 106 | elif query.data == "show_menu": 107 | await start(update, context) 108 | elif query.data == "exit_bot": 109 | await context.bot.send_message(chat_id=chat_id, text="👋 بای بای") 110 | 111 | async def tcp_menu(update: Update, context: CallbackContext): 112 | chat_id = update.effective_chat.id 113 | message = u"⚙️ تنظیمات TCP:" 114 | 115 | keyboard = [ 116 | [InlineKeyboardButton(u"🔄 ریست TCP", callback_data="restart_tcp")], 117 | [InlineKeyboardButton(u"🛑 توقف TCP", callback_data="stop_tcp")], 118 | [InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")], 119 | ] 120 | 121 | reply_markup = InlineKeyboardMarkup(keyboard) 122 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 123 | 124 | async def udp_menu(update: Update, context: CallbackContext): 125 | chat_id = update.effective_chat.id 126 | message = u"⚙️ تنظیمات UDP:" 127 | 128 | keyboard = [ 129 | [InlineKeyboardButton(u"🔄 ریست UDP", callback_data="restart_udp")], 130 | [InlineKeyboardButton(u"🛑 توقف UDP", callback_data="stop_udp")], 131 | [InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")], 132 | ] 133 | 134 | reply_markup = InlineKeyboardMarkup(keyboard) 135 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 136 | 137 | 138 | async def traffic_stats(update: Update, context: CallbackContext): 139 | chat_id = update.effective_chat.id 140 | data = api_request("network-stats") 141 | 142 | if "error" in data: 143 | await context.bot.send_message(chat_id=chat_id, text=f"❌ خطا: {data['error']}") 144 | return 145 | 146 | message = u"📊 آمار ترافیک:\n" 147 | for port, stats in data.items(): 148 | message += ( 149 | f"پورت {port}:\n" 150 | f" 🔹 داده‌های ارسال‌شده: {stats['bytes_sent']}\n" 151 | f" 🔹 داده‌های دریافت‌شده: {stats['bytes_received']}\n" 152 | f" 🔹 بسته‌های ارسال‌شده: {stats['packets_sent']}\n" 153 | f" 🔹 بسته‌های دریافت‌شده: {stats['packets_received']}\n\n" 154 | ) 155 | 156 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 157 | reply_markup = InlineKeyboardMarkup(keyboard) 158 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 159 | 160 | async def system_metrics(update: Update, context: CallbackContext): 161 | chat_id = update.effective_chat.id 162 | data = api_request("metrics") 163 | 164 | if "error" in data: 165 | await context.bot.send_message(chat_id=chat_id, text=f"❌ خطا: {data['error']}") 166 | return 167 | 168 | message = ( 169 | f"💻 وضعیت سیستم:\n" 170 | f"🔹 استفاده از CPU: {data['cpu_usage']}%\n" 171 | f"🔹 استفاده از RAM: {data['ram_usage']}%\n" 172 | f"🔹 زمان روشن بودن سیستم: {data.get('uptime', 'نامشخص')}\n" 173 | ) 174 | 175 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 176 | reply_markup = InlineKeyboardMarkup(keyboard) 177 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 178 | 179 | 180 | async def connected_ips(update: Update, context: CallbackContext): 181 | chat_id = update.effective_chat.id 182 | data = api_request("public-ip-settings") 183 | 184 | if "error" in data: 185 | message = f"❌ خطا: {data['error']}" 186 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 187 | reply_markup = InlineKeyboardMarkup(keyboard) 188 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 189 | return 190 | 191 | message = u"🌐 ایپی‌های متصل:\n" 192 | keyboard = [] 193 | 194 | for ip, status in data["ip_status"].items(): 195 | status_text = "🔴 مسدود" if status == "banned" else "🟢 فعال" 196 | message += f"IP: {ip} - وضعیت: {status_text}\n" 197 | 198 | if status == "banned": 199 | keyboard.append([InlineKeyboardButton(f"🚫 رفع انسداد {ip}", callback_data=f"unban_{ip}")]) 200 | else: 201 | keyboard.append([InlineKeyboardButton(f"🔒 مسدود کردن {ip}", callback_data=f"ban_{ip}")]) 202 | 203 | keyboard.append([InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]) 204 | reply_markup = InlineKeyboardMarkup(keyboard) 205 | 206 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup, parse_mode="HTML") 207 | 208 | async def ban_ip(chat_id, ip, context): 209 | response = api_request("ban-ip", method="POST", data={"ip": ip}) 210 | message = f"✅ IP {ip} مسدود شد." if "message" in response else f"❌ خطا: {response.get('error')}" 211 | 212 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 213 | reply_markup = InlineKeyboardMarkup(keyboard) 214 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 215 | 216 | async def unban_ip(chat_id, ip, context): 217 | response = api_request("unban-ip", method="POST", data={"ip": ip}) 218 | message = f"✅ IP {ip} رفع انسداد شد." if "message" in response else f"❌ خطا: {response.get('error')}" 219 | 220 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 221 | reply_markup = InlineKeyboardMarkup(keyboard) 222 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 223 | 224 | async def tunnel_logs(update: Update, context: CallbackContext): 225 | chat_id = update.effective_chat.id 226 | data = api_request("api/tunnel-logs") 227 | 228 | if "error" in data: 229 | message = f"❌ خطا: {data['error']}" 230 | else: 231 | logs = data.get("logs", "لاگی برای نمایش وجود ندارد.") 232 | message = f"📝 لاگ‌های تانل:\n```\n{logs}\n```" 233 | 234 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 235 | reply_markup = InlineKeyboardMarkup(keyboard) 236 | 237 | await context.bot.send_message(chat_id=chat_id, text=message, parse_mode="Markdown", reply_markup=reply_markup) 238 | 239 | async def restart_tcp(update: Update, context: CallbackContext): 240 | chat_id = update.effective_chat.id 241 | response = api_request("restart-tcp-forwarder", method="POST") 242 | 243 | message = ( 244 | "✅ فورواردر TCP با موفقیت ریست شد." 245 | if "message" in response 246 | else f"❌ خطا در ریست فورواردر TCP: {response.get('error')}" 247 | ) 248 | await context.bot.send_message(chat_id=chat_id, text=message) 249 | 250 | async def restart_udp(update: Update, context: CallbackContext): 251 | chat_id = update.effective_chat.id 252 | response = api_request("restart-udp-forwarder", method="POST") 253 | 254 | message = ( 255 | "✅ فورواردر UDP با موفقیت ریست شد." 256 | if "message" in response 257 | else f"❌ خطا در ریست فورواردر UDP: {response.get('error')}" 258 | ) 259 | await context.bot.send_message(chat_id=chat_id, text=message) 260 | 261 | 262 | async def stop_tcp(update: Update, context: CallbackContext): 263 | chat_id = update.effective_chat.id 264 | response = api_request("stop-tcp-forwarder", method="POST") 265 | 266 | message = ( 267 | "✅ فورواردر TCP با موفقیت متوقف شد." 268 | if "message" in response 269 | else f"❌ خطا در متوقف کردن فورواردر TCP: {response.get('error')}" 270 | ) 271 | await context.bot.send_message(chat_id=chat_id, text=message) 272 | 273 | 274 | async def stop_udp(update: Update, context: CallbackContext): 275 | chat_id = update.effective_chat.id 276 | response = api_request("stop-udp-forwarder", method="POST") 277 | 278 | message = ( 279 | "✅ فورواردر UDP با موفقیت متوقف شد." 280 | if "message" in response 281 | else f"❌ خطا در متوقف کردن فورواردر UDP: {response.get('error')}" 282 | ) 283 | await context.bot.send_message(chat_id=chat_id, text=message) 284 | 285 | async def fetch_forwarder_status(update: Update, context: CallbackContext): 286 | chat_id = update.effective_chat.id 287 | response = api_request("tunnel-status") 288 | 289 | if "error" in response: 290 | message = f"❌ خطا در دریافت وضعیت فورواردرها: {response['error']}" 291 | else: 292 | tcp_status = response.get("tcp_forwarder", "Inactive") 293 | udp_status = response.get("udp_forwarder", "Inactive") 294 | 295 | tcp_status_text = "🟢 فعال" if tcp_status == "Active" else "🔴 غیرفعال" 296 | udp_status_text = "🟢 فعال" if udp_status == "Active" else "🔴 غیرفعال" 297 | 298 | message = ( 299 | f"🔍 وضعیت فورواردرها:\n" 300 | f" 🔹 فورواردر TCP: {tcp_status_text}\n" 301 | f" 🔹 فورواردر UDP: {udp_status_text}\n" 302 | ) 303 | 304 | keyboard = [[InlineKeyboardButton(u"🔙 بازگشت به منو", callback_data="show_menu")]] 305 | reply_markup = InlineKeyboardMarkup(keyboard) 306 | 307 | await context.bot.send_message(chat_id=chat_id, text=message, reply_markup=reply_markup) 308 | 309 | def main(): 310 | application = Application.builder().token(TELEGRAM_BOT_TOKEN).build() 311 | 312 | application.add_handler(CommandHandler("start", start)) 313 | application.add_handler(CallbackQueryHandler(button_handler)) 314 | 315 | print("Azumi Monitoring Bot started. Press Ctrl+C to stop.") 316 | application.run_polling() 317 | 318 | main() 319 | -------------------------------------------------------------------------------- /src/yaml-cpp/include/yaml-cpp/node/convert.h: -------------------------------------------------------------------------------- 1 | #ifndef NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 | #define NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 3 | 4 | #if defined(_MSC_VER) || \ 5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 7 | #pragma once 8 | #endif 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) 22 | #include 23 | #endif 24 | 25 | #include "yaml-cpp/binary.h" 26 | #include "yaml-cpp/node/impl.h" 27 | #include "yaml-cpp/node/iterator.h" 28 | #include "yaml-cpp/node/node.h" 29 | #include "yaml-cpp/node/type.h" 30 | #include "yaml-cpp/null.h" 31 | 32 | 33 | namespace YAML { 34 | class Binary; 35 | struct _Null; 36 | template 37 | struct convert; 38 | } // namespace YAML 39 | 40 | namespace YAML { 41 | namespace conversion { 42 | inline bool IsInfinity(const std::string& input) { 43 | return input == ".inf" || input == ".Inf" || input == ".INF" || 44 | input == "+.inf" || input == "+.Inf" || input == "+.INF"; 45 | } 46 | 47 | inline bool IsNegativeInfinity(const std::string& input) { 48 | return input == "-.inf" || input == "-.Inf" || input == "-.INF"; 49 | } 50 | 51 | inline bool IsNaN(const std::string& input) { 52 | return input == ".nan" || input == ".NaN" || input == ".NAN"; 53 | } 54 | } 55 | 56 | // Node 57 | template <> 58 | struct convert { 59 | static Node encode(const Node& rhs) { return rhs; } 60 | 61 | static bool decode(const Node& node, Node& rhs) { 62 | rhs.reset(node); 63 | return true; 64 | } 65 | }; 66 | 67 | // std::string 68 | template <> 69 | struct convert { 70 | static Node encode(const std::string& rhs) { return Node(rhs); } 71 | 72 | static bool decode(const Node& node, std::string& rhs) { 73 | if (!node.IsScalar()) 74 | return false; 75 | rhs = node.Scalar(); 76 | return true; 77 | } 78 | }; 79 | 80 | // C-strings can only be encoded 81 | template <> 82 | struct convert { 83 | static Node encode(const char* rhs) { return Node(rhs); } 84 | }; 85 | 86 | template <> 87 | struct convert { 88 | static Node encode(const char* rhs) { return Node(rhs); } 89 | }; 90 | 91 | template 92 | struct convert { 93 | static Node encode(const char* rhs) { return Node(rhs); } 94 | }; 95 | 96 | #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) 97 | template <> 98 | struct convert { 99 | static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } 100 | 101 | static bool decode(const Node& node, std::string_view& rhs) { 102 | if (!node.IsScalar()) 103 | return false; 104 | rhs = node.Scalar(); 105 | return true; 106 | } 107 | }; 108 | #endif 109 | 110 | template <> 111 | struct convert<_Null> { 112 | static Node encode(const _Null& /* rhs */) { return Node(); } 113 | 114 | static bool decode(const Node& node, _Null& /* rhs */) { 115 | return node.IsNull(); 116 | } 117 | }; 118 | 119 | namespace conversion { 120 | template 121 | typename std::enable_if< std::is_floating_point::value, void>::type 122 | inner_encode(const T& rhs, std::stringstream& stream){ 123 | if (std::isnan(rhs)) { 124 | stream << ".nan"; 125 | } else if (std::isinf(rhs)) { 126 | if (std::signbit(rhs)) { 127 | stream << "-.inf"; 128 | } else { 129 | stream << ".inf"; 130 | } 131 | } else { 132 | stream << rhs; 133 | } 134 | } 135 | 136 | template 137 | typename std::enable_if::value, void>::type 138 | inner_encode(const T& rhs, std::stringstream& stream){ 139 | stream << rhs; 140 | } 141 | 142 | template 143 | typename std::enable_if<(std::is_same::value || 144 | std::is_same::value), bool>::type 145 | ConvertStreamTo(std::stringstream& stream, T& rhs) { 146 | int num; 147 | if ((stream >> std::noskipws >> num) && (stream >> std::ws).eof()) { 148 | if (num >= (std::numeric_limits::min)() && 149 | num <= (std::numeric_limits::max)()) { 150 | rhs = static_cast(num); 151 | return true; 152 | } 153 | } 154 | return false; 155 | } 156 | 157 | template 158 | typename std::enable_if::value || 159 | std::is_same::value), bool>::type 160 | ConvertStreamTo(std::stringstream& stream, T& rhs) { 161 | if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { 162 | return true; 163 | } 164 | return false; 165 | } 166 | } 167 | 168 | #define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ 169 | template <> \ 170 | struct convert { \ 171 | \ 172 | static Node encode(const type& rhs) { \ 173 | std::stringstream stream; \ 174 | stream.imbue(std::locale("C")); \ 175 | stream.precision(std::numeric_limits::max_digits10); \ 176 | conversion::inner_encode(rhs, stream); \ 177 | return Node(stream.str()); \ 178 | } \ 179 | \ 180 | static bool decode(const Node& node, type& rhs) { \ 181 | if (node.Type() != NodeType::Scalar) { \ 182 | return false; \ 183 | } \ 184 | const std::string& input = node.Scalar(); \ 185 | std::stringstream stream(input); \ 186 | stream.imbue(std::locale("C")); \ 187 | stream.unsetf(std::ios::dec); \ 188 | if ((stream.peek() == '-') && std::is_unsigned::value) { \ 189 | return false; \ 190 | } \ 191 | if (conversion::ConvertStreamTo(stream, rhs)) { \ 192 | return true; \ 193 | } \ 194 | if (std::numeric_limits::has_infinity) { \ 195 | if (conversion::IsInfinity(input)) { \ 196 | rhs = std::numeric_limits::infinity(); \ 197 | return true; \ 198 | } else if (conversion::IsNegativeInfinity(input)) { \ 199 | rhs = negative_op std::numeric_limits::infinity(); \ 200 | return true; \ 201 | } \ 202 | } \ 203 | \ 204 | if (std::numeric_limits::has_quiet_NaN) { \ 205 | if (conversion::IsNaN(input)) { \ 206 | rhs = std::numeric_limits::quiet_NaN(); \ 207 | return true; \ 208 | } \ 209 | } \ 210 | \ 211 | return false; \ 212 | } \ 213 | } 214 | 215 | #define YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(type) \ 216 | YAML_DEFINE_CONVERT_STREAMABLE(type, -) 217 | 218 | #define YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(type) \ 219 | YAML_DEFINE_CONVERT_STREAMABLE(type, +) 220 | 221 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(int); 222 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(short); 223 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long); 224 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long long); 225 | YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned); 226 | YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned short); 227 | YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long); 228 | YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long); 229 | 230 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char); 231 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(signed char); 232 | YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char); 233 | 234 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float); 235 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double); 236 | YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long double); 237 | 238 | #undef YAML_DEFINE_CONVERT_STREAMABLE_SIGNED 239 | #undef YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED 240 | #undef YAML_DEFINE_CONVERT_STREAMABLE 241 | 242 | // bool 243 | template <> 244 | struct convert { 245 | static Node encode(bool rhs) { return rhs ? Node("true") : Node("false"); } 246 | 247 | YAML_CPP_API static bool decode(const Node& node, bool& rhs); 248 | }; 249 | 250 | // std::map 251 | template 252 | struct convert> { 253 | static Node encode(const std::map& rhs) { 254 | Node node(NodeType::Map); 255 | for (const auto& element : rhs) 256 | node.force_insert(element.first, element.second); 257 | return node; 258 | } 259 | 260 | static bool decode(const Node& node, std::map& rhs) { 261 | if (!node.IsMap()) 262 | return false; 263 | 264 | rhs.clear(); 265 | for (const auto& element : node) 266 | #if defined(__GNUC__) && __GNUC__ < 4 267 | // workaround for GCC 3: 268 | rhs[element.first.template as()] = element.second.template as(); 269 | #else 270 | rhs[element.first.as()] = element.second.as(); 271 | #endif 272 | return true; 273 | } 274 | }; 275 | 276 | // std::unordered_map 277 | template 278 | struct convert> { 279 | static Node encode(const std::unordered_map& rhs) { 280 | Node node(NodeType::Map); 281 | for (const auto& element : rhs) 282 | node.force_insert(element.first, element.second); 283 | return node; 284 | } 285 | 286 | static bool decode(const Node& node, std::unordered_map& rhs) { 287 | if (!node.IsMap()) 288 | return false; 289 | 290 | rhs.clear(); 291 | for (const auto& element : node) 292 | #if defined(__GNUC__) && __GNUC__ < 4 293 | // workaround for GCC 3: 294 | rhs[element.first.template as()] = element.second.template as(); 295 | #else 296 | rhs[element.first.as()] = element.second.as(); 297 | #endif 298 | return true; 299 | } 300 | }; 301 | 302 | // std::vector 303 | template 304 | struct convert> { 305 | static Node encode(const std::vector& rhs) { 306 | Node node(NodeType::Sequence); 307 | for (const auto& element : rhs) 308 | node.push_back(element); 309 | return node; 310 | } 311 | 312 | static bool decode(const Node& node, std::vector& rhs) { 313 | if (!node.IsSequence()) 314 | return false; 315 | 316 | rhs.clear(); 317 | for (const auto& element : node) 318 | #if defined(__GNUC__) && __GNUC__ < 4 319 | // workaround for GCC 3: 320 | rhs.push_back(element.template as()); 321 | #else 322 | rhs.push_back(element.as()); 323 | #endif 324 | return true; 325 | } 326 | }; 327 | 328 | // std::list 329 | template 330 | struct convert> { 331 | static Node encode(const std::list& rhs) { 332 | Node node(NodeType::Sequence); 333 | for (const auto& element : rhs) 334 | node.push_back(element); 335 | return node; 336 | } 337 | 338 | static bool decode(const Node& node, std::list& rhs) { 339 | if (!node.IsSequence()) 340 | return false; 341 | 342 | rhs.clear(); 343 | for (const auto& element : node) 344 | #if defined(__GNUC__) && __GNUC__ < 4 345 | // workaround for GCC 3: 346 | rhs.push_back(element.template as()); 347 | #else 348 | rhs.push_back(element.as()); 349 | #endif 350 | return true; 351 | } 352 | }; 353 | 354 | // std::array 355 | template 356 | struct convert> { 357 | static Node encode(const std::array& rhs) { 358 | Node node(NodeType::Sequence); 359 | for (const auto& element : rhs) { 360 | node.push_back(element); 361 | } 362 | return node; 363 | } 364 | 365 | static bool decode(const Node& node, std::array& rhs) { 366 | if (!isNodeValid(node)) { 367 | return false; 368 | } 369 | 370 | for (auto i = 0u; i < node.size(); ++i) { 371 | #if defined(__GNUC__) && __GNUC__ < 4 372 | // workaround for GCC 3: 373 | rhs[i] = node[i].template as(); 374 | #else 375 | rhs[i] = node[i].as(); 376 | #endif 377 | } 378 | return true; 379 | } 380 | 381 | private: 382 | static bool isNodeValid(const Node& node) { 383 | return node.IsSequence() && node.size() == N; 384 | } 385 | }; 386 | 387 | 388 | // std::valarray 389 | template 390 | struct convert> { 391 | static Node encode(const std::valarray& rhs) { 392 | Node node(NodeType::Sequence); 393 | for (const auto& element : rhs) { 394 | node.push_back(element); 395 | } 396 | return node; 397 | } 398 | 399 | static bool decode(const Node& node, std::valarray& rhs) { 400 | if (!node.IsSequence()) { 401 | return false; 402 | } 403 | 404 | rhs.resize(node.size()); 405 | for (auto i = 0u; i < node.size(); ++i) { 406 | #if defined(__GNUC__) && __GNUC__ < 4 407 | // workaround for GCC 3: 408 | rhs[i] = node[i].template as(); 409 | #else 410 | rhs[i] = node[i].as(); 411 | #endif 412 | } 413 | return true; 414 | } 415 | }; 416 | 417 | 418 | // std::pair 419 | template 420 | struct convert> { 421 | static Node encode(const std::pair& rhs) { 422 | Node node(NodeType::Sequence); 423 | node.push_back(rhs.first); 424 | node.push_back(rhs.second); 425 | return node; 426 | } 427 | 428 | static bool decode(const Node& node, std::pair& rhs) { 429 | if (!node.IsSequence()) 430 | return false; 431 | if (node.size() != 2) 432 | return false; 433 | 434 | #if defined(__GNUC__) && __GNUC__ < 4 435 | // workaround for GCC 3: 436 | rhs.first = node[0].template as(); 437 | #else 438 | rhs.first = node[0].as(); 439 | #endif 440 | #if defined(__GNUC__) && __GNUC__ < 4 441 | // workaround for GCC 3: 442 | rhs.second = node[1].template as(); 443 | #else 444 | rhs.second = node[1].as(); 445 | #endif 446 | return true; 447 | } 448 | }; 449 | 450 | // binary 451 | template <> 452 | struct convert { 453 | static Node encode(const Binary& rhs) { 454 | return Node(EncodeBase64(rhs.data(), rhs.size())); 455 | } 456 | 457 | static bool decode(const Node& node, Binary& rhs) { 458 | if (!node.IsScalar()) 459 | return false; 460 | 461 | std::vector data = DecodeBase64(node.Scalar()); 462 | if (data.empty() && !node.Scalar().empty()) 463 | return false; 464 | 465 | rhs.swap(data); 466 | return true; 467 | } 468 | }; 469 | } 470 | 471 | #endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 472 | --------------------------------------------------------------------------------