📄 lylocal.c
字号:
return(0); } user_filename = srcpath; cp = strrchr(srcpath, '/'); if (cp != NULL) { user_filename = (cp + 1); } if (first) { /* * Get an unused tempfile name. - FM */ tempname(tempfile, NEW_FILE); } /* * Open the tempfile for writing and set its * protection in case this wasn't done via an * external umask. - FM */ if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { _statusline("Unable to open permit options file"); sleep(AlertSecs); return(0); } if (first) { /* * Make the tempfile a URL. */ strcpy(LYPermitFileURL, "file://localhost"); strcat(LYPermitFileURL, tempfile); first = FALSE; } StrAllocCopy(*newpath, LYPermitFileURL); grp = getgrgid(dir_info.st_gid); if (grp == NULL) { group_name = ""; } else { group_name = grp->gr_name; } LYstrncpy(LYValidPermitFile, srcpath, (sizeof(LYValidPermitFile) - 1)); fprintf(fp0, "<Html><Head>\n<Title>%s</Title>\n</Head>\n<Body>\n", PERMIT_OPTIONS_TITLE); fprintf(fp0,"<H1>Permissions for %s</H1>\n", user_filename); { /* * Prevent filenames which include '#' or '?' from messing it up. */ char * srcpath_url = HTEscape(srcpath, URL_PATH); fprintf(fp0, "<Form Action=\"LYNXDIRED://PERMIT_LOCATION%s\">\n", srcpath_url); FREE(srcpath_url); } fprintf(fp0, "<Ol><Li>Specify permissions below:<Br><Br>\n"); fprintf(fp0, "Owner:<Br>\n"); fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IRUSR\" %s> Read<Br>\n", (dir_info.st_mode & S_IRUSR) ? "checked" : ""); fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IWUSR\" %s> Write<Br>\n", (dir_info.st_mode & S_IWUSR) ? "checked" : ""); /* * If restricted, only change eXecute permissions on directories. */ if (!no_change_exec_perms || S_ISDIR(dir_info.st_mode)) fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IXUSR\" %s> %s<Br>\n", (dir_info.st_mode & S_IXUSR) ? "checked" : "", S_ISDIR(dir_info.st_mode) ? "Search" : "Execute"); fprintf(fp0, "Group %s:<Br>\n", group_name); fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IRGRP\" %s> Read<Br>\n", (dir_info.st_mode & S_IRGRP) ? "checked" : ""); fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IWGRP\" %s> Write<Br>\n", (dir_info.st_mode & S_IWGRP) ? "checked" : ""); /* * If restricted, only change eXecute permissions on directories. */ if (!no_change_exec_perms || S_ISDIR(dir_info.st_mode)) fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IXGRP\" %s> %s<Br>\n", (dir_info.st_mode & S_IXGRP) ? "checked" : "", S_ISDIR(dir_info.st_mode) ? "Search" : "Execute"); fprintf(fp0, "Others:<Br>\n"); fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IROTH\" %s> Read<Br>\n", (dir_info.st_mode & S_IROTH) ? "checked" : ""); fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IWOTH\" %s> Write<Br>\n", (dir_info.st_mode & S_IWOTH) ? "checked" : ""); /* * If restricted, only change eXecute permissions on directories. */ if (!no_change_exec_perms || S_ISDIR(dir_info.st_mode)) fprintf(fp0, "<Input Type=\"checkbox\" Name=\"mode\" Value=\"IXOTH\" %s> %s<Br>\n", (dir_info.st_mode & S_IXOTH) ? "checked" : "", S_ISDIR(dir_info.st_mode) ? "Search" : "Execute"); fprintf(fp0,"<Br>\n<Li><Input Type=\"submit\" Value=\"Submit\"> \form to permit %s %s.\n</Ol>\n</Form>\n", (dir_info.st_mode & S_IFMT) == S_IFDIR ? "directory" : "file", user_filename); fprintf(fp0, "</Body></Html>"); fclose(fp0); LYforce_no_cache = TRUE; return(PERMIT_FORM_RESULT); /* Special flag for LYMainLoop */ } else { /* The form being activated. */ mode_t new_mode = 0; char *args[5]; char amode[10]; /* * Make sure we have a valid set-permission * file comparison string loaded via a previous * call with srcpath != NULL. - KW */ if (LYValidPermitFile[0] == '\0') { if (LYCursesON) HTAlert(INVALID_PERMIT_URL); else fprintf(stderr, "%s\n", INVALID_PERMIT_URL); if (TRACE) fprintf(stderr, "permit_location: called for <%s>.\n", (destpath ? destpath : "NULL URL pointer")); return 0; } cp = destpath; while (*cp != '\0' && *cp != '?') { /* Find filename */ cp++; } if (*cp == '\0') { return(0); /* Nothing to permit. */ } *cp++ = '\0'; /* Null terminate file name and start working on the masks. */ HTUnEscape(destpath); /* Will now operate only on filename part. */ /* * Make sure that the file string is the one from * the last displayed File Permissions menu. - KW */ if (strcmp(destpath, LYValidPermitFile)) { if (LYCursesON) HTAlert(INVALID_PERMIT_URL); else fprintf(stderr, "%s\n", INVALID_PERMIT_URL); if (TRACE) fprintf(stderr, "permit_location: called for file '%s'.\n", destpath); return 0; } /* * A couple of sanity tests. */ destpath = strip_trailing_slash(destpath); if (stat(destpath, &dir_info) == -1) { sprintf(tmpbuf, "Unable to get status of '%s'.", destpath); _statusline(tmpbuf); sleep(AlertSecs); return 0; } else if ((dir_info.st_mode & S_IFMT) != S_IFDIR && (dir_info.st_mode & S_IFMT) != S_IFREG) { _statusline( "The specified item is not a file nor a directory - request ignored."); sleep(AlertSecs); return 0; } /* * Cycle over permission strings. */ while(*cp != '\0') { char *cr = cp; while(*cr != '\0' && *cr != '&') { /* GET data split by '&'. */ cr++; } if (*cr != '\0') { *cr++ = '\0'; } if (strncmp(cp, "mode=", 5) == 0) { /* Magic string. */ int i; for(i = 0; permissions[i].string_mode != NULL; i++) { if (strcmp(permissions[i].string_mode, cp+5) == 0) { /* * If restricted, only change eXecute * permissions on directories. */ if (!no_change_exec_perms || strchr(cp+5,'X') == NULL || S_ISDIR(dir_info.st_mode)) new_mode |= permissions[i].permit_bits; break; } } if (permissions[i].string_mode == NULL) { _statusline("Invalid mode format."); sleep(AlertSecs); return 0; } } else { _statusline("Invalid syntax format."); sleep(AlertSecs); return 0; } cp = cr; }#ifdef UNIX /* * Call chmod(). */ sprintf(tmpbuf, "chmod %.4o %s", (unsigned int)new_mode, destpath); sprintf(amode, "%.4o", (unsigned int)new_mode); args[0] = "chmod"; args[1] = amode; args[2] = destpath; args[3] = (char *) 0; if (LYExecv(CHMOD_PATH, args, tmpbuf) <= 0) { return (-1); }#endif /* UNIX */ LYforce_no_cache = TRUE; /* Force update of dired listing. */ return 1; }#endif /* !UNIX */}#endif /* OK_PERMIT *//* * Display or remove a tag from a given link. */PUBLIC void tagflag ARGS2( int, flag, int, cur){ if (nlinks > 0) { move(links[cur].ly, 2); stop_reverse(); if (flag == ON) { addch('+'); } else { addch(' '); }#if defined(FANCY_CURSES) || defined(USE_SLANG) if (!LYShowCursor) move((LYlines - 1), (LYcols - 1)); /* get cursor out of the way */ else#endif /* FANCY CURSES || USE_SLANG */ /* * Never hide the cursor if there's no FANCY CURSES. */ move(links[cur].ly, links[cur].lx); refresh(); }}/* * Handle DIRED tags. */PUBLIC void showtags ARGS1( HTList *, t){ int i; HTList *s; char *name; for (i = 0; i < nlinks; i++) { s = t; while ((name = HTList_nextObject(s)) != NULL) { if (!strcmp(links[i].lname, name)) { tagflag(ON, i); break; } } }}/* * Perform file management operations for LYNXDIRED URL's. * Attempt to be consistent. These are (pseudo) URLs - i.e. they should * be in URL syntax: some bytes will be URL-escaped with '%'. This is * necessary because these (pseudo) URLs will go through some of the same * kinds of interpretations and mutilations as real ones: HTParse, stripping * off #fragments etc. (Some access schemes currently have special rules * about not escaping parsing '#' "the URL way" built into HTParse, but that * doesn't look like a clean way.) */PUBLIC int local_dired ARGS1( document *, doc){ char *line_url; /* will point to doc's address, which is a URL */ char *line = NULL; /* same as line_url, but HTUnEscaped, will be alloced */ char *cp, *tp, *bp; char tmpbuf[256]; char buffer[512]; line_url = doc->address; if (TRACE) fprintf(stderr, "local_dired: called for <%s>.\n", (line_url ? line_url : "NULL URL pointer")); HTUnEscapeSome(line_url, "/"); /* don't mess too much with *doc */ StrAllocCopy(line, line_url); HTUnEscape(line); /* _file_ (not URL) syntax, for those functions that need it. Don't forget to FREE it. */ tp = NULL; if (!strncmp(line, "LYNXDIRED://NEW_FILE", 20)) { if (create_file(&line[20]) > 0) LYforce_no_cache = TRUE; } else if (!strncmp(line, "LYNXDIRED://NEW_FOLDER", 22)) { if (create_directory(&line[22]) > 0) LYforce_no_cache = TRUE; } else if (!strncmp(line, "LYNXDIRED://INSTALL_SRC", 23)) { local_install(NULL, &line[23], &tp); StrAllocCopy(doc->address, tp); FREE(line); return 0; } else if (!strncmp(line, "LYNXDIRED://INSTALL_DEST", 24)) { local_install(&line[24], NULL, &tp); LYpop(doc); } else if (!strncmp(line, "LYNXDIRED://MODIFY_NAME", 23)) { if (modify_name(&line[23]) > 0) LYforce_no_cache = TRUE; } else if (!strncmp(line, "LYNXDIRED://MODIFY_LOCATION", 27)) { if (modify_location(&line[27]) > 0) LYforce_no_cache = TRUE; } else if (!strncmp(line, "LYNXDIRED://MOVE_TAGGED", 23)) { if (modify_tagged(&line_url[23]) > 0) LYforce_no_cache = TRUE;#ifdef OK_PERMIT } else if (!strncmp(line, "LYNXDIRED://PERMIT_SRC", 22)) { permit_location(NULL, &line[22], &tp); if (tp) /* * One of the checks may have failed. */ StrAllocCopy(doc->address, tp); FREE(line); return 0; } else if (!strncmp(line, "LYNXDIRED://PERMIT_LOCATION", 27)) { permit_location(&line_url[27], NULL, &tp);#endif /* OK_PERMIT */ } else if (!strncmp(line, "LYNXDIRED://REMOVE_SINGLE", 25)) { if (remove_single(&line[25]) > 0) LYforce_no_cache = TRUE; } else if (!strncmp(line, "LYNXDIRED://REMOVE_TAGGED", 25)) { if (remove_tagged()) LYforce_no_cache = TRUE; } else if (!strncmp(line, "LYNXDIRED://CLEAR_TAGGED", 24)) { clear_tags(); } else if (!strncmp(line, "LYNXDIRED://UPLOAD", 18)) { /* * They're written by LYUpload_options() HTUnEscaped; * don't want to change that for now... so pass through * without more unescaping. Directory names containing * '#' will probably fail. */ if (LYUpload(line_url)) LYforce_no_cache = TRUE; } else { if (line[(strlen(line) - 1)] == '/') line[strlen(line)-1] = '\0'; if ((cp = strrchr(line, '/')) == NULL) { FREE(line); return 0; } /* * Construct the appropriate system command taking care to * escape all path references to avoid spoofing the shell. */ *buffer = '\0'; if (!strncmp(line, "LYNXDIRED://DECOMPRESS", 22)) { tp = quote_pathname(line + 22); sprintf(buffer,"%s %s", UNCOMPRESS_PATH, tp); FREE(tp);#if defined(OK_UUDECODE) && !defined(ARCHIVE_ONLY) } else if (!strncmp(line, "LYNXDIRED://UUDECODE", 20)) { tp = quote_pathname(line + 20); sprintf(buffer,"%s %s", UUDECODE_PATH, tp); _statusline( "Warning! UUDecoded file will exist in the directory you started Lynx."); sleep(AlertSecs); FREE(tp);#endif /* OK_UUDECODE && !ARCHIVE_ONLY */#ifdef OK_TAR# ifndef ARCHIVE_ONLY# ifdef OK_GZIP } else if (!strncmp(line, "LYNXDIRED://UNTAR_GZ", 20)) { tp = quote_pathname(line+20); *cp++ = '\0'; cp = quote_pathname(line + 20); sprintf(buffer, "%s -qdc %s | (cd %s; %s -xf -)", GZIP_PATH, tp, cp, TAR_PATH); FREE(cp); FREE(tp);# endif /* OK_GZIP */ } else if (!strncmp(line, "LYNXDIRED://UNTAR_Z", 19)) { tp = quote_pathname(line + 19); *cp++ = '\0'; cp = quote_pathname(line + 19); sprintf(buffer, "%s %s | (cd %s; %s -xf -)", ZCAT_PATH, tp, cp, TAR_PATH); FREE(cp); FREE(tp); } else if (!strncmp(line, "LYNXDIRED://UNTAR", 17)) { tp = quote_pathname(line + 17); *cp++ = '\0'; cp = quote_pathname(line + 17); sprintf(buffer, "cd %s; %s -xf %s", cp, TAR_PATH, tp); FREE(cp); FREE(tp);# endif /* !ARCHIVE_ONLY */# ifdef OK_GZIP } else if (!strncmp(line, "LYNXDIRED://TAR_GZ", 18)) { *cp++ = '\0'; cp = quote_pathname(cp); tp = quote_pathname(line + 18); sprintf(buffer, "(cd %s; %s -cf - %s) | %s -qc >%s/%s.tar.gz", tp, TAR_PATH, cp, GZIP_PATH, tp, cp); FREE(cp); FREE(tp);# endif /* OK_GZIP */ } else if (!strncmp(line, "LYNXDIRED://TAR_Z", 17)) { *cp++ = '\0'; cp = quote_pathname(cp); tp = quote_pathname(line + 17); sprintf(buffer, "(cd %s; %s -cf - %s) | %s >%s/%s.tar.Z", tp, TAR_PATH, cp, COMPRESS_PATH, tp, cp); FREE(cp); FREE(tp); } else if (!strncmp(line, "LYNXDIRED://TAR", 15)) { *cp++ = '\0'; cp = quote_pathname(cp); tp = quote_pathname(line + 15); sprintf(buffer, "(cd %s; %s -cf %s.tar %s)", tp, TAR_PATH, cp, cp); FREE(cp); FREE(tp);#endif /* OK_TAR */#ifdef OK_GZIP } else if (!strncmp(line, "LYNXDIRED://GZIP", 16)) { tp = quote_pathname(line + 16); sprintf(buffer, "%s -q %s", GZIP_PATH, tp); FREE(tp);#ifndef ARCHIVE_ONLY } else if (!strncmp(line, "LYNXDIRED://UNGZIP", 18)) { tp = quote_pathname(line + 18); sprintf(buffer, "%s -d %s", GZIP_PATH, tp); FREE(tp);#endif /* !ARCHIVE_ONLY */#endif /* OK_GZIP */#ifdef OK_ZIP } else if (!strncmp(line, "LYNXDIRED://ZIP", 15)) { tp = quote_pathname(line + 15); *cp++ = '\0'; bp = quote_pathname(cp); cp = quote_pathname(line + 15); sprintf(buffer, "cd %s; %s -rq %s.zip %s", cp, ZIP_PATH, tp, bp); FREE(cp); FREE(bp); FREE(tp);#ifndef ARCHIVE_ONLY } else if (!strncmp(line, "LYNXDIRED://UNZIP", 17)) { tp = quote_pathname(line + 17); *cp = '\0'; cp = quote_pathname(line + 17); sprintf(buffer, "cd %s; %s -q %s", cp, UNZIP_PATH, tp); FREE(cp); FREE(tp);# endif /* !ARCHIVE_ONLY */#endif /* OK_ZIP */ } else if (!strncmp(line, "LYNXDIRED://COMPRESS", 20)) { tp = quote_pathname(line + 20); sprintf(buffer, "%s %s", COMPRESS_PATH, tp); FREE(tp); } if (strlen(buffer)) { if (strlen(buffer) < 60) { sprintf(tmpbuf, "Executing %s ", buffer); } else { sprintf(tmpbuf, "Executing system command. This might take a while."); } _statusline(tmpbuf); stop_curses(); printf("%s\n", tmpbuf); fflush(stdout); system(buffer);#ifdef VMS extern BOOLEAN HadVMSInterrupt HadVMSInterrupt = FALSE;#endif /* VMS */ start_curses(); LYforce_no_cache = TRUE; } } FREE(line); LYpop(doc); return 0;}/* * Provide a menu of file management options. */PUBLIC int dired_options ARGS2( document *, doc, char **, newfile){ static char tempfile[256]; static BOOLEAN first = TRUE; char path[512], dir[512]; /* much too large */ char tmpbuf[LINESIZE]; lynx_html_item_type *nxt; struct stat dir_info; FILE *fp0; char *cp = NULL; char *dir_url = NULL; /* Will hold URL-escaped path of directory from where DIRED_MENU was invoked (NOT its full URL). */ char *path_url = NULL; /* Will hold URL-escaped path of file (or directory) which was selected when DIRED_MENU was invoked (NOT its full URL). */ BOOLEAN nothing_tagged; int count; struct dired_menu *mp; char buf[2048]; if (first) { /* * Get an unused tempfile name. - FM */ tempname(tempfile, NEW_FILE); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -