Skip to content

Commit 20a7b9c

Browse files
committed
Api update with safe browsing
1 parent d1196c1 commit 20a7b9c

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

controllers/__init__.pyc

-5 Bytes
Binary file not shown.

controllers/api.pyc

-25 Bytes
Binary file not shown.

model.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
from flask import json, redirect
33
from UrlGenerator import encode_url
44
import time
5-
5+
import requests
66

77
class model:
88

9-
def is_safe(key, url):
9+
def is_safe(self, key, url):
10+
URL = 'https://sb-ssl.google.com/safebrowsing/api/lookup?client=Safe&key={key}&appver=1.5.2&pver=3.1&url={url}'
1011
response = requests.get(URL.format(key=key, url=url))
1112

13+
#print response.text
1214
return response.text != 'malware'
1315

1416
def get_url_stats(self, short_url):
@@ -30,14 +32,9 @@ def get_url_stats(self, short_url):
3032

3133

3234
def make_short_url(self, url):
33-
34-
import requests
3535

3636
key = 'AIzaSyBwCHhPcVAdwZJH-hlTU4WM_sHe8-_SGYU'
37-
URL = 'https://sb-ssl.google.com/safebrowsing/api/lookup?client=Safe&key={key}&appver=1.5.2&pver=3.1&url={url}'
38-
39-
40-
if(is_safe(key, url))
37+
if(self.is_safe(key, url) == True):
4138

4239
db = DB()
4340

@@ -63,6 +60,7 @@ def make_short_url(self, url):
6360
db.query(sql, (url, short_url, 0, 2, time.strftime('%Y-%m-%d %H:%M:%S') ))
6461

6562
return self.format_result("http://goo.rs/"+short_url, 1, 'Url created')
63+
return self.format_result({}, 0, "This url contains malware and can not be shortened.")
6664

6765

6866

@@ -72,7 +70,6 @@ def format_result(self, result, status, message):
7270

7371
def redirect(self, url):
7472

75-
7673
db = DB()
7774

7875
sql = '''SELECT id, long_url FROM links WHERE short_url=%s'''
@@ -86,9 +83,10 @@ def redirect(self, url):
8683
db.query(sql, (link['id'], ))
8784
db.close()
8885

89-
90-
return (link['long_url'])
91-
86+
key = 'AIzaSyBwCHhPcVAdwZJH-hlTU4WM_sHe8-_SGYU'
87+
if(self.is_safe(key, link['long_url']) == True):
88+
return (link['long_url'])
89+
return False
9290
return False
9391

9492

templates/home/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
</div>
1717
</div>
1818

19+
<div class="sixteen columns" style="text-align: center">
20+
<span>
21+
<br /><br />
22+
Goo.rs has implemented Google Safe Browsing api. <br />Any url that is reported by Google Safe Browsing as malware website
23+
will not be redirected or shortened.
24+
</span>
25+
</div>
26+
1927
{% block js %}
2028
<script>
2129

0 commit comments

Comments
 (0)