Created
January 19, 2015 21:33
-
-
Save anonymous/a7a00ba08c16d26eb663 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import psycopg2 | |
def GetListInSQL(): | |
try: | |
conn = psycopg2.connect(database="db1023250_fssip", user="u1023250_fssip", password="ampersantPiNgVi237m273", host="77.221.130.141", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
idn = 0; | |
cur.execute("SELECT count(ip) as cnt from firewall where id_status=0") | |
rows = cur.fetchall() | |
if len(rows)>0: | |
for row in rows: | |
if row[0] != 0: | |
SetFireWall() | |
conn.close() | |
print "Close connection" | |
return; | |
def SetFireWall(): | |
try: | |
conn = psycopg2.connect(database="postgres", user="postgres", password="liluARKn14", host="10.0.30.20", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
idn = 0; | |
cur.execute("SELECT id,ip from firewall where visible=true") | |
rows = cur.fetchall() | |
result = "" | |
if len(rows)>0: | |
for row in rows: | |
result += str(row[1])+'\r\n' | |
UpdateIPStatus(row[0]) | |
print "ip=", row[1]+'\n' | |
f = open("/etc/listip",'w') | |
f.write(result) | |
f.close() | |
conn.close() | |
print "Close connection" | |
return; | |
def UpdateIPStatus(id): | |
try: | |
conn = psycopg2.connect(database="postgres", user="postgres", password="liluARKn14", host="10.0.30.20", port="5432") | |
print "Open connection" | |
except: | |
print "WARNING! I can't open connection" | |
cur = conn.cursor() | |
cur.execute("UPDATE firewall SET id_status=1 where id=%s",[id]); | |
conn.commit(); | |
conn.close(); | |
return; | |
GetListInSQL() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment