forked from p34709852/monkey
Implement cleanup button
Changed run monkey on island to not depend on ip
This commit is contained in:
parent
fedafa6583
commit
8bada60fcd
|
@ -9,11 +9,12 @@ import flask_restful
|
||||||
from cc.resources.monkey_download import get_monkey_executable
|
from cc.resources.monkey_download import get_monkey_executable
|
||||||
from cc.island_config import ISLAND_PORT
|
from cc.island_config import ISLAND_PORT
|
||||||
from cc.services.node import NodeService
|
from cc.services.node import NodeService
|
||||||
|
from cc.utils import local_ip_addresses
|
||||||
|
|
||||||
__author__ = 'Barak'
|
__author__ = 'Barak'
|
||||||
|
|
||||||
|
|
||||||
def run_local_monkey(island_address):
|
def run_local_monkey():
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import stat
|
import stat
|
||||||
|
@ -35,7 +36,7 @@ def run_local_monkey(island_address):
|
||||||
|
|
||||||
# run the monkey
|
# run the monkey
|
||||||
try:
|
try:
|
||||||
args = ["%s m0nk3y -s %s:%s" % (target_path, island_address, ISLAND_PORT)]
|
args = ["%s m0nk3y -s %s:%s" % (target_path, local_ip_addresses()[0], ISLAND_PORT)]
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
args = "".join(args)
|
args = "".join(args)
|
||||||
pid = subprocess.Popen(args, shell=True).pid
|
pid = subprocess.Popen(args, shell=True).pid
|
||||||
|
@ -51,8 +52,8 @@ class LocalRun(flask_restful.Resource):
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
body = json.loads(request.data)
|
body = json.loads(request.data)
|
||||||
if body.get('action') == 'run' and body.get('ip') is not None:
|
if body.get('action') == 'run':
|
||||||
local_run = run_local_monkey(island_address=body.get('ip'))
|
local_run = run_local_monkey()
|
||||||
return jsonify(is_running=local_run[0])
|
return jsonify(is_running=local_run[0])
|
||||||
|
|
||||||
# default action
|
# default action
|
||||||
|
|
|
@ -5,6 +5,10 @@ import {Link} from 'react-router-dom';
|
||||||
class StartOverPageComponent extends React.Component {
|
class StartOverPageComponent extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
cleaned: false
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -22,6 +26,12 @@ class StartOverPageComponent extends React.Component {
|
||||||
<p>
|
<p>
|
||||||
<a onClick={this.cleanup} className="btn btn-danger btn-lg">Reset Environment</a>
|
<a onClick={this.cleanup} className="btn btn-danger btn-lg">Reset Environment</a>
|
||||||
</p>
|
</p>
|
||||||
|
{ this.state.cleaned ?
|
||||||
|
<div className="alert alert-info">
|
||||||
|
<i className="glyphicon glyphicon-info-sign" style={{'marginRight': '5px'}}/>
|
||||||
|
Environment was reset successfully
|
||||||
|
</div>
|
||||||
|
: ''}
|
||||||
<p>
|
<p>
|
||||||
* BTW you can just continue and <Link to="/run-monkey">run more monkeys</Link> as you wish,
|
* BTW you can just continue and <Link to="/run-monkey">run more monkeys</Link> as you wish,
|
||||||
and see the results on the <Link to="/infection/map">Infection Map</Link> without deleting anything.
|
and see the results on the <Link to="/infection/map">Infection Map</Link> without deleting anything.
|
||||||
|
@ -30,6 +40,25 @@ class StartOverPageComponent extends React.Component {
|
||||||
</Col>
|
</Col>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
// TODO: fix
|
||||||
|
/*
|
||||||
|
this.setState({
|
||||||
|
cleaned: false
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
fetch('/api?action=reset')
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(res => {
|
||||||
|
if (res["status"] == "OK") {
|
||||||
|
// TODO: fix this
|
||||||
|
this.setState({
|
||||||
|
cleaned: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default StartOverPageComponent;
|
export default StartOverPageComponent;
|
||||||
|
|
Loading…
Reference in New Issue