2
** Routines to upload files to the local filesystem.
3
** Created by: Rick Mallett, Carleton University
4
** Report problems to rmallett@ccs.carleton.ca
5
** Modified 15-Dec-95 George Lindholm (lindholm@ucs.ubc.ca):
6
** Reread the upload menu page every time, in case the "upload" directory
7
** has changed (make the current directory that for the upload process).
8
** Prompt for the upload file name if there is no "%s" in the command
9
** string. Most protocols allow the user to specify the file name
10
** from the client side. Xmodem appears to be the only that can't
11
** figure out the filename from the transfer data so it needs the
12
** information from lynx (or an upload script which prompts for it).
13
** On the other hand, zmodem aborts when you give it a filename on
14
** the command line (great way of bypassing the nodotfile code :=( ).
23
#include <LYGlobalDefs.h>
24
#include <LYStrings.h>
26
#include <LYGetFile.h>
33
#define SUBDIR_COMMAND "cd %s ; "
36
* LYUpload uploads a file to a given location using a
37
* specified upload method. It parses an incoming link
39
* LYNXDIRED://UPLOAD=<#>/TO=<STRING>
41
PUBLIC int LYUpload ARGS1(
44
char *method, *directory;
48
char tmpbuf[LY_MAXPATH];
49
char *filename = NULL;
50
lynx_list_item_type *upload_command = 0;
51
char *the_command = 0;
54
* Use configured upload commands.
56
if((directory = strstr(line, "TO=")) == NULL)
58
*(directory - 1) = '\0';
59
/* go past "Directory=" */
62
if((method = strstr(line, "UPLOAD=")) == NULL)
68
method_number = atoi(method);
70
for (count = 0, upload_command = uploaders; count < method_number;
71
count++, upload_command = upload_command->next)
75
* Parsed out the Method and the Location?
77
if (upload_command->command == NULL) {
78
HTAlert(gettext("ERROR! - upload command is misconfigured"));
83
* Care about the local name?
85
if (HTCountCommandArgs (upload_command->command)) {
87
* Commands have the form "command %s [etc]"
88
* where %s is the filename.
90
_statusline(FILENAME_PROMPT);
93
if (LYgetstr(tmpbuf, VISIBLE, sizeof(tmpbuf), NORECALL) < 0)
99
if (strstr(tmpbuf, "../") != NULL) {
100
HTAlert(gettext("Illegal redirection \"../\" found! Request ignored."));
102
} else if (strchr(tmpbuf, '/') != NULL) {
103
HTAlert(gettext("Illegal character \"/\" found! Request ignored."));
105
} else if (tmpbuf[0] == '~') {
106
HTAlert(gettext("Illegal redirection using \"~\" found! Request ignored."));
109
HTSprintf0(&filename, "%s/%s", directory, tmpbuf);
112
if (LYIsPipeCommand(filename)) {
113
HTAlert(CANNOT_WRITE_TO_FILE);
114
_statusline(NEW_FILENAME_PROMPT);
118
switch (LYValidateOutput(filename)) {
128
* See if we can write to it.
130
CTRACE((tfp, "LYUpload: filename is %s", filename));
132
if (! LYCanWriteFile(filename)) {
136
HTAddParam(&the_upload, upload_command->command, 1, filename);
137
HTEndParam(&the_upload, upload_command->command, 1);
138
} else { /* No substitution, no changes */
139
StrAllocCopy(the_upload, upload_command->command);
142
HTAddParam(&the_command, SUBDIR_COMMAND, 1, directory);
143
HTEndParam(&the_command, SUBDIR_COMMAND, 1);
144
StrAllocCat(the_command, the_upload);
146
CTRACE((tfp, "command: %s\n", the_command));
149
LYSystem(the_command);
154
#if defined(MULTI_USER_UNIX)
156
chmod(filename, HIDE_CHMOD);
163
HTAlert(gettext("Unable to upload file."));
167
HTInfoMsg(CANCELLING);
172
* LYUpload_options writes out the current upload choices to a
173
* file so that the user can select printers in the same way that
174
* they select all other links. Upload links look like:
175
* LYNXDIRED://UPLOAD=<#>/TO=<STRING>
177
PUBLIC int LYUpload_options ARGS2(
181
static char tempfile[LY_MAXPATH];
183
lynx_list_item_type *cur_upload;
185
static char curloc[LY_MAXPATH];
188
if ((fp0 = InternalPageFP(tempfile, TRUE)) == 0)
192
strcpy(curloc, "/sys$login");
194
cp = HTfullURL_toFile(directory);
196
LYTrimPathSep(curloc);
200
LYLocalFileToURL(newfile, tempfile);
201
LYRegisterUIPage(*newfile, UIP_UPLOAD_OPTIONS);
203
BeginInternalPage(fp0, UPLOAD_OPTIONS_TITLE, UPLOAD_OPTIONS_HELP);
205
fprintf(fp0, "<pre>\n");
206
fprintf(fp0, " <em>%s</em> %s\n", gettext("Upload To:"), curloc);
207
fprintf(fp0, "\n%s\n", gettext("Upload options:"));
209
if (uploaders != NULL) {
210
for (count = 0, cur_upload = uploaders;
212
cur_upload = cur_upload->next, count++) {
213
fprintf(fp0, " <a href=\"LYNXDIRED://UPLOAD=%d/TO=%s\">",
215
fprintf(fp0, (cur_upload->name ?
216
cur_upload->name : gettext("No Name Given")));
217
fprintf(fp0, "</a>\n");
220
fprintf(fp0, " <NONE>\n");
223
fprintf(fp0, "</pre>\n");
224
EndInternalPage(fp0);
227
LYforce_no_cache = TRUE;