-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProxyCommand.cpp
More file actions
138 lines (115 loc) · 3.55 KB
/
Copy pathProxyCommand.cpp
File metadata and controls
138 lines (115 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
*
* @file ProxyCommand.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira. All rights reserved.
* https://github.com/vixcpp/vix
* Use of this source code is governed by a MIT license
* that can be found in the License file.
*
* Vix.cpp
*/
#include <vix/cli/commands/ProxyCommand.hpp>
#include <vix/cli/commands/proxy/NginxCertbot.hpp>
#include <vix/cli/commands/proxy/NginxChecker.hpp>
#include <vix/cli/commands/proxy/NginxGenerator.hpp>
#include <vix/cli/commands/proxy/NginxOutput.hpp>
#include <vix/cli/commands/proxy/ProxyConfig.hpp>
#include <iostream>
#include <string>
#include <vector>
namespace vix::commands
{
namespace
{
#ifdef __linux__
int nginx_help()
{
std::cout
<< "Usage:\n"
<< " vix proxy nginx <command>\n\n"
<< "Commands:\n"
<< " init Generate, install and enable an Nginx config\n"
<< " check Validate the installed Nginx proxy config\n"
<< " reload Validate and reload Nginx\n"
<< " certbot Issue or renew a Let's Encrypt certificate\n\n"
<< "Examples:\n"
<< " vix proxy nginx init\n"
<< " vix proxy nginx check\n"
<< " vix proxy nginx reload\n"
<< " vix proxy nginx certbot\n";
return 0;
}
int run_nginx(const std::vector<std::string> &args)
{
if (args.empty() || args[0] == "-h" || args[0] == "--help")
return nginx_help();
const auto cfg = proxy::load_nginx_proxy_config();
const std::string action = args[0];
if (action == "init")
return proxy::nginx_generator::init(cfg);
if (action == "check")
return proxy::nginx_checker::check(cfg);
if (action == "reload")
return proxy::nginx_checker::reload(cfg);
if (action == "certbot")
return proxy::nginx_certbot::run(cfg);
proxy::nginx_output::error(
std::cerr,
"unknown nginx proxy command: " + action);
proxy::nginx_output::fix(
std::cerr,
"vix proxy nginx --help");
return 1;
}
#endif
}
int ProxyCommand::run(const std::vector<std::string> &args)
{
#ifndef __linux__
(void)args;
proxy::nginx_output::error(
std::cerr,
"vix proxy is currently supported on Linux only.");
return 1;
#else
if (args.empty() || args[0] == "-h" || args[0] == "--help")
return help();
const std::string provider = args[0];
if (provider == "nginx")
{
std::vector<std::string> rest;
if (args.size() > 1)
rest.assign(args.begin() + 1, args.end());
return run_nginx(rest);
}
proxy::nginx_output::error(
std::cerr,
"unknown proxy provider: " + provider);
proxy::nginx_output::fix(
std::cerr,
"vix proxy nginx --help");
return 1;
#endif
}
int ProxyCommand::help()
{
std::cout
<< "Usage:\n"
<< " vix proxy <provider> <command>\n\n"
<< "Providers:\n"
<< " nginx Manage Nginx reverse proxy config\n\n"
<< "Commands:\n"
<< " nginx init Generate, install and enable an Nginx config\n"
<< " nginx check Validate the installed Nginx proxy config\n"
<< " nginx reload Validate and reload Nginx\n"
<< " nginx certbot Issue or renew a Let's Encrypt certificate\n\n"
<< "Examples:\n"
<< " vix proxy nginx init\n"
<< " vix proxy nginx check\n"
<< " vix proxy nginx reload\n"
<< " vix proxy nginx certbot\n";
return 0;
}
}