forked from SelfPrivacy/selfprivacy.org.app
Attempts at string escaping
parent
0bc3d9f31c
commit
f6508dfcad
|
@ -130,17 +130,34 @@ class HetznerApi extends ApiMap {
|
||||||
hostname = 'selfprivacy-server';
|
hostname = 'selfprivacy-server';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print("hostname: $hostname");
|
||||||
|
|
||||||
/// add ssh key when you need it: e.g. "ssh_keys":["kherel"]
|
/// add ssh key when you need it: e.g. "ssh_keys":["kherel"]
|
||||||
/// check the branch name, it could be "development" or "master".
|
/// check the branch name, it could be "development" or "master".
|
||||||
|
///
|
||||||
|
final userdataString = "#cloud-config\\nruncmd:\\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${escapeQuotes(rootUser.login)}' PASSWORD='${escapeQuotes(rootUser.password)}' CF_TOKEN=$cloudFlareKey DB_PASSWORD=${escapeQuotes(dbPassword)} API_TOKEN=$apiToken HOSTNAME=${escapeQuotes(hostname)} bash 2>&1 | tee /tmp/infect.log";
|
||||||
|
print(userdataString);
|
||||||
|
|
||||||
var data = jsonDecode(
|
final data = {
|
||||||
'''{"name":"$hostname","server_type":"cx11","start_after_create":false,"image":"ubuntu-20.04", "volumes":[$dbId], "networks":[], "user_data":"#cloud-config\\nruncmd:\\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${escapeSingleQuotes(rootUser.login)}' PASSWORD='${escapeSingleQuotes(rootUser.password)}' CF_TOKEN=$cloudFlareKey DB_PASSWORD=${escapeSingleQuotes(dbPassword)} API_TOKEN=$apiToken HOSTNAME=${escapeSingleQuotes(hostname)} bash 2>&1 | tee /tmp/infect.log","labels":{},"automount":true, "location": "fsn1"}''');
|
"name": hostname,
|
||||||
|
"server_type": "cx11",
|
||||||
|
"start_after_create": false,
|
||||||
|
"image": "ubuntu-20.04",
|
||||||
|
"volumes": [dbId],
|
||||||
|
"networks": [],
|
||||||
|
"user_data": userdataString,
|
||||||
|
"labels": {},
|
||||||
|
"automount": true,
|
||||||
|
"location": "fsn1"
|
||||||
|
};
|
||||||
|
print("Decoded data: $data");
|
||||||
|
|
||||||
Response serverCreateResponse = await client.post(
|
Response serverCreateResponse = await client.post(
|
||||||
'/servers',
|
'/servers',
|
||||||
data: data,
|
data: data,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
print(serverCreateResponse.data);
|
||||||
client.close();
|
client.close();
|
||||||
return HetznerServerDetails(
|
return HetznerServerDetails(
|
||||||
id: serverCreateResponse.data['server']['id'],
|
id: serverCreateResponse.data['server']['id'],
|
||||||
|
@ -240,7 +257,10 @@ class HetznerApi extends ApiMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String escapeSingleQuotes(String str) {
|
String escapeQuotes(String str) {
|
||||||
// replace all single quotes with escaped single quotes for bash strong quotes (i.e. '\'' )
|
// replace all single quotes with escaped single quotes for bash strong quotes (i.e. '\'' )
|
||||||
|
print("Escaping single quotes for bash: $str");
|
||||||
|
print("Escaping result: ${str.replaceAll(RegExp(r"'"), "'\\''")}");
|
||||||
|
// also escape all double quotes for json
|
||||||
return str.replaceAll(RegExp(r"'"), "'\\''");
|
return str.replaceAll(RegExp(r"'"), "'\\''");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue