Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions Kashira/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
from kubernetes import config, client
from kubernetes.stream import stream
from flask import Flask
import os
import zipfile
import subprocess
import pyinotify
import threading
import re
import subprocess

app = Flask(__name__)

Expand Down Expand Up @@ -34,5 +41,32 @@ def pod_executor(command, pod_name, pod_namespace):
def hello():
return "Hello, world!"

if __name__ == '__main__':
app.run()
class EventHandler(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
filepath = event.pathname
regex = r"/kashira_(\w+)\.tar\.gz$"
match = re.search(regex, filepath)
if match:
NameOfChallenge = match.group(1)
cmd=["setup",NameOfChallenge]
subprocess.run(cmd)
else:
print("Challenge name does not match specified format: ",filepath)

def start_notifier():
wm = pyinotify.WatchManager()
mask = pyinotify.IN_MODIFY
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch("/opt/kashira/", mask, rec=False)
notifier.loop()

# TODO: Add metrics/monitoring functionality
if __name__ == "__main__":
os.chmod("setup-script.sh", 0o755)
os.system("bash ./setup-script.sh")
os.system("rm -rf setup-script.sh")
os.system("rm -rf /opt/kashira/app.py")
t = threading.Thread(target=start_notifier)
t.start()
app.run('0.0.0.0', os.environ['DAEMON_PORT'])
7 changes: 6 additions & 1 deletion Kashira/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
kubernetes
Flask
Flask
flask
pytest
requests
pyinotify
thread6
4 changes: 4 additions & 0 deletions Kashira/src/setup-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cd flag-data
mv /opt/kashira/setup.sh /usr/bin/setup
chmod +x /usr/bin/setup
rm -rf /opt/kashira/requirements.txt
5 changes: 5 additions & 0 deletions Kashira/src/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
source /etc/profile
tar -xf "/opt/kashira/kashira_${1}.tar.gz" -C /opt/kashira/flag-data
rm -rf "/opt/kashira/kashira_${1}.tar.gz"

40 changes: 37 additions & 3 deletions Kissaki/src/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
from flask import Flask
from flask import Flask, request
import os
import zipfile
import subprocess
import pyinotify
import threading
import re
import subprocess

app = Flask(__name__)

@app.route('/')
def hello():
return "Hello, world!"

if __name__ == '__main__':
app.run()
class EventHandler(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
filepath = event.pathname
regex = r"/kissaki_(\w+)\.tar\.gz$" #checks for file type to be kissaki_<type-of-challenge>_<name>.tar.gz
match = re.search(regex, filepath)
if match:
NameOfChallenge = match.group(1)
cmd=["setup",NameOfChallenge]
subprocess.run(cmd)
else:
print("Challenge name does not match specified format: ",filepath)

def start_notifier():
wm = pyinotify.WatchManager()
mask = pyinotify.IN_MODIFY
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch("/opt/kissaki/", mask, rec=False)
notifier.loop()

# TODO: Add metrics/monitoring functionality
if __name__ == "__main__":
os.chmod("setup-script.sh", 0o755)
os.system("bash ./setup-script.sh")
os.system("rm -rf setup-script.sh")
os.system("rm -rf /opt/kissaki/app.py")
t = threading.Thread(target=start_notifier)
t.start()
app.run('0.0.0.0', os.environ['DAEMON_PORT'])
6 changes: 5 additions & 1 deletion Kissaki/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
kubernetes
Flask
Flask
pytest
requests
pyinotify
thread6
4 changes: 4 additions & 0 deletions Kissaki/src/setup-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cd challenge-data
mv /opt/kissaki/setup.sh /usr/bin/setup
chmod +x /usr/bin/setup
rm -rf /opt/kissaki/requirements.txt
5 changes: 5 additions & 0 deletions Kissaki/src/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
source /etc/profile
tar -xf "/opt/kissaki/kissaki_${1}.tar.gz" -C /opt/kissaki/challenge-data
rm -rf "/opt/kissaki/kissaki_${1}.tar.gz"

3 changes: 1 addition & 2 deletions Tsuka/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def process_IN_MODIFY(self, event):
subprocess.run(cmd)
else:
print("Challenge name does not match specified format: ",filepath)


def start_notifier():
wm = pyinotify.WatchManager()
Expand All @@ -57,7 +56,7 @@ def start_notifier():
wdd = wm.add_watch("/opt/katana/", mask, rec=False)
notifier.loop()

# TODO: add metrics/monitoring functionality
# TODO: Add metrics/monitoring functionality
if __name__ == "__main__":
os.chmod("setup-script.sh", 0o755)
os.system("bash ./setup-script.sh")
Expand Down
3 changes: 1 addition & 2 deletions Tsuka/src/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source /etc/profile
if [ ! -d "/opt/katana/challenge/${2}" ]; then
mkdir "/opt/katana/challenge/${2}"
fi
tar -xf "/opt/katana/katana_${2}_${1}.tar.gz" -C /opt/katana/challenge/${2}
tar -zxf "/opt/katana/katana_${2}_${1}.tar.gz" -C /opt/katana/challenge/${2}
rm -rf "/opt/katana/katana_${2}_${1}.tar.gz"
cd "/opt/katana/challenge/${2}/${1}"
if [ ! -d "/opt/katana/challenge/${2}/${1}/.git" ]; then
Expand All @@ -16,7 +16,6 @@ git checkout master
git add .
git commit -m "${1} challenge of $USERNAME"
git push -u origin master -f

curl -H "Content-Type: application/json" -X POST -d '{ "type": "gogs", "config": { "url": "'"$BACKEND_URL"'","content_type": "json"},"events": ["push"],"active": true}' "http://$GOGS/api/v1/repos/$USERNAME/${1}/hooks?token=$PASSWORD"
curl -X PUT -H "Authorization: token $PASSWORD" -H "Content-Type: application/json" -d '{"permission": "admin"}' http://$GOGS/api/v1/repos/$USERNAME/${1}/collaborators/$ADMIN
fi