This repository was archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrctf.py
72 lines (47 loc) · 1.9 KB
/
rctf.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import os, sys
from . import execute, config, logging
class rCTF:
def __init__(self, install_path = '/opt/rctf/'):
if not install_path.endswith('/'):
install_path += '/'
self.install_path = install_path
self._default_config_path = install_path + '.config.json'
self._dotenv_path = install_path + '.env'
def start(self):
os.chdir(self.install_path)
if not execute('docker-compose --no-ansi up -d --build', environ = self.get_env()):
logging.fatal('Failed to start rCTF instance.')
return False
return True
def stop(self):
os.chdir(self.install_path)
if not execute('docker-compose --no-ansi down', environ = self.get_env()):
logging.fatal('Failed to stop rCTF instance.')
return False
return True
def upgrade(self):
os.chdir(self.install_path)
# XXX: is there a way to make this not error if it fails?
self.down()
if not execute('git pull'):
logging.fatal('Failed to pull latest from repository.')
return False
if not execute('docker-compose --no-ansi build --no-cache', environ = self.get_env()):
logging.fatal('Failed to rebuild docker image.')
return False
return True
def get_config(self, path = None, update_config = False):
return config.Config(path or self._default_config_path).read(update_config = update_config)
def __getattr__(self, name):
if self.name == 'config':
# return default config path
return self.get_config()
else:
# default behaviour
raise AttributeError
# merges os.environ and configuration environ
def get_env(self):
environ = self.get_config()._get_as_environ()
environ.update(os.environ.copy())
return environ