Posts: 4,628
Threads: 115
Joined: Dec 2011
Thanks: 693
Given 494 thank(s) in 423 post(s)
06-06-2015, 07:39 AM
(This post was last modified: 06-06-2015, 07:40 AM by NiLSPACE.)
Does anyone know how to change the working directory for a function?
The idea is that if inside that function for example the "dofile" or "cFile:Exists" function is used it doesn't direct to "root/<asked file>" but "root/Plugins/MC-Web-Server/www/<asked file>"
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
06-06-2015, 09:37 AM
(This post was last modified: 06-06-2015, 09:39 AM by worktycho.)
I hope this isn't possible. The working directory is process global, so the change would effect other plugins in strange ways.
What are you actually trying to do? It looks like re-implement nginx's ngx_lua module. Why? MCServer's HTTP support is crap, and really should be farmed out to an actual server.
Posts: 783
Threads: 12
Joined: Jan 2014
Thanks: 2
Given 73 thank(s) in 61 post(s)
Off topic, but I really don't like the idea of a custom HTTP server. I've looked through your code, and already noticed that it doesn't handle uri encoding, and it has a path traversal vulnerability, as you don't pass a deliminator to StringSplit on host.lua line 25. Make sure you also handle \ for the path to fix problems on windows.