Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow upload ruleset files #850

Merged
merged 15 commits into from
Oct 16, 2019
50 changes: 50 additions & 0 deletions SplunkAppForWazuh/appserver/controllers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""


from . import api
import jsonbak
import requestsbak
import uuid
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self):
self.db = database()
self.config = self.get_config_on_memory()
self.timeout = int(self.config['timeout'])
self.wazuh_api = api.api()
self.session = requestsbak.Session()
self.session.trust_env = False
except Exception as e:
Expand Down Expand Up @@ -511,6 +513,54 @@ def check_daemons(self, url, auth, verify, check_cluster):
self.logger.error("manager: Error checking daemons: %s" % (e))
raise e

@expose_page(must_login=False, methods=['POST'])
def upload_file(self, **kwargs):
# Only rules files are uploaded currently
self.logger.debug("manager: Uploading file(s)")
try:
# Get file name and file content
split_file = str(kwargs["file"]).split('\', \'')
file_name = split_file[1]
file_content = split_file[2]
file_content = file_content[:len(file_content)-2]
file_content2 = file_content

# Get path
dest_path = kwargs["path"]


# Get current API data
opt_id = kwargs["apiId"]
current_api_json = self.db.get(opt_id)
current_api_json = jsonbak.loads(current_api_json)
opt_username = str(current_api_json["data"]["userapi"])
opt_password = str(current_api_json["data"]["passapi"])
opt_base_url = str(current_api_json["data"]["url"])
opt_base_port = str(current_api_json["data"]["portapi"])
opt_cluster = False
if "filterType" in current_api_json["data"] and current_api_json["data"]["filterType"] == 'cluster.name':
opt_cluster = True

# API requests auth
auth = requestsbak.auth.HTTPBasicAuth(opt_username, opt_password)
verify = False
url = opt_base_url + ":" + opt_base_port


if dest_path and dest_path == 'etc/lists/':
file_content = file_content.replace('\\n',"\n")
result = self.session.post(url + '/manager/files?path='+ dest_path +file_name, data=file_content, headers= {"Content-type": "application/octet-stream"}, auth=auth, timeout=20, verify=verify)
else:
file_content = file_content.replace('\\n','')
result = self.session.post(url + '/manager/files?path='+ dest_path +file_name, data=file_content, headers= {"Content-type": "application/xml"}, auth=auth, timeout=20, verify=verify)
result = jsonbak.loads(result.text)
if 'error' in result and result['error'] != 0:
return jsonbak.dumps({"status": "400", "text": "Error adding file: %s. Cause: %s" % (file_name,result["message"])})
return jsonbak.dumps({"status": "200", "text": "File %s was updated successfully. " % file_name})
except Exception as e:
self.logger.error("manager: Error trying to upload a file(s): %s" % (e))


def get_config_on_memory(self):
try:
self.logger.debug("manager: Getting configuration on memory.")
Expand Down
149 changes: 148 additions & 1 deletion SplunkAppForWazuh/appserver/static/css/styles/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
border-color: #396e3e !important;
}

.agreeBtn:hover {
background-color: #43884a !important;
}

.cancelBtn {
color: #000000 !important;
background-color: #d9d9d9 !important;
Expand Down Expand Up @@ -2280,7 +2284,7 @@ md-tabs.md-default-theme md-ink-bar, md-tabs md-ink-bar {
margin: 2px 15px 0px -500px;
height: auto;
}
}

.link-disabled {
cursor: not-allowed;
opacity: 0.5;
Expand Down Expand Up @@ -2436,6 +2440,149 @@ wazuh-card-slider {
width: 100% ;
}

.euiButton .euiButton__content {
height: 100%;
width: 100%;
vertical-align: middle;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
padding: 0 12px;
}

.euiButton:disabled .euiButton__content {
pointer-events: auto;
cursor: not-allowed;
}

.table-striped>tbody>tr:nth-child(odd)>td, .table-striped>tbody>tr:nth-child(odd)>th {
background-color: white;
}

.link-table {
margin-right:10px;
font-size: 16px;
padding-left: 10px;
}

.link-table:hover {
text-decoration: underline
}


.euiTextArea:focus {
background-color: rgb(250,250,250);
border-bottom: 2px solid rgb(63, 126, 67);
}

::-webkit-scrollbar {
width: 7px;
height: 7px;
}

/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}

