feat: Add 2 and update 6 files
This commit is contained in:
74
source/src/commands/disable.cpp
Normal file
74
source/src/commands/disable.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "command_registry.hpp"
|
||||
#include "config.hpp"
|
||||
#include "servers.hpp"
|
||||
#include "utils/output.hpp"
|
||||
#include "shared_commands.hpp"
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
int disable_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> disable_name_list = {"disable"};
|
||||
|
||||
// Static registration
|
||||
struct DisableCommandRegister
|
||||
{
|
||||
DisableCommandRegister()
|
||||
{
|
||||
CommandRegistry::instance().register_command({disable_name_list,
|
||||
disable_handler,
|
||||
shared_commands::std_autocomplete,
|
||||
false, // hidden
|
||||
true, // requires_config
|
||||
false, // requires_install
|
||||
1, // min_args
|
||||
1, // max_args
|
||||
"disable SERVERNAME",
|
||||
"Disable interaction with a server while keeping all data intact",
|
||||
R"(
|
||||
|
||||
disable SERVERNAME Disables the specified server.
|
||||
|
||||
This command marks a server as disabled on your local machine.
|
||||
When disabled, dropshell will no longer:
|
||||
- Check the server status
|
||||
- Update services on the server
|
||||
- Interact with the server in any way
|
||||
|
||||
All data and configuration on the server remains intact.
|
||||
You can re-enable the server at any time using the 'enable' command.
|
||||
|
||||
Note: This setting is stored locally only and does not affect the server itself.
|
||||
)"});
|
||||
}
|
||||
} disable_command_register;
|
||||
|
||||
int disable_handler(const CommandContext &ctx)
|
||||
{
|
||||
std::string server_name = ctx.args[0];
|
||||
|
||||
// Check if server exists
|
||||
if (!server_exists(server_name))
|
||||
{
|
||||
error << "Server '" << server_name << "' does not exist" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check if already disabled
|
||||
if (gConfig().is_server_disabled(server_name))
|
||||
{
|
||||
info << "Server '" << server_name << "' is already disabled" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Disable the server
|
||||
gConfig().set_server_disabled(server_name, true);
|
||||
|
||||
info << "Server '" << server_name << "' has been disabled" << std::endl;
|
||||
info << "Dropshell will no longer check, update, or interact with this server" << std::endl;
|
||||
info << "Use 'dropshell enable " << server_name << "' to re-enable interaction" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
70
source/src/commands/enable.cpp
Normal file
70
source/src/commands/enable.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "command_registry.hpp"
|
||||
#include "config.hpp"
|
||||
#include "servers.hpp"
|
||||
#include "utils/output.hpp"
|
||||
#include "shared_commands.hpp"
|
||||
|
||||
namespace dropshell
|
||||
{
|
||||
int enable_handler(const CommandContext &ctx);
|
||||
|
||||
static std::vector<std::string> enable_name_list = {"enable"};
|
||||
|
||||
// Static registration
|
||||
struct EnableCommandRegister
|
||||
{
|
||||
EnableCommandRegister()
|
||||
{
|
||||
CommandRegistry::instance().register_command({enable_name_list,
|
||||
enable_handler,
|
||||
shared_commands::std_autocomplete,
|
||||
false, // hidden
|
||||
true, // requires_config
|
||||
false, // requires_install
|
||||
1, // min_args
|
||||
1, // max_args
|
||||
"enable SERVERNAME",
|
||||
"Re-enable interaction with a previously disabled server",
|
||||
R"(
|
||||
|
||||
enable SERVERNAME Re-enables the specified server.
|
||||
|
||||
This command removes a server from the disabled list, allowing
|
||||
dropshell to resume normal operations with the server, including:
|
||||
- Checking server status
|
||||
- Updating and managing services
|
||||
- All other server interactions
|
||||
|
||||
Note: This setting is stored locally only and does not affect the server itself.
|
||||
)"});
|
||||
}
|
||||
} enable_command_register;
|
||||
|
||||
int enable_handler(const CommandContext &ctx)
|
||||
{
|
||||
std::string server_name = ctx.args[0];
|
||||
|
||||
// Check if server exists
|
||||
if (!server_exists(server_name))
|
||||
{
|
||||
error << "Server '" << server_name << "' does not exist" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check if not disabled
|
||||
if (!gConfig().is_server_disabled(server_name))
|
||||
{
|
||||
info << "Server '" << server_name << "' is not disabled" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Enable the server
|
||||
gConfig().set_server_disabled(server_name, false);
|
||||
|
||||
info << "Server '" << server_name << "' has been enabled" << std::endl;
|
||||
info << "Dropshell will resume checking, updating, and interacting with this server" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace dropshell
|
@@ -466,6 +466,14 @@ complete -F _dropshell_completions ds
|
||||
|
||||
int install_server(const ServerConfig &server)
|
||||
{
|
||||
// Check if server is disabled
|
||||
if (gConfig().is_server_disabled(server.get_server_name()))
|
||||
{
|
||||
warning << "Server '" << server.get_server_name() << "' is disabled. Skipping installation." << std::endl;
|
||||
info << "Use 'dropshell enable " << server.get_server_name() << "' to re-enable this server." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// install the dropshell agent on the given server.
|
||||
maketitle("Installing dropshell agent on " + server.get_server_name(), sColour::INFO);
|
||||
|
||||
@@ -557,6 +565,14 @@ complete -F _dropshell_completions ds
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check if server is disabled
|
||||
if (gConfig().is_server_disabled(server))
|
||||
{
|
||||
warning << "Server '" << server << "' is disabled. Skipping installation." << std::endl;
|
||||
info << "Use 'dropshell enable " << server << "' to re-enable this server." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ServerConfig server_env(server);
|
||||
ASSERT(server_env.is_valid(), "Invalid server environment for " + server);
|
||||
if (safearg(ctx.args, 1) == "all")
|
||||
|
@@ -118,9 +118,12 @@ void list_servers() {
|
||||
std::string ports_used_str = "";
|
||||
std::set<int> ports_used;
|
||||
|
||||
// Check if server is disabled
|
||||
bool is_disabled = gConfig().is_server_disabled(sup.server.get_server_name());
|
||||
|
||||
// Check if server is online (with caching to avoid redundant checks for multiple users)
|
||||
bool is_online = false;
|
||||
{
|
||||
if (!is_disabled) {
|
||||
auto it = server_online_status.find(sup.server.get_server_name());
|
||||
if (it != server_online_status.end()) {
|
||||
is_online = it->second;
|
||||
@@ -133,8 +136,8 @@ void list_servers() {
|
||||
}
|
||||
}
|
||||
|
||||
// Only check service status if server is online
|
||||
if (is_online) {
|
||||
// Only check service status if server is online and not disabled
|
||||
if (is_online && !is_disabled) {
|
||||
std::map<std::string, shared_commands::ServiceStatus> status = shared_commands::get_all_services_status(sup.server.get_server_name(),sup.user.user);
|
||||
|
||||
for (const auto& [service_name, service_status] : status) {
|
||||
@@ -146,12 +149,14 @@ void list_servers() {
|
||||
ports_used_str += std::to_string(port) + " ";
|
||||
}
|
||||
|
||||
// Add red cross to address if server is offline
|
||||
// Add red cross to address if server is offline or disabled
|
||||
std::string address_display = sup.server.get_SSH_HOST();
|
||||
if (!is_online) {
|
||||
if (is_disabled) {
|
||||
address_display += " :disabled:";
|
||||
} else if (!is_online) {
|
||||
address_display += " :cross:";
|
||||
}
|
||||
|
||||
|
||||
// critical section
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(tp_mutex);
|
||||
|
@@ -44,6 +44,14 @@ namespace dropshell
|
||||
|
||||
bool start_service(const std::string &server, const std::string &service)
|
||||
{
|
||||
// Check if server is disabled
|
||||
if (gConfig().is_server_disabled(server))
|
||||
{
|
||||
warning << "Server '" << server << "' is disabled. Cannot start services." << std::endl;
|
||||
info << "Use 'dropshell enable " << server << "' to re-enable this server." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
ServerConfig server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
|
@@ -44,6 +44,14 @@ namespace dropshell
|
||||
|
||||
bool stop_service(const std::string &server, const std::string &service)
|
||||
{
|
||||
// Check if server is disabled
|
||||
if (gConfig().is_server_disabled(server))
|
||||
{
|
||||
warning << "Server '" << server << "' is disabled. Cannot stop services." << std::endl;
|
||||
info << "Use 'dropshell enable " << server << "' to re-enable this server." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
ServerConfig server_env(server);
|
||||
if (!server_env.is_valid())
|
||||
{
|
||||
|
Reference in New Issue
Block a user