This commit is contained in:
j
2025-12-30 09:31:21 +13:00
parent 0917e1e3f3
commit 4bcbf12088
6 changed files with 79 additions and 59 deletions

View File

@@ -170,6 +170,11 @@ namespace dropshell
return remotepath(mServer_name, mUser).DROPSHELL_DIR() + "/" + filenames::server_json;
}
std::string remotefile::server_info_env()
{
return remotepath(mServer_name, mUser).DROPSHELL_DIR() + "/" + filenames::server_info_env;
}
remotepath::remotepath(const std::string &server_name, const std::string &user) : mServer_name(server_name), mUser(user) {}
std::string remotepath::DROPSHELL_DIR() const

View File

@@ -42,6 +42,7 @@ namespace dropshell {
// |-- (...other config files for specific server&service...)
namespace filenames {
static const std::string server_info_env = "server_info.env";
static const std::string template_info_env = "template_info.env";
static const std::string service_env = "service.env";
static const std::string readme = "README.txt";
@@ -80,6 +81,7 @@ namespace dropshell {
//------------------------------------------------------------------------------------------------
// remote paths
// DROPSHELL_DIR
// |-- server_info.env
// |-- server.json
// |-- backups
// |-- temp_files
@@ -102,6 +104,7 @@ namespace dropshell {
remotefile(const std::string &server_name, const std::string &user);
std::string service_env(const std::string &service_name) const;
std::string server_json();
std::string server_info_env();
private:
std::string mServer_name;
std::string mUser;

View File

@@ -235,52 +235,45 @@ namespace dropshell
return "";
// need to construct to change directory and set environment variables
std::string cmdstr;
if (!bb64path.empty())
{
if (!mDir.empty())
cmdstr += "cd " + quote(mDir) + " && ";
if (!mVars.empty())
{
// Export variables so they're available for expansion in the command
for (const auto &env_var : mVars)
{
// Basic sanity check - skip invalid variable names
if (!is_valid_env_var_name(env_var.first))
{
error << "Skipping invalid environment variable name: " << env_var.first << std::endl;
continue;
}
// Very basic check for completely broken values that could break the command
// We still use quote() for proper escaping, but warn about suspicious values
const std::string &value = env_var.second;
if (value.find('\0') != std::string::npos)
{
error << "Skipping environment variable with null byte: " << env_var.first << std::endl;
continue;
}
cmdstr += "export " + env_var.first + "=" + quote(dequote(trim(value))) + " && ";
}
}
cmdstr += mCmd;
cmdstr = makesafecmd(bb64path, cmdstr);
}
else
if (bb64path.empty())
{ // raw! bootstrapping only.
ASSERT(mVars.empty(), "Bootstrapping command must not have environment variables");
if (!mDir.empty())
cmdstr += mDir + "/" + mCmd;
else
cmdstr += mCmd;
return (mDir.empty() ? mCmd : mDir + "/" + mCmd);
}
return cmdstr;
std::string cmdstr;
if (!mDir.empty())
cmdstr += "cd " + quote(mDir) + " && ";
if (!mVars.empty())
{
// Export variables so they're available for expansion in the command
for (const auto &env_var : mVars)
{
// Basic sanity check - skip invalid variable names
if (!is_valid_env_var_name(env_var.first))
{
error << "Skipping invalid environment variable name: " << env_var.first << std::endl;
continue;
}
// Very basic check for completely broken values that could break the command
// We still use quote() for proper escaping, but warn about suspicious values
const std::string &value = env_var.second;
if (value.find('\0') != std::string::npos)
{
error << "Skipping environment variable with null byte: " << env_var.first << std::endl;
continue;
}
cmdstr += "export " + env_var.first + "=" + quote(dequote(trim(value))) + " && ";
}
}
cmdstr += mCmd;
return makesafecmd(bb64path, cmdstr);
}
bool sSSHInfo::valid() const