|
| 1 | +# RUN CONFIG.PY TO CONFIGURE |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +'''Max buffer size to accept from a client''' |
| 6 | +SIZE = 8192 # 8*1024 = 8MB |
| 7 | + |
| 8 | +'''Gets the Current Working directory (.)''' |
| 9 | +ROOT = os.getcwd() |
| 10 | + |
| 11 | +#dictionary to convert month to its decimal |
| 12 | +MONTH = { 'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, |
| 13 | + 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12 } |
| 14 | + |
| 15 | +''' |
| 16 | +fav icon which is displayed in title bar of the browser is requested by client |
| 17 | +so we define the path of favicon.ico here |
| 18 | +''' |
| 19 | +favicon = '/images/favicon.ico' |
| 20 | +FAVICON = ROOT + favicon # to get absolute path |
| 21 | + |
| 22 | +''' |
| 23 | +only HTTP version no. 1.1 is supported for this server. |
| 24 | +It depends on the implementation of the dev but I am only supporting 1.1 |
| 25 | +''' |
| 26 | +RUNNING_VERSION = '1.1' |
| 27 | + |
| 28 | +''' |
| 29 | +Number of Thread Requests handled by the server at one time |
| 30 | +''' |
| 31 | +MAX_REQUEST = 20 |
| 32 | + |
| 33 | +''' |
| 34 | +Maximum URL length supported by the server at the time of establishing new connection |
| 35 | +''' |
| 36 | +MAX_URL = 250 |
| 37 | + |
| 38 | +''' |
| 39 | +log file path so that we can write into it |
| 40 | +''' |
| 41 | +LOG = ROOT + '/server.log' |
| 42 | +w = open(LOG, "a") # using a mode so we can only append and not overrite etc bad stuff |
| 43 | +w.close() |
| 44 | + |
| 45 | +''' |
| 46 | +workfile.html has the response saved msg. |
| 47 | +It is not part of the Server program I am using it show client that it's response is saved |
| 48 | +''' |
| 49 | +WORKFILE = ROOT + '/workfile.html' # path |
| 50 | + |
| 51 | +''' |
| 52 | +this creates a basic html workfile |
| 53 | +''' |
| 54 | +w = open(WORKFILE, "w") |
| 55 | +d = '''<html lang="en"> |
| 56 | +<head> |
| 57 | + <meta charset="UTF-8"> |
| 58 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 59 | + <title>Response Recieved</title> |
| 60 | +<body> |
| 61 | + <h1>Yeah We got the response!</h1> |
| 62 | + </br> |
| 63 | + <h1>Your Response was Saved Succesfully!</h1> |
| 64 | +</body> |
| 65 | +</html>''' |
| 66 | +w.write(d) |
| 67 | +w.close() |
| 68 | + |
| 69 | +''' |
| 70 | +All data entered by the client is stored here for checking Purpose. |
| 71 | +''' |
| 72 | +CSVFILE = ROOT + '/output.csv' |
| 73 | +w = open(CSVFILE, "a") # only appending not writing |
| 74 | +w.close() |
| 75 | + |
| 76 | +''' |
| 77 | +all the files which are deleted using DELETE are getting moved here. |
| 78 | +''' |
| 79 | +DELETE = ROOT + '/deleted' |
| 80 | +''' |
| 81 | +the /deleted folder mentioned above is created here. |
| 82 | +For the DELETE req purpose |
| 83 | +''' |
| 84 | +try: |
| 85 | + os.mkdir(DELETE) |
| 86 | +except: |
| 87 | + pass |
| 88 | + |
| 89 | +''' |
| 90 | +username and password for approval of delete request method |
| 91 | +''' |
| 92 | +USERNAME = 'http' # delete can only be done after checking Auth |
| 93 | +PASSWORD = 'sudo' # Keep this secret folks |
| 94 | + |
| 95 | + |
| 96 | +''' |
| 97 | +cookie details |
| 98 | +''' |
| 99 | +COOKIE = 'Set-Cookie: id=' # id will be given in the program |
| 100 | +MAXAGE = '; max-age=3600' # 3600 sec is 60min |
| 101 | + |
| 102 | +'''Following is the file formats supported by the server''' |
| 103 | +FORMAT = { |
| 104 | + ".aac" : "audio/aac", |
| 105 | + ".abw" : "application/x-abiword", |
| 106 | + ".arc" : "application/x-freearc", |
| 107 | + ".avi" : "video/x-msvideo", |
| 108 | + ".azw" : "application/vnd.amazon.ebook", |
| 109 | + ".bin" : "application/octet-stream", |
| 110 | + ".bmp" : "image/bmp", |
| 111 | + ".bz" : "application/x-bzip", |
| 112 | + ".bz2" : "application/x-bzip2", |
| 113 | + ".csh" : "application/x-csh", |
| 114 | + ".css" : "text/css", |
| 115 | + ".csv" : "text/csv", |
| 116 | + ".doc" : "application/msword", |
| 117 | + ".docx" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document", |
| 118 | + ".eot" : "application/vnd.ms-fontobject", |
| 119 | + ".epub" : "application/epub+zip", |
| 120 | + ".gz" : "application/gzip", |
| 121 | + ".gif" : "image/gif", |
| 122 | + ".htm" : "text/html", |
| 123 | + ".html" : "text/html", |
| 124 | + ".ico" : "image/vnd.microsoft.icon", |
| 125 | + ".ics" : "text/calendar", |
| 126 | + ".jar" : "application/java-archive", |
| 127 | + ".jpeg" : "image/jpeg", |
| 128 | + ".jpg" : "image/jpeg", |
| 129 | + ".js" : "text/javascript", |
| 130 | + ".json" : "application/json", |
| 131 | + ".jsonld": "application/ld+json", |
| 132 | + ".mid" : "audio/midi", |
| 133 | + " .midi": "audio/midi", |
| 134 | + ".mjs" : "text/javascript", |
| 135 | + ".mp3" : "audio.mpeg", |
| 136 | + ".mpeg" : "video/mpeg", |
| 137 | + ".mpkg" : "application/vnd.apple.installer+xml", |
| 138 | + ".odp" : "application/vnd.oasis.opendocument.presentation", |
| 139 | + ".ods" : "application/vnd.oasis.opendocument.spreadsheet", |
| 140 | + ".oga" : "audio/ogg", |
| 141 | + ".ogv" : "video/ogg", |
| 142 | + ".ogx" : "application/ogg", |
| 143 | + ".otf" : "font/otf", |
| 144 | + ".png" : "image/png", |
| 145 | + ".pdf" : "application/pdf", |
| 146 | + ".php" : "appliction/php", |
| 147 | + ".ppt" : "application/vnd.ms-powerpoint", |
| 148 | + ".pptx" : "application/vnd.openxmlformats-officedocument.presentationml.presentation", |
| 149 | + ".rar" : "application/x-rar-compressed", |
| 150 | + ".rtf" : "application/rtf", |
| 151 | + ".sh" : "application/x-sh", |
| 152 | + ".svg" : "image/svg+xml", |
| 153 | + ".swf" : "application/x-shockwave-flash", |
| 154 | + ".tar" : "application/x-tar", |
| 155 | + ".tif" : "image/tiff", |
| 156 | + " .tiff": "image/tiff", |
| 157 | + ".ts" : "video/mp2t", |
| 158 | + ".ttf" : "font/ttf", |
| 159 | + ".txt" : "text/html", |
| 160 | + ".vsd" : "application/vnd.visio", |
| 161 | + ".wav" : "audio/wav", |
| 162 | + ".weba" : "audio/webm", |
| 163 | + ".webm" : "video/webm", |
| 164 | + ".webp" : ".webp", |
| 165 | + ".woff" : "font/woff", |
| 166 | + ".woff2": "font/woff2", |
| 167 | + ".xhtml": "application/xhtml+xml", |
| 168 | + ".xls" : "application/vnd.ms-excel", |
| 169 | + ".xlsx" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", |
| 170 | + ".xml" : "application/xml", |
| 171 | + ".xul" : "application/vnd.mozilla.xul+xml", |
| 172 | + ".zip" : "application/zip", |
| 173 | + ".3gp" : "video/3gpp", |
| 174 | + ".3g2" : "video/3gpp2", |
| 175 | + ".7z" : "application/x-7z-compressed", |
| 176 | + } |
| 177 | + |
| 178 | +'''Following is the file formats supported by the server''' |
| 179 | +FORMAT2 = { |
| 180 | + "audio/aac" : ".aac" , |
| 181 | + "application/x-abiword" : ".abw" , |
| 182 | + "application/x-freearc" : ".arc" , |
| 183 | + "video/x-msvideo" : ".avi" , |
| 184 | + "application/vnd.amazon.ebook" : ".azw" , |
| 185 | + "application/octet-stream" : ".bin" , |
| 186 | + "image/bmp" : ".bmp" , |
| 187 | + "application/x-bzip" : ".bz" , |
| 188 | + "application/x-bzip2" : ".bz2" , |
| 189 | + "application/x-csh" : ".csh" , |
| 190 | + "text/css" : ".css" , |
| 191 | + "text/csv" : ".csv" , |
| 192 | + "application/msword" : ".doc" , |
| 193 | + "application/vnd.openxmlformats-officedocument.wordprocessingml.document":".docx" , |
| 194 | + "application/vnd.ms-fontobject" : ".eot" , |
| 195 | + "application/epub+zip" : ".epub" , |
| 196 | + "application/gzip" : ".gz" , |
| 197 | + "image/gif" : ".gif" , |
| 198 | + "text/html" : ".html" , |
| 199 | + "image/vnd.microsoft.icon" : ".ico" , |
| 200 | + "text/calendar" : ".ics" , |
| 201 | + "application/java-archive" : ".jar" , |
| 202 | + "image/jpeg" : ".jpeg" , |
| 203 | + "text/javascript" : ".js" , |
| 204 | + "application/json" : ".json" , |
| 205 | + "application/ld+json" : ".jsonld" , |
| 206 | + "audio/midi" : ".mid" , |
| 207 | + "audio.mpeg" : ".mp3" , |
| 208 | + "video/mpeg" : ".mpeg" , |
| 209 | + "application/vnd.apple.installer+xml":".mpkg" , |
| 210 | + "application/vnd.oasis.opendocument.presentation" : ".odp" , |
| 211 | + "application/vnd.oasis.opendocument.spreadsheet" : ".ods" , |
| 212 | + "audio/ogg" : ".oga" , |
| 213 | + "video/ogg" : ".ogv" , |
| 214 | + "application/ogg" : ".ogx" , |
| 215 | + "font/otf" : ".otf" , |
| 216 | + "image/png" : ".png" , |
| 217 | + "application/pdf" : ".pdf" , |
| 218 | + "appliction/php" : ".php" , |
| 219 | + "application/vnd.ms-powerpoint" : ".ppt" , |
| 220 | + "application/vnd.openxmlformats-officedocument.presentationml.presentation":".pptx" , |
| 221 | + "application/x-rar-compressed" : ".rar" , |
| 222 | + "application/rtf" : ".rtf" , |
| 223 | + "application/x-sh" : ".sh" , |
| 224 | + "image/svg+xml" : ".svg" , |
| 225 | + "application/x-shockwave-flash" : ".swf" , |
| 226 | + "application/x-tar" : ".tar" , |
| 227 | + "image/tiff" : ".tif" , |
| 228 | + "video/mp2t" : ".ts" , |
| 229 | + "font/ttf" : ".ttf" , |
| 230 | + "application/vnd.visio" : ".vsd" , |
| 231 | + "audio/wav" : ".wav" , |
| 232 | + "audio/webm" : ".weba" , |
| 233 | + "video/webm" : ".webm" , |
| 234 | + ".webp" : ".webp" , |
| 235 | + "font/woff" : ".woff" , |
| 236 | + "font/woff2" : ".woff2" , |
| 237 | + "application/xhtml+xml" : ".xhtml" , |
| 238 | + "application/vnd.ms-excel" : ".xls" , |
| 239 | + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":".xlsx" , |
| 240 | + "application/xml" : ".xml" , |
| 241 | + "application/vnd.mozilla.xul+xml":".xul" , |
| 242 | + "application/zip" : ".zip" , |
| 243 | + "video/3gpp" : ".3gp" , |
| 244 | + "video/3gpp2" : ".3g2" , |
| 245 | + "application/x-7z-compressed" : ".7z" , |
| 246 | + } |
| 247 | + |
| 248 | +'''Response status codes''' |
| 249 | +status_codes = { |
| 250 | + 200 : "Ok", |
| 251 | + 201 : "Created", |
| 252 | + 202 : "Accepted", |
| 253 | + 204 : "No Content", |
| 254 | + 304 : "Not Modified", |
| 255 | + 400 : "Bad Request", |
| 256 | + 401 : "Unauthorized", |
| 257 | + 403 : "Forbidden", |
| 258 | + 404 : "Not Found", |
| 259 | + 411 : "Length required", |
| 260 | + 412 : "Precondition Failed", |
| 261 | + 414 : "URI too long", |
| 262 | + 415 : "Unsupported media Type", |
| 263 | + 500 : "Internal Server Error", |
| 264 | + 501 : "Not Implemented", |
| 265 | + 503 : "Server Unavailable", |
| 266 | + 505 : "HTTP version not supported", |
| 267 | + } |
| 268 | + |
| 269 | +'''Methods supported by the server''' |
| 270 | +methods = ["GET", "POST", "HEAD", "PUT", "DELETE", "TRACE", "OPTIONS"] |
0 commit comments