Skip to content

Commit

Permalink
fixed webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4f53 committed Nov 14, 2023
1 parent 0fae319 commit 0bac80b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 0 additions & 2 deletions file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ def append_to_output_file(data, file_name):
loaded_json = json.loads(read_file.read())
except: # No file
print ("\nCreating new file named \'" + file_name + "\' and writing to it.")

with open(file_name, 'w') as write_file:
loaded_json.append(data)
if len(octopii.notifyURL) > 0: webhook.push_data(json.dumps(loaded_json, indent=4), octopii.notifyURL)
write_file.write(json.dumps(loaded_json, indent=4))

except:
Expand Down
10 changes: 4 additions & 6 deletions octopii.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import json, textract, sys, urllib, cv2, os, json, shutil, traceback
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from pdf2image import convert_from_path
import image_utils, file_utils, text_utils
import image_utils, file_utils, text_utils, webhook

model_file_name = 'models/other_pii_model.h5'
labels_file_name = 'models/other_pii_model.txt'
Expand Down Expand Up @@ -112,7 +112,6 @@ def search_pii(file_path):


if __name__ in '__main__':

if len(sys.argv) == 1:
print_logo()
help_screen()
Expand All @@ -123,10 +122,8 @@ def search_pii(file_path):
# Check for the -notify flag
notify_index = sys.argv.index('--notify') if '--notify' in sys.argv else -1

if notify_index != -1 and notify_index + 1 < len(sys.argv):
notifyURL = sys.argv[notify_index + 1]
else:
notifyURL = None
if notify_index != -1 and notify_index + 1 < len(sys.argv): notifyURL = sys.argv[notify_index + 1]
else: notifyURL = None

rules=text_utils.get_regexes()

Expand Down Expand Up @@ -206,6 +203,7 @@ def search_pii(file_path):
results = search_pii (file_path)
print(json.dumps(results, indent=4).replace("{", "").replace("}", "").replace(" ", ""))
file_utils.append_to_output_file(results, output_file)
if notifyURL != None: webhook.push_data(json.dumps(results), notifyURL)
print ("\nOutput saved in " + output_file)

except textract.exceptions.MissingFileError: print ("\nCouldn't find file '" + file_path + "', skipping...")
Expand Down
36 changes: 22 additions & 14 deletions webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,27 @@
SOFTWARE.
"""

import requests

import requests
import json

def push_data(data: str, url: str):
headers = {'Content-type': 'application/json'}
if "discord" in url: data = "{\"content\":\"{" + data + "}\"}"
else: data = "{\"text\":\"{" + data + "}\"}"

req = requests.post (
url, # Example: https://hooks.slack.com/services/<>/<>/<>
headers=headers,
data=data,
timeout=7
)

if req is not None and req.status_code == 200: print('Scan results sent to webhook.')
else: print('Couldn\'t send scan results to webhook. Reason: ' + req.text)

if "discord" in url:
payload = {"content": data}
else:
payload = {"text": data}

try:
req = requests.post(
url,
headers=headers,
json=payload, # Use the json parameter to send JSON data
timeout=7
)

req.raise_for_status() # Raise an HTTPError for bad responses

print('Scan results sent to webhook.')
except requests.exceptions.RequestException as e:
print(f'Couldn\'t send scan results to webhook. Reason: {e}')

0 comments on commit 0bac80b

Please sign in to comment.