diff options
author | tenox <as@tenoware.com> | 2017-01-21 01:32:08 -0800 |
---|---|---|
committer | tenox <as@tenoware.com> | 2017-01-21 01:32:08 -0800 |
commit | e9d79c70ed2d6d2a89cb5dbd9ff14d7d78b6c6de (patch) | |
tree | b2c722036b2e77059007ee9bd46fc205ecf4a3af | |
parent | 34d5f06f39ef4051793b8200be0cc532ebf63c8f (diff) | |
download | wfm-e9d79c70ed2d6d2a89cb5dbd9ff14d7d78b6c6de.tar.gz |
git rename support
-rw-r--r-- | dialogs.c | 21 | ||||
-rw-r--r-- | fileio.c | 62 | ||||
-rw-r--r-- | wfm.c | 9 | ||||
-rw-r--r-- | wfm.h | 7 |
4 files changed, 69 insertions, 30 deletions
@@ -262,7 +262,7 @@ void about(void) { "User Agent: %s<BR>\n" "NAME_MAX: %d<BR>\n" "JavaScript Level: %d<BR>\n" - "Git Support: %s (%s)<BR>\n" + "Change Control: %s (%s)<BR>\n" " <P>\n" " <P>\n" "</TD>\n" @@ -281,9 +281,9 @@ void about(void) { "</TD></TR></TABLE>\n</BODY></HTML>\n", ICONSURL, TAGLINE, VERSION, __DATE__, __TIME__, __VERSION__, cgiServerSoftware, cgiUserAgent, NAME_MAX, js, #ifdef WFMGIT - "Yes" + "Git" #else - "No" + "Nono" #endif , (repo_check()) ? "Oo Repo Present" : "Repo OK", cgiScriptName, virt_dirname, token); @@ -351,17 +351,21 @@ void edit_ui(void) { FILE *input; char *buff; char backup[4]={0}; +#ifndef WFMGIT char *bkcolor; +#endif int size; checkfilename(NULL); +#ifndef WFMGIT cgiFormString("backup", backup, sizeof(backup)); if(strcmp("yes", backup)==0) bkcolor="background-color:#404040; color:#FFFFFF;"; else bkcolor="background-color:#EEEEEE; color:#000000;"; +#endif input=fopen(phys_filename, "r"); if(input==NULL) @@ -400,6 +404,7 @@ void edit_ui(void) { " document.EDITOR.wrapbtn.style.color='#000000';\n" " } \n" "} \n" +#ifndef WFMGIT "function chbak() { \n" " if(document.EDITOR.backup.value=='yes') { \n" " document.EDITOR.backup.value='no'; \n" @@ -411,6 +416,7 @@ void edit_ui(void) { " document.EDITOR.bakbtn.style.color='#FFFFFF';\n" " } \n" "} \n" +#endif "//-->\n" "</SCRIPT>\n"); @@ -430,10 +436,11 @@ void edit_ui(void) { "<TD BGCOLOR=\"#CCCCCC\" ALIGN=\"RIGHT\">", cgiScriptName, (strncmp(cgiUserAgent, "Mozilla/4.0 (compatible; MSIE 6", 31)==0) ? "80" : "100", ICONSURL, virt_filename); - if(js) fprintf(cgiOut, - "<INPUT TYPE=\"button\" ID=\"bakbtn\" onClick=\"chbak()\" VALUE=\"Backup\" STYLE=\"border:none; %s \"> \n" - "<INPUT TYPE=\"button\" ID=\"wrapbtn\" onClick=\"chwrap()\" VALUE=\"Wrap\" STYLE=\"border:none; background-color:#404040; color:#FFFFFF;\">\n", - bkcolor); +#ifndef WFMGIT + if(js) fprintf(cgiOut, "<INPUT TYPE=\"button\" ID=\"bakbtn\" onClick=\"chbak()\" VALUE=\"Backup\" STYLE=\"border:none; %s \"> \n", bkcolor); +#endif + + if(js) fprintf(cgiOut, "<INPUT TYPE=\"button\" ID=\"wrapbtn\" onClick=\"chwrap()\" VALUE=\"Wrap\" STYLE=\"border:none; background-color:#404040; color:#FFFFFF;\">\n"); fprintf(cgiOut, "</TD>\n" @@ -2,6 +2,36 @@ #include "wfm.h" + +/* +// Debug dump vars +//void debugdumpvars(void) { + + cgiHeaderContentType("text/plain"); + + printf( + "virt_dirname=%s\n" + "phys_dirname=%s\n" + "virt_filename=%s\n" + "phys_filename=%s\n" + "virt_destination=%s\n" + "phys_destination=%s\n" + // "final_destination=%s\n" + "virt_parent=%s\n", + virt_dirname, + phys_dirname, + virt_filename, + phys_filename, + virt_destination, + phys_destination, + // final_destination, + virt_parent + ); + + exit(1); +} +*/ + // // Send file to client browser // Called by cgiMain action=sendfile @@ -82,7 +112,7 @@ void receivefile(void) { cgiFormFileClose(input); fclose(output); - change_commit("Receive File"); + wfm_commit(CHANGE); redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename_urlencoded, virt_dirname_urlencoded, token); @@ -104,7 +134,7 @@ void mkfile(void) { fclose(output); - change_commit("New File"); + wfm_commit(CHANGE); redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename_urlencoded, virt_dirname_urlencoded, token); @@ -136,10 +166,12 @@ void edit_save(void) { char tempname[64]={0}; //FILE *output; FILE *tempf; +#ifndef WFMGIT char backup[4]={0}; char backup_filename[PHYS_DESTINATION_SIZE]={0}; regex_t re; regmatch_t pmatch; +#endif struct stat tmpstat; checkfilename(NULL); @@ -157,6 +189,7 @@ void edit_save(void) { cgiFormString("content", buff, size); +#ifndef WFMGIT // rename to .bak if requested cgiFormStringNoNewlines("backup", backup, sizeof(backup)); @@ -171,7 +204,7 @@ void edit_save(void) { } } } - +#endif // write to temporary file snprintf(tempname, sizeof(tempname), "%s/.wfmXXXXXX", phys_dirname); @@ -205,7 +238,7 @@ void edit_save(void) { free(buff); - change_commit("Editor Save"); + wfm_commit(CHANGE); redirect("%s?highlight=%s&directory=%s&token=%s", cgiScriptName, virt_filename_urlencoded, virt_dirname_urlencoded, token); } @@ -240,7 +273,7 @@ void fileio_re_rmdir(char *dirname) { } else { if(unlink(tempfullpath)!=0) error("Unable to remove file....<BR>%s", strerror(errno)); - delete_commit("Recursive Delete"); + wfm_commit(DELETE); } } @@ -267,7 +300,7 @@ void fileio_delete(void) { else { if(unlink(phys_filename)!=0) error("Unable to remove file.<BR>%s", strerror(errno)); - delete_commit("Delete File"); + wfm_commit(DELETE); } } @@ -302,26 +335,18 @@ void delete(void) { // Called by move() // void fileio_move(void) { - char final_destination[PHYS_DESTINATION_SIZE]={0}; struct stat fileinfo; - int move=0; // If moving file to a different directory we need to append the original file name to destination - if( stat(phys_destination, &fileinfo)==0 && S_ISDIR(fileinfo.st_mode) ) { + if( stat(phys_destination, &fileinfo)==0 && S_ISDIR(fileinfo.st_mode) ) snprintf(final_destination, sizeof(final_destination), "%s/%s", phys_destination, virt_filename); - move=1; - } else { + else strncpy(final_destination, phys_destination, sizeof(final_destination)); - move=0; - } - + if(rename(phys_filename, final_destination)!=0) error("Unable to move file. <BR>[%d: %s]<BR>[SRC=%s] [DST=%s]", errno, strerror(errno), phys_filename, final_destination); - if(move) - move_commit("Move File"); - else - rename_commit("Rename File"); + wfm_commit(MOVE); } @@ -333,7 +358,6 @@ void move(void) { int i; char **responses; - checkdestination(); // Single @@ -388,6 +388,15 @@ int cgiMain(void) { fprintf(cgiOut, "Cache-Control: max-age=0, private\r\nExpires: -1\r\n"); + memset(virt_dirname, 0, VIRT_DIRNAME_SIZE); + memset(phys_dirname, 0, PHYS_DIRNAME_SIZE); + memset(virt_filename, 0, VIRT_FILENAME_SIZE); + memset(phys_filename, 0, PHYS_FILENAME_SIZE); + memset(virt_destination, 0, VIRT_DESTINATION_SIZE); + memset(phys_destination, 0, PHYS_DESTINATION_SIZE); + memset(final_destination, 0, PHYS_DESTINATION_SIZE); + memset(virt_parent, 0, VIRT_DIRNAME_SIZE); + snprintf(ICONSURL, sizeof(ICONSURL), "%s?ea=icon&name=", cgiScriptName); @@ -78,6 +78,7 @@ char *virt_filename_urlencoded; char phys_filename[PHYS_FILENAME_SIZE]; char virt_destination[VIRT_DESTINATION_SIZE]; char phys_destination[PHYS_DESTINATION_SIZE]; +char final_destination[PHYS_DESTINATION_SIZE]; char virt_parent[VIRT_DIRNAME_SIZE]; char *virt_parent_urlencoded; @@ -105,6 +106,7 @@ struct timeval mt; enum { FALSE, TRUE }; enum { PERM_NO, PERM_RO, PERM_RW }; +enum { CHANGE, DELETE, MOVE }; typedef struct asdir_ { char name[NAME_MAX]; @@ -149,8 +151,5 @@ void html_title(char *); void singleprompt_ui(char *); char *url_encode(char *); char *url_decode(char *); -int change_commit(char *); -int delete_commit(char *); -int rename_commit(char *); -int move_commit(char *); +int wfm_commit(int); int repo_check(void);
\ No newline at end of file |