/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
border-radius: 10px;
}

/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}


.logtest-fullscreen {
position: fixed !important;
top: 0;
left: 0;
overflow: hidden;
height: 100% !important;
width: 100% !important;
max-width: 100% !important;
max-height: 100% !important;
z-index: 100;
}
.dz-filename {
padding-top: 18px !important;
}

.dropzone .dz-preview .dz-progress {
margin-top: -18px !important;
}

.dropzone.dz-clickable {
cursor: pointer;
background-color: #b4c5b573;
border: 1px solid rgba(0, 0, 0, 0.12);
}


.wz-popover-wrapper {
position: relative;
top: 55px;
right: -92%;
display: inline-block;
z-index: 100;
}
.wz-popover-content {
opacity: 0;
z-index:100;
visibility: hidden;
position: absolute;
left: -350px;
transform: translate(0, 10px);
background-color: #ffffff;
padding: 1rem 1.5rem 1.5rem 1.5rem;
box-shadow: 1px 2px 4px 1px rgba(0, 0, 0, 0.76);
width: 350px;
}
.wz-popover-content:before {
content: "";
position: fixed;
width: 10px;
height: 10px;
background: white;
transform: rotate(45deg);
top: -6px;
z-index: 1 !important;
left: 326px;
border-top: 1px solid #80808085;
border-left: 1px solid #80808085;
}
.wz-popover-wrapper .wz-popover-content {
z-index: 10;
opacity: 1;
visibility: visible;
height:auto;
transform: translate(0, 10px);
}


.wz-popover-message {
text-align: center;
}


.wz-success-message {
color: rgb(32, 121, 32) !important
}

.wz-error-message {
color: rgb(173, 16, 16) !important
}

.wz-min-height-40 {
min-height: 40px !important;
}
7 changes: 6 additions & 1 deletion SplunkAppForWazuh/appserver/static/css/styles/component.css
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ md-chip {
flex-grow: 1;
}

.euiButtonIcon--primary>.euiIcon:hover {
padding-top:1px;
border-bottom: 1px solid;
}

.euiButtonIcon {
font-family: "Inter UI", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-weight: 400;
Expand Down Expand Up @@ -342,7 +347,7 @@ md-chip {
}

.euiButtonIcon--primary {
color: #006BB4;
color: rgba(34, 129, 55, 0.767);
}

/* DEV TOOLS */
Expand Down
2 changes: 2 additions & 0 deletions SplunkAppForWazuh/appserver/static/css/styles/dropzone.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions SplunkAppForWazuh/appserver/static/css/styles/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
margin: 8px 8px 8px 0px;
}

.wz-margin-8 {
margin: 8px;
}

.wz-margin-right-15 {
margin-right: 15px;
}
Expand Down
3 changes: 2 additions & 1 deletion SplunkAppForWazuh/appserver/static/css/styles/loader.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
@import "wz_tooltips.css";
@import "xml-editor.css";
@import "wz-multiple-selector.css";
@import "wz-add-filter-chip.css";
@import "wz-add-filter-chip.css";
@import "dropzone.css";
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ define(['../module'], function(module) {
.state('manager', {
templateUrl:
BASE_URL +
'static/app/SplunkAppForWazuh/js/controllers/management/welcome/manager-welcome.html'
'static/app/SplunkAppForWazuh/js/controllers/management/welcome/manager-welcome.html',
onEnter: () => {
window.sessionStorage.showLogtest = false
}
})
// Manager - Monitoring
.state('mg-monitoring', {
Expand Down
Loading