Skip to content

Instantly share code, notes, and snippets.

@sdfsdhgjkbmnmxc
Forked from anonymous/gist:a7a00ba08c16d26eb663
Last active August 29, 2015 14:13
Show Gist options
  • Save sdfsdhgjkbmnmxc/e00b407c75a335ef6c44 to your computer and use it in GitHub Desktop.
Save sdfsdhgjkbmnmxc/e00b407c75a335ef6c44 to your computer and use it in GitHub Desktop.
#!/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