This commit is contained in:
Your Name
2025-05-23 21:41:33 +12:00
parent 94f77994f0
commit 048345c636
21 changed files with 377 additions and 203 deletions

View File

@ -161,70 +161,69 @@ namespace localpath {
// |-- (other config files for specific server&service)
remotefile::remotefile(const std::string &server_name, const std::string &user) :
mServer_name(server_name), mUser(user) {}
namespace remotefile {
std::string service_env(const std::string &server_name, const std::string &service_name)
std::string remotefile::service_env(const std::string &service_name) const
{
return remotepath::service_config(server_name, service_name) + "/service.env";
return remotepath(mServer_name,mUser).service_config(service_name) + "/service.env";
}
}
namespace remotepath {
std::string DROPSHELL_DIR(const std::string &server_name)
remotepath::remotepath(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
std::string remotepath::DROPSHELL_DIR() const
{
return server_env_manager(server_name).get_DROPSHELL_DIR();
return server_env_manager(mServer_name).get_user_dir(mUser);
}
std::string services(const std::string &server_name)
std::string remotepath::services() const
{
std::string dsp = DROPSHELL_DIR(server_name);
std::string dsp = DROPSHELL_DIR();
return (dsp.empty() ? "" : (dsp + "/services"));
}
std::string service(const std::string &server_name, const std::string &service_name)
std::string remotepath::service(const std::string &service_name) const
{
std::string services_path = services(server_name);
std::string services_path = services();
return (services_path.empty() ? "" : (services_path + "/" + service_name));
}
std::string service_config(const std::string &server_name, const std::string &service_name)
std::string remotepath::service_config(const std::string &service_name) const
{
std::string service_path = service(server_name, service_name);
std::string service_path = service(service_name);
return (service_path.empty() ? "" : (service_path + "/config"));
}
std::string service_template(const std::string &server_name, const std::string &service_name)
std::string remotepath::service_template(const std::string &service_name) const
{
std::string service_path = service(server_name, service_name);
std::string service_path = service(service_name);
return (service_path.empty() ? "" : (service_path + "/template"));
}
std::string backups(const std::string &server_name)
std::string remotepath::backups() const
{
std::string dsp = DROPSHELL_DIR(server_name);
std::string dsp = DROPSHELL_DIR();
return (dsp.empty() ? "" : (dsp + "/backups"));
}
std::string temp_files(const std::string &server_name)
std::string remotepath::temp_files() const
{
std::string dsp = DROPSHELL_DIR(server_name);
std::string dsp = DROPSHELL_DIR();
return (dsp.empty() ? "" : (dsp + "/temp_files"));
}
std::string agent(const std::string &server_name)
std::string remotepath::agent() const
{
std::string dsp = DROPSHELL_DIR(server_name);
std::string dsp = DROPSHELL_DIR();
return (dsp.empty() ? "" : (dsp + "/agent"));
}
std::string service_env(const std::string &server_name, const std::string &service_name)
{
std::string service_path = service_config(server_name, service_name);
return (service_path.empty() ? "" : (service_path + "/service.env"));
}
} // namespace remotepath
// std::string remotepath::service_env(const std::string &service_name) const
// {
// std::string service_path = service_config(service_name);
// return (service_path.empty() ? "" : (service_path + "/service.env"));
// }
// ------------------------------------------------------------------------------------------

View File

@ -99,20 +99,30 @@ namespace dropshell {
// |-- .template_info.env
// |-- (other config files for specific server&service)
namespace remotefile {
std::string service_env(const std::string &server_name, const std::string &service_name);
} // namespace remotefile
class remotefile {
public:
remotefile(const std::string &server_name, const std::string &user);
std::string service_env(const std::string &service_name) const;
private:
std::string mServer_name;
std::string mUser;
};
namespace remotepath {
std::string DROPSHELL_DIR(const std::string &server_name);
std::string services(const std::string &server_name);
std::string service(const std::string &server_name, const std::string &service_name);
std::string service_config(const std::string &server_name, const std::string &service_name);
std::string service_template(const std::string &server_name, const std::string &service_name);
std::string backups(const std::string &server_name);
std::string temp_files(const std::string &server_name);
std::string agent(const std::string &server_name);
} // namespace remotepath
class remotepath {
public:
remotepath(const std::string &server_name, const std::string &user);
std::string DROPSHELL_DIR() const;
std::string services() const;
std::string service(const std::string &service_name) const;
std::string service_config(const std::string &service_name) const;
std::string service_template(const std::string &service_name) const;
std::string backups() const;
std::string temp_files() const;
std::string agent() const;
private:
std::string mServer_name;
std::string mUser;
};
//------------------------------------------------------------------------------------------------
// utility functions

View File

@ -171,7 +171,7 @@ namespace dropshell
std::string remote_bb64_path;
if (!hasFlag(mode, cMode::NoBB64))
remote_bb64_path = remotepath::agent(ssh_info.server_ID) + "/bb64";
remote_bb64_path = remotepath(ssh_info.server_ID, ssh_info.user).agent() + "/bb64";
bool rval = execute_local_command(
"", // local directory to run in

View File

@ -41,12 +41,13 @@ bool execute_ssh_command(const sSSHInfo & ssh_info, const sCommand & remote_comm
// class to hold a command to run on the remote server.
class sCommand {
public:
sCommand(std::string directory_to_run_in, std::string command_to_run, const std::map<std::string, std::string> & env_vars) :
mDir(directory_to_run_in), mCmd(command_to_run), mVars(env_vars) {}
sCommand(std::string directory_to_run_in, std::string command_to_run, const std::map<std::string, std::string> & env_vars, bool requires_root = false) :
mDir(directory_to_run_in), mCmd(command_to_run), mVars(env_vars), mRequiresRoot(requires_root) {}
std::string get_directory_to_run_in() const { return mDir; }
std::string get_command_to_run() const { return mCmd; }
const std::map<std::string, std::string>& get_env_vars() const { return mVars; }
bool requires_root() const { return mRequiresRoot; }
void add_env_var(const std::string& key, const std::string& value) { mVars[key] = value; }
@ -58,6 +59,7 @@ class sCommand {
std::string makesafecmd(std::string bb64path, const std::string& command) const;
private:
bool mRequiresRoot;
std::string mDir;
std::string mCmd;
std::map<std::string, std::string> mVars;

View File

@ -9,6 +9,7 @@
#include <random>
#include <sys/ioctl.h>
#include <unistd.h>
#include <cctype>
namespace dropshell {
@ -432,4 +433,16 @@ std::string get_line_wrap(std::string &src, int maxchars)
return remove_return(out) + '\n';
}
std::string tolower(const std::string& str) {
if (str.empty()) return str;
std::string result;
result.reserve(str.size()); // Pre-allocate space for efficiency
for (unsigned char c : str) {
result.push_back(std::tolower(c));
}
return result;
}
} // namespace dropshell

View File

@ -59,4 +59,6 @@ int get_console_width();
std::string get_line_wrap(std::string & src, int maxchars);
std::string tolower(const std::string& str);
} // namespace dropshell