aboutsummaryrefslogtreecommitdiff
path: root/wfm.h
blob: 4c1080ee05848a85e3b9ad50ea8d0eeca7e5adae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#define VERSION "1.4.0"
#define COPYRIGHT "<!-- WFM Version " VERSION ", Mountain View, CA, " __DATE__ " [" __TIME__ "] -->\n" \
                  "<!-- Copyright (c) 1994-2018 by Antoni Sawicki -->\n"

#define FONT_SIZE "13px"

#define CSS_STYLE         \
            "  <STYLE TYPE=\"text/css\"><!-- \n" \
            "    A:link {text-decoration: none; color:#0000CE; } \n" \
            "    A:visited {text-decoration: none; color:#0000CE; } \n" \
            "    A:active {text-decoration: none; color:#FF0000; } \n" \
            "    A:hover {text-decoration: none; color:#FF0000; } \n" \
            "    body, td, th, input { font-family: Tahoma, Sans-Serif; font-size:" FONT_SIZE ";  } \n" \
            "    html, body { box-sizing: border-box; width:100%%; height:100%%; margin:0px; padding:0px; } \n" \
            "    input  { border-color:#000000; border-style:solid; }\n" \
            "    img { vertical-align: middle; }\n" \
            "    .tbr { border-width: 1px; border-style: solid solid solid solid; border-color: #AAAAAA #555555 #555555 #AAAAAA; }\n" \
            "    .twh { width:100%%; height:100%%; }\n" \
            "  --></STYLE>\n"

#define HTML_HEADER \
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" \
        "   \"http://www.w3.org/TR/html4/loose.dtd\">\n" \
        "<HTML LANG=\"en\">\n" \
        COPYRIGHT \
        "<HEAD>\n" \
        "  <META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=US-ASCII\">\n" \
        "  <META HTTP-EQUIV=\"Content-Language\" CONTENT=\"en-US\">\n" \
        "  <META HTTP-EQUIV=\"google\" CONTENT=\"notranslate\">\n" \
        "  <META NAME=\"viewport\" CONTENT=\"width=device-width\">\n" \
        CSS_STYLE


#define _FILE_OFFSET_BITS 64

#ifdef __sun__
#define _POSIX_PTHREAD_SEMANTICS
#endif

#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <ctype.h>
#include <dirent.h>
#include <regex.h>
#include <stdarg.h>
#include <errno.h>
#include <time.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/shm.h>    
#include <sys/file.h>
//#include <sys/dir.h>
#include "md5.h"
#include "cgic.h"
#include "wfmiconres.h"

#define VALIDCHRS "an ()[]{}-_.,!@#$%^&=+;"
#define VALIDCHRS_DIR VALIDCHRS "/"


#define P1024_1 1024.0f
#define P1024_2 1048576.0f
#define P1024_3 1073741824.0f
#define P1024_4 1099511627776.0f

#define SHM_SIZE 16

struct  wfm_paths {
    char virt_dirname[NAME_MAX];
    char *virt_dirname_urlencoded;
    char virt_filename[NAME_MAX]; 
    char *virt_filename_urlencoded; 
    char virt_destination[NAME_MAX]; 
    char virt_parent[NAME_MAX];
    char *virt_parent_urlencoded;
    char phys_dirname[PATH_MAX]; 
    char phys_filename[PATH_MAX];
    char phys_destination[PATH_MAX];
    char final_destination[PATH_MAX];
} wp;

regex_t dotdot;

struct config_struct {
    int users_defined;
    int edit_by_default;
    int edit_any_file;
    int recursive_du;
    int largeset;
    char homedir[1024];
    char homeurl[1024];
    char tagline[1024];
    char favicon[1024];
} cfg;

struct runtime_struct {
    char token[256];
    char iconsurl[1024];
    char loggedinuser[64];
    int access_level;
    int access_as_user;
    int js;
} rt;

double t1, t2;
struct timeval mt;

enum { FALSE, TRUE };
enum { PERM_NO, PERM_RO, PERM_RW };
enum { CHANGE, DELETE, MOVE };


typedef struct asdir_ {
    char name[NAME_MAX];
    mode_t type;
    off_t size;
    time_t atime, mtime, rtime;
} ASDIR;

int namesort(const void *, const void *);
int rnamesort(const void *, const void *);
int sizesort(const void *, const void *);
int rsizesort(const void *, const void *);
int timesort(const void *, const void *);
int rtimesort(const void *, const void *);
int asscandir(const char *, ASDIR **, int (*compar)(const void *, const void *));

void dbgprintf(char *, ...);
void error(char *, ...);
void redirect(char *, ...);
char *buprintf(float, int);
int strip(char *, int, char *);
int strsplit(char *, char ***, char *);
void checkfilename(char *);
void checkdestination(void); 
void mkfile(void);
void newdir(void);
void edit_save(void);
void delete(void);
void move(void);
void dirlist(void);
void edit_ui(void);
void rename_ui(void);
void mkdir_ui(void);
void mkfile_ui(void);
void multiprompt_ui(char *);
void about(void);
void sendfile(void);
void receivefile(void);
off_t du(char *);
void re_dir_ui(char *, int);
int re_dir_up(char *);
void login_ui(void);
void tstop(void);
void html_title(char *);
void singleprompt_ui(char *);
char *url_encode(char *);
char *url_decode(char *);
int wfm_commit(int, char *);
int repo_check(void);