Cleaned the code, added the 'key' option to the config file (so you

can give a default ssh key) and added it to the manpages.
master
qorg11 2022-07-08 20:49:19 +02:00
parent 2daedef710
commit bfcc3b9d94
5 changed files with 40 additions and 15 deletions

View File

@ -8,11 +8,11 @@ void
print_config()
{
puts("Current configuration:");
printf("Server: %s\n",server);
printf("Server: %s\n", server);
if(socks_proxy_flag)
printf("Socks proxy url: %s",socks_proxy_url);
printf("Socks proxy url: %s", socks_proxy_url);
if(http_proxy_flag)
printf("HTTP proxy url: %s",http_proxy_url);
printf("HTTP proxy url: %s", http_proxy_url);
if(silent_flag)
puts("Silent: true");
else
@ -39,6 +39,7 @@ parse_config_file(FILE *config)
config_read(&runtime_config, config);
config_setting_t *cur;
cur = config_lookup(&runtime_config, "server");
if(config != NULL) {
if(cur != NULL)
server = (char *)config_setting_get_string(cur);
@ -63,5 +64,8 @@ parse_config_file(FILE *config)
cur = config_lookup(&runtime_config, "force_ipv4");
if(cur != NULL)
ipv4_flag = config_setting_get_bool(cur);
cur = config_lookup(&runtime_config, "key");
if(cur != NULL)
ssh_key_path = (char *)config_setting_get_string(cur);
}
}

View File

@ -27,5 +27,5 @@ extern bool ipv6_flag;
extern bool ipv4_flag;
extern bool silent_flag;
extern config_t runtime_config;
extern char *ssh_key_path;
#endif /* OPTIONS_H */

View File

@ -7,11 +7,12 @@
.Sh SYPNOSIS
sakisafecli https://sakisafe.tld FILE
sakisafecli [https]://sakisafe.tld FILE
.Sh DESCRIPTION
sakisafecli is a file uploader. Intended for sakisafe, but also works
for 0x0.st, 0xff.i2p, i.kalli.st and probably others.
for 0x0.st, 0xff.i2p, i.kalli.st and probably others. It also supports
transfer via scp.
.Sh OPTIONS
.Sy --http_proxy
@ -36,6 +37,11 @@ server.
.Sy -C
Print the current settings.
.Sy --key
path to the private SSH key to use. Only useful when using the
.Sy scp://
protocol.
.Sh BUGS
Of course.
.Sh HISTORY

View File

@ -21,7 +21,7 @@ bool ipv6_flag = false, ipv4_flag = false, http_proxy_flag = false,
socks_proxy_flag = false, silent_flag = false, paste_flag = false;
char *http_proxy_url, *socks_proxy_url;
char *ssh_key_path = NULL;
config_t runtime_config;
char *server = "https://lainsafe.delegao.moe";
@ -147,8 +147,7 @@ main(int argc, char **argv)
print_config();
return 0;
case 'k':
curl_easy_setopt(
easy_handle, CURLOPT_SSH_PRIVATE_KEYFILE, optarg);
ssh_key_path = optarg;
break;
default:
print_usage();
@ -170,6 +169,12 @@ main(int argc, char **argv)
int protocol = get_protocol(server);
/* If using SCP, set the ssh key */
if(protocol == CURLPROTO_SCP && ssh_key_path != NULL) {
curl_easy_setopt(
easy_handle, CURLOPT_SSH_PRIVATE_KEYFILE, ssh_key_path);
}
/* Proxy options */
if(socks_proxy_flag && http_proxy_flag) {
@ -205,8 +210,6 @@ main(int argc, char **argv)
/* Process HTTP uploads */
printf("%d\n", protocol);
if(protocol == CURLPROTO_HTTP || protocol == CURLPROTO_HTTPS) {
curl_mimepart *file_data;
file_data = curl_mime_addpart(mime);
@ -228,17 +231,23 @@ main(int argc, char **argv)
puts(buffer);
if(protocol == CURLPROTO_HTTP)
curl_mime_free(mime);
} else if(protocol == CURLPROTO_SCP) {
}
/* Process SCP uploads */
else if(protocol == CURLPROTO_SCP) {
char path[256];
char *filename = argv[optind];
curl_easy_setopt(easy_handle, CURLOPT_UPLOAD, true);
FILE *fp = fopen(argv[optind], "r");
FILE *fp = fopen(filename, "r");
struct stat st;
stat(argv[optind], &st);
snprintf(path, 256, "%s/%s", server, filename);
curl_easy_setopt(easy_handle, CURLOPT_READDATA, fp);
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag);
curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress);
curl_easy_setopt(
easy_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)st.st_size);
printf("%d\n", curl_easy_perform(easy_handle));
curl_easy_setopt(easy_handle, CURLOPT_URL, path);
curl_easy_perform(easy_handle);
} else {
puts("Unsupported protocol");
return -1;
@ -246,7 +255,6 @@ main(int argc, char **argv)
if(!silent_flag)
putchar('\n');
curl_easy_cleanup(easy_handle);
free(buffer);

View File

@ -39,11 +39,18 @@ Force an IPv6 connection. Cannot be used with
.Sy force_ipv4 (boolean)
Force an IPv4 connection. Cannot be used with
.Sy force_ipv6
.Sy key
Path to the private ssh key used to connect to a server using the
.Sy scp
protocol.
.Sh FILES
.Bl -tag -width $HOME/.sakisafeclirc -compact
.It Pa $HOME/.sakisafeclirc
configuration file.
.Sh EXAMPLE
This example sets the default server to