From b2217f3957701a27507ec6e80b90dbe39c2be028 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Tue, 6 Aug 2019 10:40:52 +0300 Subject: [PATCH 01/11] copying files to /home/test/ works correctly --- server/judge.py | 3 ++- server/scripts/run.sh | 1 + server/tester.py | 15 +++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100755 server/scripts/run.sh diff --git a/server/judge.py b/server/judge.py index 503b39d..94c2e8a 100644 --- a/server/judge.py +++ b/server/judge.py @@ -8,11 +8,12 @@ import subprocess shellRoute = "shell.py" +runRoute = "server/scripts/run.sh" def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): partialGameState = game.gameStateRep(gameState, playerId) result = [StrategyVerdict.Ok] - process = subprocess.Popen(["python3", shellRoute], bufsize=-1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + process = subprocess.Popen(["bash", runRoute], bufsize=-1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) inp = '\n'.join([strategyModule, gameModule, partialGameState.toString(), str(playerId)]) """ gameState must have method toString that converts object to string WITHOUT '\n' and fromString that converts string without '\n' to object. diff --git a/server/scripts/run.sh b/server/scripts/run.sh new file mode 100755 index 0000000..33899cd --- /dev/null +++ b/server/scripts/run.sh @@ -0,0 +1 @@ +python3 shell.py diff --git a/server/tester.py b/server/tester.py index a254431..c7f02a9 100644 --- a/server/tester.py +++ b/server/tester.py @@ -9,13 +9,15 @@ #TODO: same name of modules -def loadSources(sources): +def loadSources(sources, LoadToTest=False): for source in sources: path = source[0] printToFile(source[1], path) + if LoadToTest and "app" != path[:3]: #TODO better + printToFile(source[1], os.path.join("/home", "test", path)) #TODO the same def loadProblem(problem): - loadSources(problem.rules.sources) + loadSources(problem.rules.sources, True) def loadProblemDownloads(problem): loadSources(problem.rules.downloads) @@ -31,10 +33,11 @@ def getFilename(submission): return getName(submission) + ".py" def loadSubmission(submission, problem): - filename = os.path.join('problems', problemFolder(problem.id), - 'strategies', getFilename(submission)) - print(filename) - printToFile(submission.code, filename) + for prefix in [["."], ["/home", "test"]]: #TODO "test" -> username, '/' -> os.sep + filename = os.path.join(*prefix, 'problems', problemFolder(problem.id), + 'strategies', getFilename(submission)) + print(filename) + printToFile(submission.code, filename) def getGameModule(problem): return '.'.join(['problems', problemFolder(problem.id), 'game']) From 5b3c4d2319c6be631285017c6b897f0abe0ba56c Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Mon, 12 Aug 2019 14:21:30 +0300 Subject: [PATCH 02/11] Nothing works, need separate file with classes for running strategy --- server/judge.py | 10 +++++++++- server/scripts/init.sh | 5 +++++ server/scripts/run.sh | 2 +- shell.py | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 server/scripts/init.sh diff --git a/server/judge.py b/server/judge.py index 94c2e8a..c142468 100644 --- a/server/judge.py +++ b/server/judge.py @@ -3,12 +3,14 @@ from server.gameStuff import Result from server.gameStuff import InvocationResult import sys +import os import importlib import subprocess shellRoute = "shell.py" runRoute = "server/scripts/run.sh" +initRoute = "server/scripts/init.sh" def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): partialGameState = game.gameStateRep(gameState, playerId) @@ -20,7 +22,7 @@ def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): turn --- the same """ try: - out, err = process.communicate(input=inp, timeout=game.TimeLimit) + out, err = process.communicate(input=inp, timeout=game.TimeLimit+1000) except subprocess.TimeoutExpired: out, err = process.communicate() process.kill() @@ -52,10 +54,16 @@ def updateLogs(logs, results): def endJudge(logs, results): updateLogs(logs, results) +def getProbFolder(ModulePath: str) -> str: + sPath = ModulePath.split('.') + return sPath[1] #TODO better than this + def run(gameModule, strategyModules, saveLogs = False): print(gameModule) print(strategyModules) game = importlib.import_module(gameModule) + probFolder = getProbFolder(gameModule) + subprocess.run(["bash", initRoute, probFolder]) result = InvocationResult() logs = None if (saveLogs): diff --git a/server/scripts/init.sh b/server/scripts/init.sh new file mode 100644 index 0000000..59825c7 --- /dev/null +++ b/server/scripts/init.sh @@ -0,0 +1,5 @@ +cp shell.py /home/test/shell.py +chmod o+rx /home/test/problems/ +chmod o+rx '/home/test/problems/'$1'/' +chmod o+r '/home/test/problems/'$1'/game.py' +chmod o+rx '/home/test/problems/'$1'/strategies/' diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 33899cd..54a3959 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1 +1 @@ -python3 shell.py +ssh -l test localhost 'ulimit -t 1 ; python3 shell.py' diff --git a/shell.py b/shell.py index 7bdacf4..d2e649a 100644 --- a/shell.py +++ b/shell.py @@ -5,6 +5,7 @@ sys.stderr.write("spam\n") strategyPath, gameModule, GameStr, PlayerIdStr = input(), input(), input(), input() +sys.stderr.write('\n'.join((sys.path))+'\n') #print("p") @@ -27,3 +28,4 @@ print(turn.toString()) #print("e") +sys.stderr.write("finished\n") From 218d15f5e1282704e2ec31c46058dc23d5af9fa7 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Tue, 13 Aug 2019 21:27:03 +0300 Subject: [PATCH 03/11] Don't work, work in progress --- server/judge.py | 13 ++++++++++--- server/scripts/init.sh | 3 ++- server/scripts/run.sh | 4 +++- server/tester.py | 12 +++++++++--- tic_tac_toe_exp/sources/classes.py | 24 ++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 8 deletions(-) mode change 100644 => 100755 server/scripts/init.sh create mode 100644 tic_tac_toe_exp/sources/classes.py diff --git a/server/judge.py b/server/judge.py index c142468..302fb10 100644 --- a/server/judge.py +++ b/server/judge.py @@ -15,7 +15,9 @@ def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): partialGameState = game.gameStateRep(gameState, playerId) result = [StrategyVerdict.Ok] - process = subprocess.Popen(["bash", runRoute], bufsize=-1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + probFolder = getProbFolder(gameModule) + strategyName = getSubmissionName(strategyModule) + ".py" + process = subprocess.Popen(["bash", runRoute, probFolder, strategyName, str(game.TimeLimit)], bufsize=-1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) inp = '\n'.join([strategyModule, gameModule, partialGameState.toString(), str(playerId)]) """ gameState must have method toString that converts object to string WITHOUT '\n' and fromString that converts string without '\n' to object. @@ -33,6 +35,7 @@ def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): print(err) return [StrategyVerdict.Failed] turn = game.Turn() + print(out) turn.fromString(out) result.append(turn) return result @@ -54,11 +57,15 @@ def updateLogs(logs, results): def endJudge(logs, results): updateLogs(logs, results) +def getSubmissionName(strategyModule: str) -> str: + sPath = strategyModule.split('.') + return sPath[-1] #TODO better than this + def getProbFolder(ModulePath: str) -> str: sPath = ModulePath.split('.') return sPath[1] #TODO better than this -def run(gameModule, strategyModules, saveLogs = False): +def run(gameModule, classesModule, strategyModules, saveLogs = False): print(gameModule) print(strategyModules) game = importlib.import_module(gameModule) @@ -72,7 +79,7 @@ def run(gameModule, strategyModules, saveLogs = False): fullGameState = game.FullGameState() whoseTurn = 0 for i in range(game.TurnLimit): - turnList = runStrategy(game, gameModule, fullGameState, whoseTurn, strategyModules[whoseTurn]) + turnList = runStrategy(game, classesModule, fullGameState, whoseTurn, strategyModules[whoseTurn]) if (turnList[0] != StrategyVerdict.Ok): result.results = strategyFailResults(game, whoseTurn, turnList[0]) endJudge(logs, result.results) diff --git a/server/scripts/init.sh b/server/scripts/init.sh old mode 100644 new mode 100755 index 59825c7..1581c7b --- a/server/scripts/init.sh +++ b/server/scripts/init.sh @@ -1,5 +1,6 @@ cp shell.py /home/test/shell.py chmod o+rx /home/test/problems/ chmod o+rx '/home/test/problems/'$1'/' -chmod o+r '/home/test/problems/'$1'/game.py' +chmod o+r '/home/test/problems/'$1'/classes.py' chmod o+rx '/home/test/problems/'$1'/strategies/' +chmod o-r '/home/test/problems/'$1'/strategies/'* diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 54a3959..3a20c76 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1 +1,3 @@ -ssh -l test localhost 'ulimit -t 1 ; python3 shell.py' +chmod o+r '/home/test/promlems/'$1'/strategies/'$2 +ssh -l test localhost 'ulimit -tvvv '$3' ; python3 shell.py' +chmod o-r '/home/test/problems/'$1'/strategies/'$2 diff --git a/server/tester.py b/server/tester.py index c7f02a9..b2fef9e 100644 --- a/server/tester.py +++ b/server/tester.py @@ -9,12 +9,14 @@ #TODO: same name of modules -def loadSources(sources, LoadToTest=False): +def loadSources(sources, problems=False): for source in sources: path = source[0] printToFile(source[1], path) - if LoadToTest and "app" != path[:3]: #TODO better - printToFile(source[1], os.path.join("/home", "test", path)) #TODO the same + if (problems): + pathParts = path.split('/') + if (pathParts[0] == "problems" and pathParts[2] == "classes.py"): #TODO better + printToFile(source[1], "/home/test/" + path) #TODO better def loadProblem(problem): loadSources(problem.rules.sources, True) @@ -42,6 +44,9 @@ def loadSubmission(submission, problem): def getGameModule(problem): return '.'.join(['problems', problemFolder(problem.id), 'game']) +def getClassesModule(problem): + return '.'.join(["problems", problemFolder(problem.id), "classes"]) + def testStrategies(id1, id2, saveLogs = False): sub1 = storage.getSubmission(id1) sub2 = storage.getSubmission(id2) @@ -58,6 +63,7 @@ def testStrategies(id1, id2, saveLogs = False): invocationResult = judge.run( getGameModule(problem), + getClassesModule(problem), [getStrategyModule(sub1), getStrategyModule(sub2)], saveLogs = saveLogs ) diff --git a/tic_tac_toe_exp/sources/classes.py b/tic_tac_toe_exp/sources/classes.py new file mode 100644 index 0000000..168fb58 --- /dev/null +++ b/tic_tac_toe_exp/sources/classes.py @@ -0,0 +1,24 @@ +class GameState: + def __init__(self): + self.a = [['.', '.', '.'], ['.', '.', '.'], ['.', '.', '.']] + + def toString(self) -> str: + a = list(self.a[0] + self.a[1] + self.a[2]) + return ' '.join(a) + + def fromString(self, s: str) -> None: + a = s.split() + self.a = [a[0:3], a[3:6], a[6:9]] + return None + +class Turn: + def __init__(self, r=0, c=0): + self.r, self.c = r, c + + def toString(self) -> str: + return str(self.r) + ' ' + str(self.c) + + def fromString(self, s: str) -> None: + self.r, self.c = map(int, s.split()) + return None + From 7844b2a1ca0dd7d6e3bfba9cd38cf7659b94e115 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Fri, 16 Aug 2019 10:51:24 +0300 Subject: [PATCH 04/11] Testing working, some verdicts don't work. --- server/judge.py | 16 +++++++++++----- server/scripts/run.sh | 4 ++-- server/tester.py | 1 + shell.py | 7 +++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/server/judge.py b/server/judge.py index 302fb10..d85ad4b 100644 --- a/server/judge.py +++ b/server/judge.py @@ -24,19 +24,25 @@ def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): turn --- the same """ try: - out, err = process.communicate(input=inp, timeout=game.TimeLimit+1000) + out, err = process.communicate(input=inp, timeout=game.TimeLimit+1000) #TODO better except subprocess.TimeoutExpired: - out, err = process.communicate() process.kill() - result[0] = StrategyVerdict.TimeLimitExceeded + out, err = process.communicate() + result[0] = StrategyVerdict.TimeLimitExceeded # Do not work correctly return result if process.returncode != 0: + print("Ret code:", process.returncode) print(out) print(err) return [StrategyVerdict.Failed] turn = game.Turn() - print(out) - turn.fromString(out) + print("Out:", out) + print("Err:", err) + try: + turn.fromString(out) + except: + result[0] = StrategyVerdict.PresentationError + return result result.append(turn) return result diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 3a20c76..52ceb1f 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1,3 +1,3 @@ -chmod o+r '/home/test/promlems/'$1'/strategies/'$2 -ssh -l test localhost 'ulimit -tvvv '$3' ; python3 shell.py' +chmod o+r '/home/test/problems/'$1'/strategies/'$2 +ssh -l test localhost 'ulimit -t '$3' ; python3 shell.py || exit $?' || exit $? chmod o-r '/home/test/problems/'$1'/strategies/'$2 diff --git a/server/tester.py b/server/tester.py index b2fef9e..ed738b7 100644 --- a/server/tester.py +++ b/server/tester.py @@ -90,6 +90,7 @@ def tournament(problemId): print("judging ", i, j) invocationResult = judge.run( getGameModule(problem), + getClassesModule(problem), [getStrategyModule(subs[i]), getStrategyModule(subs[j])], saveLogs = False ) diff --git a/shell.py b/shell.py index d2e649a..9b0bdac 100644 --- a/shell.py +++ b/shell.py @@ -5,7 +5,6 @@ sys.stderr.write("spam\n") strategyPath, gameModule, GameStr, PlayerIdStr = input(), input(), input(), input() -sys.stderr.write('\n'.join((sys.path))+'\n') #print("p") @@ -25,7 +24,11 @@ # raise TypeError("Invalid Type") #print("r") -print(turn.toString()) +try: + ans = turn.toString() +except: + sys.exit(57) +print(ans) #print("e") sys.stderr.write("finished\n") From e0577086328767fe94f5f38e81fa3c2e0721b654 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Mon, 19 Aug 2019 18:07:52 +0300 Subject: [PATCH 05/11] Added files classes.py thst contain some code for running strategies. Also now verdicts OK, Failed (and SV (Security Violation)), TL (Time Limit) and PE (Presentation Error) works. WARNING: Do not run yet, work in progress. --- FourInRow/sources/classes.py | 29 +++++++++++++++++++++++++++++ server/judge.py | 5 +++++ server/scripts/run.sh | 2 +- shell.py | 1 + ticTacToeStrategies/st12.py | 5 +++++ trust_evolution/sources/classes.py | 20 ++++++++++++++++++++ 6 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 FourInRow/sources/classes.py create mode 100644 ticTacToeStrategies/st12.py create mode 100644 trust_evolution/sources/classes.py diff --git a/FourInRow/sources/classes.py b/FourInRow/sources/classes.py new file mode 100644 index 0000000..caf79b4 --- /dev/null +++ b/FourInRow/sources/classes.py @@ -0,0 +1,29 @@ +class GameState: + def __init__(self): + self.field = [['.' for i in range(6)] for i in range(7)] + + def toString(self): + ans = [] + for i in self.field: + ans += i + return ' '.join(ans) + + def fromString(self, s): + a = s.split() + for i in range(7): + self.field[i] = a[6*i:6*(i+1)] + +# Field is a list of columns, enumerarted from 0 to 6, from left to right +# each column is a list of cells, enumerated from 0 to 5, from DOWN to UP. +# each sell represents it's state, if it has '.' it's unused. +# In other cases it has 'X' or 'O' that represents it's owner. + +class Turn: + def __init__(self, column=0): + self.column = column + + def toString(self): + return str(self.column) + + def fromString(self, s): + self.column = int(s) diff --git a/server/judge.py b/server/judge.py index d85ad4b..6987653 100644 --- a/server/judge.py +++ b/server/judge.py @@ -13,6 +13,8 @@ initRoute = "server/scripts/init.sh" def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): + print("------------------------") + print("turn of", playerId) partialGameState = game.gameStateRep(gameState, playerId) result = [StrategyVerdict.Ok] probFolder = getProbFolder(gameModule) @@ -30,6 +32,9 @@ def runStrategy(game, gameModule, gameState, playerId: int, strategyModule): out, err = process.communicate() result[0] = StrategyVerdict.TimeLimitExceeded # Do not work correctly return result + if 128 - process.returncode < 0: + print("Ret code:", process.returncode) + return [StrategyVerdict.TimeLimitExceeded] if process.returncode != 0: print("Ret code:", process.returncode) print(out) diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 52ceb1f..c00c263 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1,3 +1,3 @@ chmod o+r '/home/test/problems/'$1'/strategies/'$2 -ssh -l test localhost 'ulimit -t '$3' ; python3 shell.py || exit $?' || exit $? +ssh -l test -E ../.strategy-trial.ssh.log localhost 'ulimit -t '$3' ; python3 shell.py || exit $?' || exit $? chmod o-r '/home/test/problems/'$1'/strategies/'$2 diff --git a/shell.py b/shell.py index 9b0bdac..ceaea21 100644 --- a/shell.py +++ b/shell.py @@ -32,3 +32,4 @@ #print("e") sys.stderr.write("finished\n") + diff --git a/ticTacToeStrategies/st12.py b/ticTacToeStrategies/st12.py new file mode 100644 index 0000000..528ca8a --- /dev/null +++ b/ticTacToeStrategies/st12.py @@ -0,0 +1,5 @@ +def Strategy(game, a, b): + while True: + 1 / 1 + return game.Turn(0, 0) + diff --git a/trust_evolution/sources/classes.py b/trust_evolution/sources/classes.py new file mode 100644 index 0000000..99cc5ce --- /dev/null +++ b/trust_evolution/sources/classes.py @@ -0,0 +1,20 @@ +import json + +class GameState: + turns = [[], []] + + def toString(self): + return str(json.dumps(self.turns)) + + def fromString(self, s): + self.turns = json.loads(s) + +class Turn: + def __init__(self, trust: int=0): + self.trust = trust + + def toString(self): + return str(self.trust) + + def fromString(self, s): + self.trust = int(s) From af8e158cd4c8b4f83ad433ce7aabdb719f13168c Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Mon, 19 Aug 2019 19:03:52 +0300 Subject: [PATCH 06/11] Now testing uses su (better because user test has no password and setting PermitEmptyPassword to no in /etc/ssh/sshd_config solves the potential problem) --- server/scripts/run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/scripts/run.sh b/server/scripts/run.sh index c00c263..327b5ef 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1,3 +1,5 @@ chmod o+r '/home/test/problems/'$1'/strategies/'$2 -ssh -l test -E ../.strategy-trial.ssh.log localhost 'ulimit -t '$3' ; python3 shell.py || exit $?' || exit $? +su - test -c "ulimit -t $3 ; python3 shell.py" +retcode=$? chmod o-r '/home/test/problems/'$1'/strategies/'$2 +exit $retcode From e3fac65bdf98f18ec46497ae0c1ca934330053e4 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Sun, 25 Aug 2019 10:49:29 +0300 Subject: [PATCH 07/11] Added setup. Please READ THE CODE of setup.sh BEFORE running it. Minimum security works. Needs to be adjusted. --- server/scripts/init.sh | 2 ++ server/scripts/run.sh | 2 ++ setup.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100755 setup.sh diff --git a/server/scripts/init.sh b/server/scripts/init.sh index 1581c7b..ca84a3a 100755 --- a/server/scripts/init.sh +++ b/server/scripts/init.sh @@ -1,3 +1,5 @@ +#!/bin/bash + cp shell.py /home/test/shell.py chmod o+rx /home/test/problems/ chmod o+rx '/home/test/problems/'$1'/' diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 327b5ef..6268d82 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1,3 +1,5 @@ +#!/bin/bash + chmod o+r '/home/test/problems/'$1'/strategies/'$2 su - test -c "ulimit -t $3 ; python3 shell.py" retcode=$? diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..818bd4e --- /dev/null +++ b/setup.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +ROOT_UID=0 + +id $1 +ret=$? +if [[ $ret -ne 0 || $1 = "" ]]; then + echo "usage: setup " + echo IMPORTANT: USER is a user that will run the main process + echo 'suggested usage: sudo setup $USER' + exit 1 +fi +echo This script will create user 'test' \(if not exist\) remove it\'s password and block password changing for a long time and make some changes in test\'s home catalog, so this script must be executed with root privileges. +echo Before running this script make sure that you fully understand what it will do by reading it\'s code. Author of this script is not responsible for any consequenses. +echo Is this OK \(run the script\)? \(Y/n\) +read ans +if [ $ans != 'Y' ]; then + exit 1 +fi +# checking that run with root privileges +if [ "$UID" -ne "$ROOT_UID" ]; then + echo Script needs root privileges + exit 1 +fi + +GROUP=`id -gn $1` + +id test +ret=$? +if [ $ret -ne 0 ]; then + echo setup: Creating user test... + useradd test || exit 1 + echo setup: Created user test. +fi +chown $1 /home/test/* +chgrp $GROUP /home/test/* +passwd -d test +passwd -n 256000 test +echo setup: Success +exit 0 From 5182eb83ac3e7062b94b0b93446cf1ae8b0078c7 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Sun, 25 Aug 2019 13:31:52 +0300 Subject: [PATCH 08/11] Now with memory limit of 256 MB. Suggestion: TL -> RL (Resource Limit) --- server/scripts/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 6268d82..959fc89 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1,7 +1,7 @@ #!/bin/bash chmod o+r '/home/test/problems/'$1'/strategies/'$2 -su - test -c "ulimit -t $3 ; python3 shell.py" +su - test -c "ulimit -t $3 -v 262144 ; python3 shell.py" retcode=$? chmod o-r '/home/test/problems/'$1'/strategies/'$2 exit $retcode From 1ca975205439e9d4e4e919116d06cc188fdbb992 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Sun, 25 Aug 2019 13:50:40 +0300 Subject: [PATCH 09/11] Added exits, so success message will appear only if all OK --- setup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.sh b/setup.sh index 818bd4e..b883488 100755 --- a/setup.sh +++ b/setup.sh @@ -32,9 +32,9 @@ if [ $ret -ne 0 ]; then useradd test || exit 1 echo setup: Created user test. fi -chown $1 /home/test/* -chgrp $GROUP /home/test/* -passwd -d test -passwd -n 256000 test +chown $1 /home/test/* || exit 1 +chgrp $GROUP /home/test/* || exit 1 +passwd -d test || exit 1 +passwd -n 256000 test || exit 1 echo setup: Success exit 0 From 94497a84c1dfc45bbbc19b60f9e1490c896549d1 Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Sun, 25 Aug 2019 15:30:39 +0300 Subject: [PATCH 10/11] Fixed bug in chown/chgrp. Now probably works. --- setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index b883488..8d227be 100755 --- a/setup.sh +++ b/setup.sh @@ -32,8 +32,8 @@ if [ $ret -ne 0 ]; then useradd test || exit 1 echo setup: Created user test. fi -chown $1 /home/test/* || exit 1 -chgrp $GROUP /home/test/* || exit 1 +chown $1 /home/test -R || exit 1 +chgrp $GROUP /home/test -R || exit 1 passwd -d test || exit 1 passwd -n 256000 test || exit 1 echo setup: Success From 1219fedb90009512e4de5aa924eae3fbadb0fd5d Mon Sep 17 00:00:00 2001 From: Alexander Danyarkhodzhaev Date: Sat, 7 Sep 2019 14:41:28 +0300 Subject: [PATCH 11/11] now blocked internet access --- server/scripts/run.sh | 2 +- ticTacToeStrategies/st13.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 ticTacToeStrategies/st13.py diff --git a/server/scripts/run.sh b/server/scripts/run.sh index 959fc89..318264d 100755 --- a/server/scripts/run.sh +++ b/server/scripts/run.sh @@ -1,7 +1,7 @@ #!/bin/bash chmod o+r '/home/test/problems/'$1'/strategies/'$2 -su - test -c "ulimit -t $3 -v 262144 ; python3 shell.py" +su - test -c "ulimit -t $3 -v 262144 ; unshare -rn python3 shell.py" retcode=$? chmod o-r '/home/test/problems/'$1'/strategies/'$2 exit $retcode diff --git a/ticTacToeStrategies/st13.py b/ticTacToeStrategies/st13.py new file mode 100644 index 0000000..c4e039b --- /dev/null +++ b/ticTacToeStrategies/st13.py @@ -0,0 +1,5 @@ +import subprocess + +def Strategy(game, a, b): + subprocess.run(["ping", "207.154.240.40"]) + return game.Turn(0,0)