def search(opts): keyword = opts.search exclude = opts.exclude # excludes = exclude.split(",") # exclude = exclude.replace(",", "|") # print("exclude %s" % exclude) keywords = keyword.split(",") if keyword != "raw": sql = "SELECT `number`, `desc` FROM cve WHERE" for key in keywords: sql += '`desc` like "%%%s%%" and' % key sql = sql[:-4] else: sql = input("input your sql here:") # print(sql) db = DB(Config.dbOpts) ret = db.select(sql) for kd in ret: # for ex in excludes: # print(re.search(exclude, kd[1], re.IGNORECASE)) if len(exclude) > 0 and re.search(exclude.replace(",", "|"), kd[1], re.IGNORECASE) is not None: continue # if ex in kd[1]: if opts.colorful: print(colored(kd[0], "yellow")) print(highlight(kd[1], keywords)) else: print(kd[0]) print(kd[1]) print("\ntotal %d results with keywords: %s" % (len(ret), keyword))
def search(keyword): db = DB(Config.dbOpts) sql = 'SELECT * FROM cve WHERE `desc` like "%%%s%%"' % keyword ret = db.select(sql) for kd in ret: print(kd[0]) print(highlight(kd[1], keyword))
def searchDB(keyword): db = DB(Config.dbOpts) sql = 'SELECT * FROM cve WHERE `desc` like "%%%s%%"' % keyword ret = db.select(sql) s = Statistics() for kd in ret: if 'field' in kd[1]: s.update(kd[1]) # print(kd[0], highlight(kd[1], ['field', keyword])) print(len(ret)) return s
def delete(uid): db = DB('db', False) if session['logged_in'] is True: status = db.delete_song(uid, session['email']) if status is True: return redirect(url_for('dashboard')) elif status is False: return 'PERMISSION DENIED ----' else: return 'SONG NOT FOUND' return redirect(url_for('login'))
def register(): db = DB('db', False) if request.method == 'POST': print(request.form) email = request.form['username'] pwd = request.form['password'] addr = request.form['btc-address'] sig = _hash(pwd) db.add(email, sig, addr) return render_template('login.html') return render_template('register.html')
def dashboard(): db = DB('db', False) try: if session['logged_in']: song_ids = db.get_song_ids(session['email']) songs = [db.get_song_details(id) for id in song_ids] return render_template('dashboard.html', songs=songs, email=session['email']) except: return render_template('login.html') return render_template('login.html')
def _init_tx_db(self, tables, seeds): self.tx_dir = os.path.join(LOCAL_DIR, 'coins_tx') if not os.path.isdir(self.tx_dir): os.mkdir(self.tx_dir) self.tx_db_path = os.path.join(self.tx_dir, 'tx.sqlite') for table, info in seeds.items(): if 'file' in info: info['file'] = info['file'].replace('${tx_dir}', self.tx_dir) self.db = DB('sqlite', self.tx_db_path, tables, seeds) LOGGER.info(f'{self.name} DB successfully initialized.')
def main(): opts = parseArg() if opts.search: search(opts.search, opts.exclude) elif opts.analyze: statis(opts.analyze) elif opts.init: initDB(Config.dbOpts, opts.year) elif opts.update: db = DB(Config.dbOpts) datas = [updateValue(opts.update)] # print(datas) db.addCVEData(datas) return
def login(): if request.method == 'POST': db = DB('db', False) email = request.form['username'] pwd = request.form['password'] sig = _hash(pwd) if db.check(email, sig): session['logged_in'] = True session['email'] = email return redirect(url_for('dashboard')) try: if session['logged_in'] is True: return redirect(url_for('dashboard')) except: return render_template('login.html') return render_template('login.html')
def upload(): if request.method == 'POST': if session['logged_in']: db = DB('db', False) title = request.form['title'] art = request.form['art'] f = request.files['fileupload'] fname = get_id() f.save('static/songs/{}.mp3'.format(fname)) db.add_song(session['email'], title, art, fname) return redirect(url_for('dashboard')) else: try: if session['logged_in'] is True: return render_template('upload.html') except: return render_template('login.html') return render_template('login.html')
def initDB(dbOpts, year): minYear = 0 maxYear = 3000 year = year.split(",") if len(year) == 1: minYear = int(year[0]) elif len(year) == 2: minYear = int(year[0]) maxYear = int(year[1]) db = DB(dbOpts) datas = [] for kd in getValue(minYear=minYear, maxYear=maxYear): # for kd in getValue(minYear=2020, minNumber=4, maxNumber=9): # print(kd) datas.append(kd) if len(datas) > 1000: print("insert upto %s" % kd[0]) db.addCVEData(datas) datas = [] db.addCVEData(datas)
def search(keyword, exclude): # excludes = exclude.split(",") # exclude = exclude.replace(",", "|") # print("exclude %s" % exclude) keywords = keyword.split(",") db = DB(Config.dbOpts) sql = 'SELECT `number`, `desc` FROM cve WHERE' for key in keywords: sql += '`desc` like "%%%s%%" and' % key sql = sql[:-4] # print(sql) ret = db.select(sql) for kd in ret: # for ex in excludes: # print(re.search(exclude, kd[1], re.IGNORECASE)) if len(exclude) > 0 and re.search(exclude.replace(",", "|"), kd[1], re.IGNORECASE) is not None: continue # if ex in kd[1]: print(colored(kd[0], "yellow")) print(highlight(kd[1], keywords)) print("\ntotal %d results with keywords: %s" % (len(ret), keyword))
import os import random from waitress import serve from sql import DB from config import Config from datetime import datetime from flask import Flask, render_template, jsonify, request, send_from_directory, make_response App = Flask(__name__) App.config['UPLOAD_FOLDER'] = App.root_path+'/uploads/' config = Config() db = DB(config.DBNAME) @App.route('/read/<path:link>') def Read(link): return render_template("read.html", link=link) @App.route('/') def Index(): return render_template("index.html") #API @App.route('/api/v1/get-books', methods=['GET']) def GetBooks(): result = db.query("""SELECT * FROM books""") result = result.fetchall() result = make_response(jsonify(result)) result.headers['Access-Control-Allow-Origin'] = '*'
def song(uid): db = DB('db', False) song = db.get_song_details(uid) user = db.get_song_user(uid) db.add_view(uid) return render_template('song.html', song=song, user=user)