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.
This commit is contained in:
parent
2daedef710
commit
bfcc3b9d94
5 changed files with 40 additions and 15 deletions
|
@ -8,11 +8,11 @@ void
|
||||||
print_config()
|
print_config()
|
||||||
{
|
{
|
||||||
puts("Current configuration:");
|
puts("Current configuration:");
|
||||||
printf("Server: %s\n",server);
|
printf("Server: %s\n", server);
|
||||||
if(socks_proxy_flag)
|
if(socks_proxy_flag)
|
||||||
printf("Socks proxy url: %s",socks_proxy_url);
|
printf("Socks proxy url: %s", socks_proxy_url);
|
||||||
if(http_proxy_flag)
|
if(http_proxy_flag)
|
||||||
printf("HTTP proxy url: %s",http_proxy_url);
|
printf("HTTP proxy url: %s", http_proxy_url);
|
||||||
if(silent_flag)
|
if(silent_flag)
|
||||||
puts("Silent: true");
|
puts("Silent: true");
|
||||||
else
|
else
|
||||||
|
@ -39,6 +39,7 @@ parse_config_file(FILE *config)
|
||||||
config_read(&runtime_config, config);
|
config_read(&runtime_config, config);
|
||||||
config_setting_t *cur;
|
config_setting_t *cur;
|
||||||
cur = config_lookup(&runtime_config, "server");
|
cur = config_lookup(&runtime_config, "server");
|
||||||
|
|
||||||
if(config != NULL) {
|
if(config != NULL) {
|
||||||
if(cur != NULL)
|
if(cur != NULL)
|
||||||
server = (char *)config_setting_get_string(cur);
|
server = (char *)config_setting_get_string(cur);
|
||||||
|
@ -63,5 +64,8 @@ parse_config_file(FILE *config)
|
||||||
cur = config_lookup(&runtime_config, "force_ipv4");
|
cur = config_lookup(&runtime_config, "force_ipv4");
|
||||||
if(cur != NULL)
|
if(cur != NULL)
|
||||||
ipv4_flag = config_setting_get_bool(cur);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,5 +27,5 @@ extern bool ipv6_flag;
|
||||||
extern bool ipv4_flag;
|
extern bool ipv4_flag;
|
||||||
extern bool silent_flag;
|
extern bool silent_flag;
|
||||||
extern config_t runtime_config;
|
extern config_t runtime_config;
|
||||||
|
extern char *ssh_key_path;
|
||||||
#endif /* OPTIONS_H */
|
#endif /* OPTIONS_H */
|
||||||
|
|
|
@ -7,11 +7,12 @@
|
||||||
|
|
||||||
.Sh SYPNOSIS
|
.Sh SYPNOSIS
|
||||||
|
|
||||||
sakisafecli https://sakisafe.tld FILE
|
sakisafecli [https]://sakisafe.tld FILE
|
||||||
|
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
sakisafecli is a file uploader. Intended for sakisafe, but also works
|
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
|
.Sh OPTIONS
|
||||||
|
|
||||||
.Sy --http_proxy
|
.Sy --http_proxy
|
||||||
|
@ -36,6 +37,11 @@ server.
|
||||||
.Sy -C
|
.Sy -C
|
||||||
Print the current settings.
|
Print the current settings.
|
||||||
|
|
||||||
|
.Sy --key
|
||||||
|
path to the private SSH key to use. Only useful when using the
|
||||||
|
.Sy scp://
|
||||||
|
protocol.
|
||||||
|
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
Of course.
|
Of course.
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
|
|
|
@ -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;
|
socks_proxy_flag = false, silent_flag = false, paste_flag = false;
|
||||||
|
|
||||||
char *http_proxy_url, *socks_proxy_url;
|
char *http_proxy_url, *socks_proxy_url;
|
||||||
|
char *ssh_key_path = NULL;
|
||||||
config_t runtime_config;
|
config_t runtime_config;
|
||||||
|
|
||||||
char *server = "https://lainsafe.delegao.moe";
|
char *server = "https://lainsafe.delegao.moe";
|
||||||
|
@ -147,8 +147,7 @@ main(int argc, char **argv)
|
||||||
print_config();
|
print_config();
|
||||||
return 0;
|
return 0;
|
||||||
case 'k':
|
case 'k':
|
||||||
curl_easy_setopt(
|
ssh_key_path = optarg;
|
||||||
easy_handle, CURLOPT_SSH_PRIVATE_KEYFILE, optarg);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage();
|
print_usage();
|
||||||
|
@ -170,6 +169,12 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
int protocol = get_protocol(server);
|
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 */
|
/* Proxy options */
|
||||||
|
|
||||||
if(socks_proxy_flag && http_proxy_flag) {
|
if(socks_proxy_flag && http_proxy_flag) {
|
||||||
|
@ -205,8 +210,6 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
/* Process HTTP uploads */
|
/* Process HTTP uploads */
|
||||||
|
|
||||||
printf("%d\n", protocol);
|
|
||||||
|
|
||||||
if(protocol == CURLPROTO_HTTP || protocol == CURLPROTO_HTTPS) {
|
if(protocol == CURLPROTO_HTTP || protocol == CURLPROTO_HTTPS) {
|
||||||
curl_mimepart *file_data;
|
curl_mimepart *file_data;
|
||||||
file_data = curl_mime_addpart(mime);
|
file_data = curl_mime_addpart(mime);
|
||||||
|
@ -228,17 +231,23 @@ main(int argc, char **argv)
|
||||||
puts(buffer);
|
puts(buffer);
|
||||||
if(protocol == CURLPROTO_HTTP)
|
if(protocol == CURLPROTO_HTTP)
|
||||||
curl_mime_free(mime);
|
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);
|
curl_easy_setopt(easy_handle, CURLOPT_UPLOAD, true);
|
||||||
FILE *fp = fopen(argv[optind], "r");
|
FILE *fp = fopen(filename, "r");
|
||||||
struct stat st;
|
struct stat st;
|
||||||
stat(argv[optind], &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_READDATA, fp);
|
||||||
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag);
|
curl_easy_setopt(easy_handle, CURLOPT_NOPROGRESS, silent_flag);
|
||||||
curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress);
|
curl_easy_setopt(easy_handle, CURLOPT_PROGRESSFUNCTION, progress);
|
||||||
curl_easy_setopt(
|
curl_easy_setopt(
|
||||||
easy_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)st.st_size);
|
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 {
|
} else {
|
||||||
puts("Unsupported protocol");
|
puts("Unsupported protocol");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -246,7 +255,6 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if(!silent_flag)
|
if(!silent_flag)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
|
||||||
curl_easy_cleanup(easy_handle);
|
curl_easy_cleanup(easy_handle);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
|
@ -39,11 +39,18 @@ Force an IPv6 connection. Cannot be used with
|
||||||
.Sy force_ipv4 (boolean)
|
.Sy force_ipv4 (boolean)
|
||||||
Force an IPv4 connection. Cannot be used with
|
Force an IPv4 connection. Cannot be used with
|
||||||
.Sy force_ipv6
|
.Sy force_ipv6
|
||||||
|
|
||||||
|
.Sy key
|
||||||
|
Path to the private ssh key used to connect to a server using the
|
||||||
|
.Sy scp
|
||||||
|
protocol.
|
||||||
|
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
|
|
||||||
.Bl -tag -width $HOME/.sakisafeclirc -compact
|
.Bl -tag -width $HOME/.sakisafeclirc -compact
|
||||||
.It Pa $HOME/.sakisafeclirc
|
.It Pa $HOME/.sakisafeclirc
|
||||||
configuration file.
|
configuration file.
|
||||||
|
|
||||||
.Sh EXAMPLE
|
.Sh EXAMPLE
|
||||||
|
|
||||||
This example sets the default server to
|
This example sets the default server to
|
||||||
|
|
Loading…
Add table
Reference in a new issue