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

Fixed Counter #26

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ def counter_data(total,phishing,safe_site,reported,mode='r'):
if mode == 'w':
with open('counter_data.txt','w') as w_count:
w_count.write(f"{total} {phishing} {safe_site} {reported}")
else:
with open('counter_data.txt') as r_count:
data_read = [r_count.read().split(' ')]
return data_read
w_count.flush()
return True

def mysqldata_insert(seurl,inurl): # For appending values to reports_data table
try:
Expand All @@ -52,12 +50,16 @@ def mysqldata_insert(seurl,inurl): # For appending values to reports_data table

@app.route("/") # index page
def index():
for i in counter_data(total=total,phishing=phishing,safe_site=safe_site,reported=reported):
total_scanned = int(i[0])
phishing_sites = int(i[1])
safe_sites = int(i[2])
reported_sites = int(i[3])
# for i in counter_data(total=total,phishing=phishing,safe_site=safe_site,reported=reported):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the commented piece of code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore

# total_scanned = int(i[0])
# phishing_sites = int(i[1])
# safe_sites = int(i[2])
# reported_sites = int(i[3])
with open('counter_data.txt') as file:
total_scanned,phishing_sites,safe_sites,reported_sites=(file.read()).split()

counter = [['Sites Scanned',total_scanned],['Safe Sites',safe_sites],['Phishing Sites',phishing_sites],['Sites Reported',reported_sites]]

try:
connect = mysql.connect() # for connecting to the database
cursor = connect.cursor() # cursor to execute mysql queries
Expand All @@ -71,11 +73,13 @@ def index():
lis2 = list(db_output2) # converting tuple to list
lis2.sort() # sorting the list
countrydata = [["SELECT YOUR COUNTRY","select"]]+lis2 # appending the list to the list

return render_template("index.html",selecturl=selecturl,countrydata=countrydata,counterdata=counter) # selecturl sends list containing list of real sites
except Exception as e:
print(e)
selecturl = [["Error Occured","select"]] # if error occured while fetching data from the database
countrydata = [["Error Occured","select"]] # if error occured while fetching data from the database

return render_template("index.html",selecturl=selecturl,countrydata=countrydata,counterdata=counter) # selecturl sends error as it failed to get data from the database
return redirect('/')

Expand All @@ -95,10 +99,12 @@ def check():
if output is True:
mysqldata_insert(seurl,inurl) # For appending data if it is a phising site
phishing += 1
counter_data(total,phishing,safe_site,'w')
counter_data(total,phishing,safe_site,reported,'w')
VFXGamer marked this conversation as resolved.
Show resolved Hide resolved
print('Updated')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the print statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore

return redirect('/phishing') # Redirects to It is PHISHING SITE
safe_site += 1
counter_data(total,phishing,safe_site,'w')
counter_data(total,phishing,safe_site,reported,'w')

return redirect('/safe') # Redirects to It is SAFE SITE
return redirect('/') # Redirects to home page if values are not entered

Expand All @@ -107,11 +113,12 @@ def check():
def reports():
global reported
try:
for i in counter_data(total=total,phishing=phishing,safe_site=safe_site,reported=reported):
total_scanned = int(i[0])
phishing_sites = int(i[1])
safe_sites = int(i[2])
reported_sites = int(i[3])
with open('counter_data.txt') as file:
total_scanned, phishing_sites, safe_sites, reported_sites = (file.read()).split()

counter = [['Sites Scanned', total_scanned], ['Safe Sites', safe_sites], ['Phishing Sites', phishing_sites],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore

['Sites Reported', reported_sites]]

counter = [['Sites Scanned',total_scanned],['Safe Sites',safe_sites],['Phishing Sites',phishing_sites],['Sites Reported',reported_sites]]
connect = mysql.connect() # for connecting to the database
cursor = connect.cursor() # cursor to execute mysql queries
Expand All @@ -121,6 +128,7 @@ def reports():
report = list(db_output) if list(db_output) else []
reported = report[-1][0] if report else 0
counter_data(total=total,phishing=phishing,safe_site=safe_site,reported=reported,mode='w')

return render_template("reports.html",head=header,reports=report,counterdata=counter) # header for column names and reports for rows/site data
except Exception as e:
print(e)
Expand Down Expand Up @@ -176,11 +184,12 @@ def api():
if store == 'True': # String as the input can be made to anything and to overcoming error if the input is coverted to boolean before filtering
if output is True:
phishing += 1
counter_data(total,phishing,safe_site,'w')
counter_data(total,phishing,safe_site,reported,'w')
mysqldata_insert(seurl,inurl) # To adding data to the database
return jsonify({'Input Url':inurl,'Orginal Url':seurl,'Phishing Site':output,'Data Saved':bool(store),'Region':country}) # API response with data saved information
safe_site += 1
counter_data(total,phishing,safe_site,'w')
counter_data(total,phishing,safe_site,reported,'w')

return jsonify({'Input Url':inurl,'Orginal Url':seurl,'Phishing Site':output,'Data Saved':bool(store),'Region':country}) # API response with data saved information
return jsonify({'Input Url':inurl,'Orginal Url':seurl,'Phishing Site':output,'Region':country}) # API response if values are not saved
return render_template('api.html') # Redirecting to reports page to show that changes were made successfully
Expand Down
2 changes: 1 addition & 1 deletion phishbuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def comparing_url(url_phish,url_org,country="com"):
return output_comparison # Returns 'True' / 'False'

if __name__ == "__main__":
print(comparing_url('input.url','orginal_domain.name','country'))
print(comparing_url('input.url','orginal_domain.name','country'))