diff --git a/environments/php/pythia.mk b/environments/php/pythia.mk new file mode 100644 index 0000000..02c3845 --- /dev/null +++ b/environments/php/pythia.mk @@ -0,0 +1,24 @@ +# Copyright 2013 The Pythia Authors. +# This file is part of Pythia. +# +# Pythia is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# Pythia is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pythia. If not, see . + +ENV_PHP := $(ENV_OUT_DIR)/php.sfs + +environments: $(ENV_PHP) + +$(ENV_PHP): $~/rootfs-config.sh $(MKROOTFS_DEPS) + @mkdir -p $(@D) + $(MKROOTFS) -o $@ $< + +# vim:set ts=4 sw=4 noet: diff --git a/environments/php/rootfs-config.sh b/environments/php/rootfs-config.sh new file mode 100644 index 0000000..526c37b --- /dev/null +++ b/environments/php/rootfs-config.sh @@ -0,0 +1,24 @@ +# Copyright 2018 The Pythia Authors. +# This file is part of Pythia. +# +# Pythia is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# Pythia is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pythia. If not, see . +# +# PHP 7.0 +install_busybox + +install_debs php7.0-cli php7.0-common php7.0-json php7.0-opcache php7.0-readline + +# Depending libraries +install_debs libc6 libedit2 libpcre3 libssl1.1 libxml2 mime-support tzdata ucf zlib1g \ + libgcc1 libbsd0 libncurses5 libtinfo5 libmagic-mgc multiarch-support debconf \ + libicu57 liblzma5 php-common coreutils libstdc++6 libselinux1 diff --git a/environments/ruby/pythia.mk b/environments/ruby/pythia.mk new file mode 100644 index 0000000..b9ba0f8 --- /dev/null +++ b/environments/ruby/pythia.mk @@ -0,0 +1,24 @@ +# Copyright 2013 The Pythia Authors. +# This file is part of Pythia. +# +# Pythia is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# Pythia is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pythia. If not, see . + +ENV_RUBY := $(ENV_OUT_DIR)/ruby.sfs + +environments: $(ENV_RUBY) + +$(ENV_RUBY): $~/rootfs-config.sh $(MKROOTFS_DEPS) + @mkdir -p $(@D) + $(MKROOTFS) -o $@ $< + +# vim:set ts=4 sw=4 noet: diff --git a/environments/ruby/rootfs-config.sh b/environments/ruby/rootfs-config.sh new file mode 100644 index 0000000..68db048 --- /dev/null +++ b/environments/ruby/rootfs-config.sh @@ -0,0 +1,22 @@ +# Copyright 2018 The Pythia Authors. +# This file is part of Pythia. +# +# Pythia is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# Pythia is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pythia. If not, see . + +# Ruby 2.3 +install_debs ruby2.3 libruby2.3 rake ruby-did-you-mean ruby-minitest ruby-net-telnet \ + ruby-power-assert ruby-test-unit rubygems-integration + +# Base libraries +install_debs libc6 libgmp10 rubygems-integration libgcc1 libffi6 libgdbm3 libncurses5 libreadline7 \ + libssl1.0.2 libtinfo5 libyaml-0-2 zlib1g ca-certificates dpkg readline-common debconf diff --git a/tasks/execute-java.task b/tasks/execute-java.task new file mode 100644 index 0000000..4829a4b --- /dev/null +++ b/tasks/execute-java.task @@ -0,0 +1,10 @@ +{ + "environment": "java", + "taskfs": "execute-java.sfs", + "limits": { + "time": 90, + "memory": 64, + "disk": 50, + "output": 1024 + } +} diff --git a/tasks/execute-java/Pre.java b/tasks/execute-java/Pre.java new file mode 100755 index 0000000..a1ed07e --- /dev/null +++ b/tasks/execute-java/Pre.java @@ -0,0 +1,70 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.Writer; +import java.io.*; +import java.lang.reflect.Field; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.charset.Charset; + +public class Pre +{ + private static String ReadProc(InputStream is) throws IOException + { + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); + StringBuilder builder = new StringBuilder(); + String line = null; + while((line = reader.readLine()) != null) { + builder.append(line); + builder.append(System.getProperty("line.separator")); + } + return builder.toString(); + } + + public static void main(String[] args) + { + try{ + InputStreamReader in = new InputStreamReader(System.in); + BufferedReader input = new BufferedReader(in); + String file = "Script.java"; + OutputStreamWriter f = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")); + String str; + + while((str = input.readLine()) != null) { + + //System.out.println(str); + f.write(str.trim() + "\n"); + } + f.close(); + + ProcessBuilder pb = new ProcessBuilder( "/usr/lib/jvm/java-8-openjdk-i386/bin/javac","-encoding", "UTF-8", file); + pb.directory(new File("/tmp/work")); + Process p = pb.start(); + + int a = p.waitFor(); + + if(a != 0) { + System.out.println("{\"stdout\": \"" + ReadProc(p.getInputStream()) + "\", \"stderr\": \"" + ReadProc(p.getErrorStream()) + "\", \"returncode\": \"" + a + "\"}"); + return; + } + + pb = new ProcessBuilder( "/usr/lib/jvm/java-8-openjdk-i386/bin/java", "Script"); + p = pb.start(); + + a = p.waitFor(); + + System.out.println("{\"stdout\": \"" + ReadProc(p.getInputStream()) + "\", \"stderr\": \"" + ReadProc(p.getErrorStream()) + "\", \"returncode\": \"" + a + "\"}"); + + } catch (IOException|InterruptedException io) { + io.printStackTrace(); + } + } +} diff --git a/tasks/execute-java/control b/tasks/execute-java/control new file mode 100755 index 0000000..82693f0 --- /dev/null +++ b/tasks/execute-java/control @@ -0,0 +1 @@ +/task/execute-java.sh diff --git a/tasks/execute-java/execute-java.sh b/tasks/execute-java/execute-java.sh new file mode 100755 index 0000000..f3c399c --- /dev/null +++ b/tasks/execute-java/execute-java.sh @@ -0,0 +1,7 @@ +#!/bin/sh +PATH=/usr/lib/jvm/java-8-openjdk-i386/bin:$PATH +mkdir /tmp/work +cp /task/Pre.java /tmp/work/Pre.java +cd /tmp/work +javac Pre.java +java Pre diff --git a/tasks/execute-php.task b/tasks/execute-php.task new file mode 100644 index 0000000..22526f8 --- /dev/null +++ b/tasks/execute-php.task @@ -0,0 +1,10 @@ +{ + "environment": "php", + "taskfs": "execute-php.sfs", + "limits": { + "time": 60, + "memory": 32, + "disk": 50, + "output": 4096 + } +} diff --git a/tasks/execute-php/control b/tasks/execute-php/control new file mode 100755 index 0000000..f3ab0a1 --- /dev/null +++ b/tasks/execute-php/control @@ -0,0 +1 @@ +/task/execute.php diff --git a/tasks/execute-php/execute.php b/tasks/execute-php/execute.php new file mode 100755 index 0000000..86288a6 --- /dev/null +++ b/tasks/execute-php/execute.php @@ -0,0 +1,32 @@ +#!/usr/bin/env php7.0 + +$desc = array(STDIN, array('pipe', "w"), array('pipe','w')); +$process = proc_open('php7.0 -f ' .$filename, $desc, $pipes, '/tmp'); +if(is_resource($process)) { + $output = stream_get_contents($pipes[1]); + $err = stream_get_contents($pipes[2]); + $return_val = proc_close($process); + echo ('{"stdin": "' . $output . '", "stderr": "' .$err . '", "returncode": "' .$return_val. '"}'); +} + + +?> diff --git a/tasks/hello-php.task b/tasks/hello-php.task new file mode 100644 index 0000000..fc0b155 --- /dev/null +++ b/tasks/hello-php.task @@ -0,0 +1,10 @@ +{ + "environment": "php", + "taskfs": "hello-php.sfs", + "limits": { + "time": 60, + "memory": 32, + "disk": 50, + "output": 1024 + } +} diff --git a/tasks/hello-php/control b/tasks/hello-php/control new file mode 100755 index 0000000..6b351b0 --- /dev/null +++ b/tasks/hello-php/control @@ -0,0 +1 @@ +/task/hello.php diff --git a/tasks/hello-php/hello.php b/tasks/hello-php/hello.php new file mode 100755 index 0000000..f3a8ba7 --- /dev/null +++ b/tasks/hello-php/hello.php @@ -0,0 +1,4 @@ +#!/usr/bin/env php7.0 + diff --git a/tasks/hello-ruby.task b/tasks/hello-ruby.task new file mode 100644 index 0000000..d0bf940 --- /dev/null +++ b/tasks/hello-ruby.task @@ -0,0 +1,10 @@ +{ + "environment": "ruby", + "taskfs": "hello-ruby.sfs", + "limits": { + "time": 60, + "memory": 32, + "disk": 50, + "output": 1024 + } +} diff --git a/tasks/hello-ruby/control b/tasks/hello-ruby/control new file mode 100755 index 0000000..c1e13e1 --- /dev/null +++ b/tasks/hello-ruby/control @@ -0,0 +1 @@ +/task/hello.sh diff --git a/tasks/hello-ruby/hello.rb b/tasks/hello-ruby/hello.rb new file mode 100755 index 0000000..d33182b --- /dev/null +++ b/tasks/hello-ruby/hello.rb @@ -0,0 +1 @@ +puts 'Hello Ruby world!' diff --git a/tasks/hello-ruby/hello.sh b/tasks/hello-ruby/hello.sh new file mode 100755 index 0000000..83dad05 --- /dev/null +++ b/tasks/hello-ruby/hello.sh @@ -0,0 +1,5 @@ +#!/bin/sh +mkdir /tmp/work +cp /task/hello.rb /tmp/work/hello.rb +cd /tmp/work +ruby hello.rb