1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import MySQLdb
USER = "asdfus"
PASSWORD = "gTYgT&M6q"
DATABASE = "asdfus"
class Db(object):
def __init__ (self):
self.conn = None
self.cursor = None
self.connect()
def connect (self):
self.conn = MySQLdb.connect (host = "localhost",
user = USER,
passwd = PASSWORD,
db = DATABASE
)
self.cursor = self.conn.cursor ()
def execute (self,sql,args=()):
try:
self.cursor.execute(sql,args)
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
# sys.exit (1)
self.connect()
self.cursor.execute(sql,args)
def lastinsertid (self):
return self.conn.insert_id()
def insert_cmd (
self,
date=time.time(),
remote_addr="NULL",
username="NULL",
url="NULL",
directory="NULL",
oldfile="NULL",
newfile="NULL",
cmd="NULL",
dataobj="NULL",
tag="NULL"):
try:
sql = "INSERT INTO im_cmd "
sql += "(date, remote_addr, name, url, dir, oldfile, newfile, cmd, dataobj, tag) "
sql += "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
#or "NULL"
args = (date, remote_addr, username, url, directory, oldfile, newfile, cmd, dataobj, tag)
#args = (now(), os.environ['REMOTE_ADDR'], name, url, dir, oldfile, newfile, " ".join(cmd),dataobj)
self.execute(sql, args)
except Exception as e:
sys.stderr.write(str(e))
return
|