mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
Replaced original forked version with a piped one. Original version for some reason resulted in incomplete file transfer. This works better. Just needs to be optimized.
This commit is contained in:
parent
34d2fed9d2
commit
100ada27f8
1 changed files with 17 additions and 21 deletions
|
|
@ -571,7 +571,7 @@ main_upload(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
static int exec_command(const char *cmd, char **out){
|
static int exec_command(const char *cmd, char **out){
|
||||||
FILE *fd;
|
FILE *fd;
|
||||||
int buffer_size = 4096;
|
int buffer_size = 4096;
|
||||||
|
|
@ -594,18 +594,6 @@ static int exec_command(const char *cmd, char **out){
|
||||||
}
|
}
|
||||||
*out = data;
|
*out = data;
|
||||||
return (int)(pdata - data);
|
return (int)(pdata - data);
|
||||||
}*/
|
|
||||||
|
|
||||||
static void run_child(const char *cmd){
|
|
||||||
FILE *fd;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
if ((fd = popen(cmd, "r"))) {
|
|
||||||
while((c = fgetc(fd)) != EOF){
|
|
||||||
putc(c, stdout);
|
|
||||||
}
|
|
||||||
pclose(fd);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -618,9 +606,9 @@ main_backup(int argc, char **argv)
|
||||||
char buf[4096];*/
|
char buf[4096];*/
|
||||||
char datestr[16] = { 0 };
|
char datestr[16] = { 0 };
|
||||||
char hostname[64] = { 0 };
|
char hostname[64] = { 0 };
|
||||||
char *fields[] = { "sessionid", NULL };
|
char *fields[] = { "sessionid", NULL, "password", NULL };
|
||||||
|
|
||||||
if (!postdecode(fields, 1) || !session_access(fields[1], "backup", "read"))
|
if (!postdecode(fields, 2) || !session_access(fields[1], "backup", "read"))
|
||||||
return failure(0, "Backup permission denied");
|
return failure(0, "Backup permission denied");
|
||||||
|
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
|
|
@ -632,19 +620,27 @@ main_backup(int argc, char **argv)
|
||||||
printf("Status: 200 OK\r\n");
|
printf("Status: 200 OK\r\n");
|
||||||
|
|
||||||
char cmd[256];
|
char cmd[256];
|
||||||
|
char *data;
|
||||||
|
|
||||||
if(fields[3]){
|
if(fields[3]){
|
||||||
snprintf(cmd, sizeof(cmd), "sysupgrade --create-backup - --password %s", fields[3]);
|
snprintf(cmd, sizeof(cmd), "sysupgrade --create-backup - --password %s", fields[3]);
|
||||||
} else {
|
} else {
|
||||||
snprintf(cmd, sizeof(cmd), "sysupgrade --create-backup -");
|
snprintf(cmd, sizeof(cmd), "sysupgrade --create-backup -");
|
||||||
}
|
}
|
||||||
|
int size = exec_command(cmd, &data);
|
||||||
|
if(size){
|
||||||
|
printf("Content-Type: application/x-targz\r\n");
|
||||||
|
printf("Content-Disposition: attachment; "
|
||||||
|
"filename=\"backup-%s-%s.tar.gz\"\r\n\r\n", hostname, datestr);
|
||||||
|
|
||||||
printf("Content-Type: application/x-targz\r\n");
|
fwrite(data, size, 1, stdout);
|
||||||
printf("Content-Disposition: attachment; "
|
fflush(stdout);
|
||||||
"filename=\"backup-%s-%s.tar.gz\"\r\n\r\n", hostname, datestr);
|
free(data);
|
||||||
|
} else {
|
||||||
run_child(cmd);
|
// TODO: make sure that we return some kind of error code so we can show it in the gui.
|
||||||
|
// otherwise the form post just silently fails without showing this message!
|
||||||
|
printf("No data!\n");
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
if (pipe(fds))
|
if (pipe(fds))
|
||||||
return failure(errno, "Failed to spawn pipe");
|
return failure(errno, "Failed to spawn pipe");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue