CREATE DATABASE webtasks;
GRANT ALL PRIVILEGES ON webtasks.* TO 'webtasks'@'localhost' IDENTIFIED BY 'eexi0AutJoohee5I';
USE webtasks;
CREATE TABLE capabilities ( id int(5) NOT NULL default 0, capability varchar(20) NOT NULL default "");
CREATE TABLE results (sid int(11) NOT NULL, testno int(11) NOT NULL, retval int(11), stdout LONGBLOB, stderr LONGBLOB);
CREATE TABLE solutions (sid int(11) NOT NULL auto_increment, id int(5) NOT NULL, tid int(11) NOT NULL, solution LONGBLOB NOT NULL, PRIMARY KEY(sid));
CREATE TABLE tasks ( tid int(11) NOT NULL auto_increment, title TEXT NOT NULL, text LONGTEXT NOT NULL, PRIMARY KEY(tid));
CREATE TABLE tests (tid int(11) NOT NULL, testno int(11) NOT NULL, input LONGBLOB, inputfile LONGBLOB, output LONGBLOB, outputfile LONGBLOB, policy LONGBLOB, PRIMARY KEY (tid, testno));
CREATE TABLE users ( id int(5) NOT NULL auto_increment, user varchar(20) NOT NULL default "", pass varchar(50) NOT NULL default "", PRIMARY KEY (id));
INSERT INTO capabilities SET id=1, capability="login";
INSERT INTO capabilities SET id=1, capability="taskedit";
INSERT INTO capabilities SET id=1, capability="useredit";
INSERT INTO capabilities SET id=15, capability="login";
INSERT INTO `solutions` VALUES (1,15,1,'public class HelloWorld {\n	public static void main(String[] args) {\n		System.out.println(\"Hello World\");\n	}\n}\n');
INSERT INTO `solutions` VALUES (2,15,1,'public class HelloWorld {\n	public static void main(String[] args) {\n		System.out.println(\"Hello World\");\n	}\n}\n');
INSERT INTO `solutions` VALUES (3,15,1,'public class DontCompile {\n	public static void main(String[] args) {\n		System.out.println(\"Hello World\")\n	}\n}\n');
INSERT INTO `solutions` VALUES (4,15,1,'public class DontCompile {\n	public static void main(String[] args) {\n		System.out.println(\"Hello World\")\n	}\n\n');
INSERT INTO `solutions` VALUES (5,15,1,'public class SalutMundi {\n	public static void main(String[] args) {\n		System.out.println(\"Salut Mundi\");\n	}\n}\n');
INSERT INTO tasks SET tid=1, title="Test-Task", text="As a first step write a program which prints \"Hello World\" on stdout and terminates.";
INSERT INTO tasks SET tid=2, title="Addition", text="Write a program which reads two integers from stdin and adds them. Print the result to stdout. If one of the lines of the input are not a integer print \"NaN\".";
INSERT INTO tasks SET tid=3, title="Cat", text="Write a programm which acts like the unix command cat without any parameters. The name of the input file is the first and only command line parameter.";
INSERT INTO tasks SET tid=4, title="Quicksort", text="Implement a simple sorting program using quicksort. The name of the input file is given on the commandline. If the switch -r is specified the sort should be performed in reverse order. The input file contains an arbitrary number of intergers seperated by \\n. The sorted integers should be written to stdout, one per line. Lines not containing integers in the input file should be ignored.";
INSERT INTO tasks SET tid=5, title="Copy", text="Write a program which accepts two filenames as commandline parameters. The content of the first file is to be copied into the second file. All 256 possible byte values have to be handled including the Null-Byte!";
INSERT INTO users SET id=1, user = "admin", pass = "21232f297a57a5a743894a0e4a801fc3";
INSERT INTO users SET id=15, user = "foo", pass = "acbd18db4cc2f85cedef654fccc4a4d8";
INSERT INTO tests SET tid=1, testno=2, input="", inputfile="", output="/^\\h*Hello.*World\\h*$/", outputfile="", policy="";
INSERT INTO tests SET tid=2, testno=3, input="1\n1\n", inputfile="", output="/^2\\h*.*$/", outputfile="", policy="";
INSERT INTO tests SET tid=2, testno=4, input="17\n4\n", inputfile="", output="/^21\\h*.*$/", outputfile="", policy="";
INSERT INTO tests SET tid=2, testno=5, input="1\n2\n", inputfile="", output="/^3\\h*.*$/", outputfile="", policy="";
INSERT INTO tests SET tid=2, testno=6, input="1\nfoobar\n", inputfile="", output="/^NaN$/", outputfile="", policy="";
INSERT INTO tests SET tid=3, testno=7, input="", inputfile="foobar", output="/^foobar$/", outputfile="", policy="";
INSERT INTO tests SET tid=3, testno=8, input="", inputfile="foo\r\nbar", output="/^foo\r\nbar$/", outputfile="", policy="";
INSERT INTO tests SET tid=3, testno=9, input="", inputfile="foo\r\nbar\r\nglue", output="/^foo\r\nbar\r\nglue$/", outputfile="", policy=""
INSERT INTO tests SET tid=4, testno=10, input="", inputfile="1\r\n2\r\n7\r\n5\r\nfoobar\r\n4\r\nfasel\r\n6\r\n3\r\n", output="/1\n2\n3\n4\n5\n6\n7/", outputfile="", policy="";
INSERT INTO tests SET tid=4, testno=11, input="", inputfile="1\r\n1\r\n1", output="/1\n1\n1/", outputfile="", policy="";
INSERT INTO tests SET tid=4, testno=12, input="", inputfile="1\r\n2\r\n3\r\n", output="/1\n2\n3/", outputfile="", policy="";
INSERT INTO tests SET tid=4, testno=13, input="", inputfile="3\r\n2\r\n1", output="/1\n2\n3/", outputfile="", policy="";
INSERT INTO tests SET tid=5, testno=14, input="", inputfile="foobar", output="", outputfile="foobar", policy="grant {\r\n        permission java.io.FilePermission \"/tmp/-\", \"read, write\";\r\n};\r\n";
INSERT INTO tests SET tid=5, testno=15, input="", inputfile="\\n\\r\\t", output="", outputfile="\\n\\r\\t", policy="grant {\r\n        permission java.io.FilePermission \"/tmp/-\", \"read, write\";\r\n};\r\n";
