forked from p15670423/monkey
Finish up hooking frontend and backend for export config
This commit is contained in:
parent
46408e6d32
commit
f4b5d341cf
|
@ -11,7 +11,7 @@ from monkey_island.cc.services.utils.config_encryption import encrypt_config
|
||||||
class ConfigurationExport(flask_restful.Resource):
|
class ConfigurationExport(flask_restful.Resource):
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def get(self):
|
def get(self):
|
||||||
return {"encrypted_config": self.config_to_return}
|
return {"to_export": self.config_to_return, "is_plaintext": self.is_plaintext}
|
||||||
|
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def post(self):
|
def post(self):
|
||||||
|
@ -21,8 +21,10 @@ class ConfigurationExport(flask_restful.Resource):
|
||||||
plaintext_config = ConfigService.get_config()
|
plaintext_config = ConfigService.get_config()
|
||||||
|
|
||||||
self.config_to_return = plaintext_config
|
self.config_to_return = plaintext_config
|
||||||
|
self.is_plaintext = True
|
||||||
if should_encrypt:
|
if should_encrypt:
|
||||||
password = data["password"]
|
password = data["password"]
|
||||||
self.config_to_return = encrypt_config(plaintext_config, password)
|
self.config_to_return = encrypt_config(plaintext_config, password)
|
||||||
|
self.is_plaintext = False
|
||||||
|
|
||||||
return self.get()
|
return self.get()
|
||||||
|
|
|
@ -15,6 +15,7 @@ def encrypt_config(config: Dict, password: str) -> str:
|
||||||
pyAesCrypt.encryptStream(
|
pyAesCrypt.encryptStream(
|
||||||
plaintext_config_stream, ciphertext_config_stream, password, BUFFER_SIZE
|
plaintext_config_stream, ciphertext_config_stream, password, BUFFER_SIZE
|
||||||
)
|
)
|
||||||
|
|
||||||
ciphertext_config_bytes = str(ciphertext_config_stream.getvalue())
|
ciphertext_config_bytes = str(ciphertext_config_stream.getvalue())
|
||||||
return ciphertext_config_bytes
|
return ciphertext_config_bytes
|
||||||
|
|
||||||
|
|
|
@ -35,11 +35,17 @@ const ConfigExportModal = (props: Props) => {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res);
|
let configToExport = res['to_export'];
|
||||||
const configAsBinary = new Blob([res['encrypted_config']]);
|
if (res['is_plaintext'] === true) {
|
||||||
|
const configAsBinary = new Blob([configToExport], {type: 'text/plain;charset=utf-8'});
|
||||||
FileSaver.saveAs(configAsBinary, 'monkey.conf');
|
FileSaver.saveAs(configAsBinary, 'monkey.conf');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const configAsBinary = new Blob([configToExport.slice(2, -1)]);
|
||||||
|
FileSaver.saveAs(configAsBinary, 'monkey.conf');
|
||||||
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue