aboutsummaryrefslogtreecommitdiff
path: root/server.d
blob: 640271cee6eb796e537ae5386331165c8097557e (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
import std.socket, std.stdio,
       std.conv, std.file,
       std.string;
import serverutils;

void main(string[] args) {
	if (args.length != 2) return;
	auto sock = new TcpSocket();
	sock.bind(new InternetAddress("127.0.0.1", to!ushort(args[1])));
	sock.listen(1000);
	while (true) {
    auto level = 0;
		auto pair = sock.accept();
		char[255] filename;
		auto len = pair.receive(filename);
    auto file = filename[0 .. len];
    file = strip(file);
    if (inRoot(file)) {
  		pair.send(readText(file));
    } else {
      pair.send("ERROR: Client left root!\n");
    }
		pair.shutdown(SocketShutdown.BOTH);
		pair.close();
	}
}