Example #1
0
def desk_patientdel():
    if 'username' in session and 'AD' in session['username']:
        form=SearchForm(request.form)
        if request.method=='POST':
            if request.form['action'] == 'show':
                con=mysql.connect()
                cursor=con.cursor()
                query = "SELECT * FROM patient WHERE id = %s "
                cursor.execute(query, (form.pid.data,))
                pdata=cursor.fetchall()
                cursor.close()
                con.commit()
                con.close()
                if pdata:
                    return render_template("desk/patient_delete.html",pdata=pdata,form=form,desk_patient_delete_page=True)
                else:
                    flash("Patient not Found")
                    return render_template("desk/patient_delete.html",pdata=pdata,form=form,desk_patient_delete_page=True)
            elif request.form['action'] == 'delete':
                con=mysql.connect()
                cursor=con.cursor()
                query = "DELETE FROM patient WHERE id = %s "
                cursor.execute(query, (form.pid.data,))
                cursor.close()
                con.commit()
                con.close()
                return render_template("desk/patient_delete.html",form=form,desk_patient_delete_page=True)

        else:
            return render_template("desk/patient_delete.html",form=form,desk_patient_delete_page=True)
    else:
        return redirect(url_for('login'))
Example #2
0
def update_inventory(quantity,issueid):
    con=mysql.connect()
    con=mysql.connect()
    cursor=con.cursor()
    cursor.execute("UPDATE medicine_inventory SET quantity = quantity-%s WHERE mid = %s and quantity >= 0",(quantity,issueid))
    cursor1=con.cursor()
    cursor1.execute("SELECT * FROM medicine_inventory")
    meddata=cursor1.fetchall()
    con.commit()
    cursor1.close()
    cursor.close()
    con.close()
    return meddata
Example #3
0
def desk_patient_update():
    if 'username' in session and 'AD' in session['username']:
        form=UpdatePatientForm(request.form)
        if request.method=='POST':
            if request.form['action'] == 'show':
                
                con=mysql.connect()
                cursor=con.cursor()
                query = "SELECT * FROM patient WHERE id = %s "
                cursor.execute(query, (form.pid.data,))
                pdata=cursor.fetchall()
                cursor.close()
                con.commit()
                con.close()
                
                
                if pdata:
                    form.set_data(pdata[0])
                    session["pid"]=form.pid.data
                    return render_template("desk/patient_update.html",pid=form.pid.data,form=form,update=True,desk_patient_update_page=True)
                else:
                    flash("Patient not Found")
                    return render_template("desk/patient_update.html",form=form,update=False,desk_patient_update_page=True)
            elif request.form['action'] == 'update':
                con=mysql.connect()
                cursor=con.cursor()

                query = "UPDATE patient SET uid = %s,name = %s,age = %s,doadmission = %s,bedtype = %s,address = %s,city = %s,state = %s,status = %s WHERE id = %s"
                data = (form.uid.data,form.pName.data,form.pAge.data,form.dateOfSubmission.data,form.bedType.data,
                        form.address.data,form.city.data,form.state.data,form.status.data,session['pid'])
                cursor.execute(query, data)
                cursor.close()
                con.commit()
                con.close()
                del session['pid']
                flash('Patient Details Updated.')
                return render_template("desk/patient_update.html",form=form,Update=False,desk_patient_update_page=True)
            else:
                #discard
                del session['pid']
                return render_template("desk/patient_update.html",form=form,update=False,desk_patient_update_page=True)
        else:
            
            return render_template("desk/patient_update.html",form=form,update=False,desk_patient_update_page=True)
    else:
        if 'username' in session:
            if 'PH' in session['username']:
                return redirect(url_for('pharmacy_home'))
            return redirect(url_for('diagnostic_home'))
        return redirect(url_for('login'))
Example #4
0
def resultapk(md5):
    connect = mysql.connect()
    cursor = connect.cursor()
    cursor.execute("SELECT * FROM tbl_apkinfo WHERE md5 = %s", (md5))
    data = cursor.fetchall()
    connect.close()
    for element in data:
        apkinfo = {
            'md5': element[0],
            'appName': element[1],
            'fileSize': element[2],
            'analysisTime': element[3],
            'sha1': element[4],
            'sha256': element[5],
            'sha512': element[6],
            'firstSubmission': element[7],
            'lastSubmission': element[8],
            'package': element[9],
            'androidversionCode': element[10],
            'androidversionName': element[11],
            'minSDKVersion': element[12],
            'maxSDKVersion': element[13],
            'targetSDKVersion': element[14],
            'mainActivity': element[15],
            'certificate': json.loads(element[16]),
            'certificateIssuer': json.loads(element[17]),
            'certificateSubject': json.loads(element[18]),
            'declaredPermissions': json.loads(element[19]),
            'requestedPermissions': json.loads(element[20]),
            'activities': json.loads(element[21]),
            'services': json.loads(element[22]),
            'providers': json.loads(element[23]),
            'receivers': json.loads(element[24])
        }
    return render_template('resultapk.html', apkinfo = apkinfo)
Example #5
0
def login():
    if 'username' in session:
        username = session['username']
        if 'AD' in username:
            return redirect(url_for('desk_home'))
        elif 'PH' in username:
            return redirect(url_for('pharmacy_home'))
        return redirect(url_for('diagnostic_home'))
    if request.method == 'POST':
        username = request.form["username"]
        password = request.form["password"]

        n = mysql.connect().cursor().execute(
            "SELECT * from userstore where loginid =%s and password=%s",
            (username, password))
        if n:
            session["username"] = username
            session.permanent = True
            if 'AD' in username:
                return redirect(url_for('desk_home'))
            elif 'PH' in username:
                return redirect(url_for('pharmacy_home'))
            return redirect(url_for('diagnostic_home'))
        else:
            flash(' Invalid Credentials.')
            return redirect(url_for('login'))
    form = LoginForm()
    return render_template("login.html", form=form)
Example #6
0
def login():
    form=LoginForm()
    if 'username' in session:
        username=session['username']
        if 'AD' in username:
            return redirect(url_for('desk_home'))
        elif 'PH' in username:
            return redirect(url_for('pharmacy_home'))
        return redirect(url_for('diagnostic_home'))
    if request.method == 'POST':
        username=request.form["username"]
        password=request.form["password"]

        #validate username and Password 
        if len(username) < 8 :
            flash('username must be alphabetic or alphanumeric and should have a minimum of 8 characters.')
            return render_template("login.html",form=form)
        if password_validation(password):
            flash('Password should contain 10 characters including one special character, one upper case, one numeric')
            return render_template("login.html",form=form)
        n= mysql.connect().cursor().execute("SELECT * from userstore where loginid =%s and password=%s",(username,password))
        if n :
            session["username"] = username
            session.permanent = True
            if 'AD' in username:
                return redirect(url_for('desk_home'))
            elif 'PH' in username:
                return redirect(url_for('pharmacy_home'))
            return redirect(url_for('diagnostic_home'))
        else:
            flash(' Invalid Credentials.')
            return redirect(url_for('login'))
    
    return render_template("login.html",form=form)
Example #7
0
def get_med_inventory():
        con=mysql.connect()
        cursor=con.cursor()
        cursor.execute("SELECT * FROM medicine_inventory ")
        meddata=cursor.fetchall()
        cursor.close()
        con.commit()
        con.close()
        return meddata
Example #8
0
def available_tests():
        con=mysql.connect()
        cursor=con.cursor()
        cursor.execute("SELECT * FROM diagnostic_tests ")
        data=cursor.fetchall()
        cursor.close()
        con.commit()
        con.close()
        return data
Example #9
0
def get_diagnostic(issueid):
    con=mysql.connect()
    cursor=con.cursor()
    cursor.execute("SELECT * FROM diagnostic_tests WHERE tid=%s",issueid)
    med=cursor.fetchall()
    cursor.close()
    con.commit()
    con.close()
    return med
Example #10
0
def get_medicine(issueid):
    con=mysql.connect()
    cursor=con.cursor()
    cursor.execute("SELECT * FROM medicine_inventory WHERE mid=%s",issueid)
    med=cursor.fetchall()
    cursor.close()
    con.commit()
    con.close()
    return med
Example #11
0
def registerPatient(form):
    try:
        con=mysql.connect()
        cursor=con.cursor()
        status=cursor.execute("INSERT INTO patient(uid,name,age,doadmission,bedtype,address,city,state,status) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)",(form.uid.data,form.pName.data,form.pAge.data,form.dateOfSubmission.data,form.bedType.data,form.address.data,form.city.data,form.state.data,form.status.data))
        con.commit()
        con.close()  
        return status 
    except:
        return False #We can add more elaborate exceptions but it doesn't seem like a priority.
def femaleEmpStatus():
    cursor = mysql.connect().cursor()
    cursor.execute("select count(*) as count,employee_data.id,gender,punch_event from employee_data,punch_application where employee_data.gender='Female' and employee_data.id=punch_application.id group by employee_data.id,punch_event")
    data = cursor.fetchall()
    if data is None:
     return "Username or Password is wrong"
    else:
        outputObj=(makeDict(data))
        totalIn,fem=calculateInCount(outputObj)
        return json.dumps(fem)
def getEmpById(id):
    cursor = mysql.connect().cursor()
    cursor.execute("select * from employee_data where id="+id)
    data = cursor.fetchall()
    if data is None:
        return "Username or Password is wrong"
    else:
        try:
            return json.dumps(data[0])
        except:
            return "Employee not found!!"
Example #14
0
def issue_test(issueid):
    try:
        con=mysql.connect()
        cursor=con.cursor()
        cursor.execute("INSERT INTO diagnostic_tests_conducted VALUES(%s,%s)",(session['pid'],issueid))
        con.commit()
        cursor.close()
        con.close()
        return True
    except:
        return False 
Example #15
0
def issue(issueid,quantity,doi):
    try:
        con=mysql.connect()
        cursor=con.cursor()
        cursor.execute("INSERT INTO issued_medicines VALUES(%s,%s,%s)",(session['pid'],issueid,quantity))
        con.commit()
        cursor.close()
        con.close()
        return True
    except:
        return False 
def getIntervalData():
    cursor = mysql.connect().cursor()
    cursor.execute("select hour(punch_time) time_hour,count(id) punches from punch_application group by hour(punch_time) order by time_hour asc")
    data = cursor.fetchall()
    if data is None:
        return "No data"
    else:
        try:
            return json.dumps(data)
        except:
            return "no data"
Example #17
0
def activepatients():
    if 'username' in session and 'AD' in session['username']:
        curr = mysql.connect().cursor()
        curr.execute("select * from patient where status='Active'")
        data = curr.fetchall()
        if curr.rowcount > 0:
            return render_template("desk/activepatients.html",data=data,desk_patient_active_page=True)
        else:
            return render_template("desk/activepatients.html",desk_patient_active_page=True)

    else:
        if 'username' in session:
            if 'PH' in session['username']:
                return redirect(url_for('pharmacy_home'))
            return redirect(url_for('diagnostic_home'))
        else:
            return redirect(url_for('login'))
Example #18
0
def search_patients():
    if 'username' in session and 'PH' in session['username']:
            form = SearchForm(request.form)
            if request.method == 'POST':
                    con=mysql.connect()
                    
                    cursor1=con.cursor()
                    query1 = "SELECT * FROM patient WHERE id = %s "
                    cursor1.execute(query1, (form.pid.data))
                    pdata=cursor1.fetchall()


                    cursor2=con.cursor()
                    query2 = "select medicine_inventory.mname,issued_medicines.quantity_issued,medicine_inventory.rate,medicine_inventory.rate*issued_medicines.quantity_issued from medicine_inventory INNER JOIN issued_medicines ON medicine_inventory.mid = issued_medicines.mid where issued_medicines.pid = %s"
                    cursor2.execute(query2, (form.pid.data,))
                    mdata=cursor2.fetchall()

                    session['pdata']=pdata
                    session['mdata']=mdata
                    session['pid']=form.pid.data


                    cursor1.close()
                    cursor2.close()
                    con.commit()
                    con.close()
                
                    if pdata:
                        return redirect(url_for("display_patient_details"))
                    else:
                        flash("Patient is not registered! Please check ID again!")
                        return render_template("pharmacy/search_patient.html",form=form)
            
            else:
                return render_template("pharmacy/search_patient.html",form=form)
    else:
        return redirect(url_for('login'))
Example #19
0
def search_diagnostics():
    if 'username' in session and 'DS' in session['username']:
            form = SearchForm(request.form)
            if request.method == 'POST':
                    con=mysql.connect()
                    
                    cursor1=con.cursor()
                    query1 = "SELECT * FROM patient WHERE id = %s "
                    cursor1.execute(query1, (form.pid.data))
                    pdata=cursor1.fetchall()


                    cursor2=con.cursor()
                    query2 = "select diagnostic_tests.tid,diagnostic_tests.tname,diagnostic_tests.charge FROM diagnostic_tests INNER JOIN diagnostic_tests_conducted ON diagnostic_tests.tid = diagnostic_tests_conducted.tid where diagnostic_tests_conducted.pid = %s"
                    cursor2.execute(query2, (form.pid.data))
                    ddata=cursor2.fetchall()

                    session['pdata']=pdata
                    session['ddata']=ddata
                    session['pid']=form.pid.data


                    cursor1.close()
                    cursor2.close()
                    con.commit()
                    con.close()
                
                    if pdata:
                        return redirect(url_for("display_diagnostic_details"))
                    else:
                        flash("Patient is not registered! Please check ID again!")
                        return render_template("diagnostic/search_diagnostics.html",form=form)
            
            else:
                return render_template("diagnostic/search_diagnostics.html",form=form)
    else:
        return redirect(url_for('login'))
Example #20
0
def get_conn():
    conn = mysql.connect()
    #    cursor = conn.cursor()
    return conn
	def __init__(self, query):
		self.query = query
		self.conn = mysql.connect()
		self.cursor = self.conn.cursor()
Example #22
0
def analyze(path):
    try:
        start = process_time()
        hashfunctions = dict(md5=hashlib.md5,
                             sha1=hashlib.sha1,
                             sha256=hashlib.sha256,
                             sha512=hashlib.sha512)
        a = APK(path)

        certs = set(
            a.get_certificates_der_v3() + a.get_certificates_der_v2() +
            [a.get_certificate_der(x) for x in a.get_signature_names()])

        for cert in certs:
            x509_cert = x509.Certificate.load(cert)

            issuer = {
                'commonName': None,
                'organizationName': None,
                'organizationalUnitName': None,
                'countryName': None,
                'stateOrProvinceName': None,
                'localityName': None
            }
            subject = {
                'commonName': None,
                'organizationName': None,
                'organizationalUnitName': None,
                'countryName': None,
                'stateOrProvinceName': None,
                'localityName': None
            }

            strIssuer = get_certificate_name_string(x509_cert.issuer,
                                                    short=False)
            strSubject = get_certificate_name_string(x509_cert.subject,
                                                     short=False)

            arrIssuer = strIssuer.split(',')
            for i in arrIssuer:
                if i.lstrip().split('=')[0] == 'commonName':
                    issuer['commonName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'organizationName':
                    issuer['organizationName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'organizationalUnitName':
                    issuer['organizationalUnitName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'countryName':
                    issuer['countryName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'stateOrProvinceName':
                    issuer['stateOrProvinceName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'localityName':
                    issuer['localityName'] = i.lstrip().split('=')[1]

            arrSubject = strSubject.split(',')
            for i in arrSubject:
                if i.lstrip().split('=')[0] == 'commonName':
                    subject['commonName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'organizationName':
                    subject['organizationName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'organizationalUnitName':
                    subject['organizationalUnitName'] = i.lstrip().split(
                        '=')[1]
                elif i.lstrip().split('=')[0] == 'countryName':
                    subject['countryName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'stateOrProvinceName':
                    subject['stateOrProvinceName'] = i.lstrip().split('=')[1]
                elif i.lstrip().split('=')[0] == 'localityName':
                    subject['localityName'] = i.lstrip().split('=')[1]

            for k, v in hashfunctions.items():
                if k == 'md5':
                    md5 = v(cert).hexdigest()
                elif k == 'sha1':
                    sha1 = v(cert).hexdigest()
                elif k == 'sha256':
                    sha256 = v(cert).hexdigest()
                elif k == 'sha512':
                    sha512 = v(cert).hexdigest()

        md5 = md5

        appName = a.get_app_name()
        fileSize = os.stat(a.get_filename()).st_size
        sha1 = sha1
        sha256 = sha256
        sha512 = sha512
        timestamp = time.time()
        dateTime = datetime.fromtimestamp(timestamp)
        timeOfSubmit = dateTime.strftime("%Y-%m-%d %H:%M:%S")
        package = a.get_package()
        androidversionCode = a.get_androidversion_code()
        androidversionName = a.get_androidversion_name()
        minSDKVersion = a.get_min_sdk_version()
        maxSDKVersion = a.get_max_sdk_version()
        targetSDKVersion = a.get_target_sdk_version()
        mainActivity = a.get_main_activity()

        attributes = {
            'validFrom':
            x509_cert['tbs_certificate']['validity']
            ['not_before'].native.strftime("%Y-%m-%d %H:%M:%S"),
            'validTo':
            x509_cert['tbs_certificate']['validity']
            ['not_after'].native.strftime("%Y-%m-%d %H:%M:%S"),
            'serialNumber':
            hex(x509_cert.serial_number),
            'hashAlgorithm':
            x509_cert.hash_algo,
            'signatureAlgorithm':
            x509_cert.signature_algo
        }

        certificateAttributes = json.dumps(attributes)
        certificateIssuer = json.dumps(issuer)
        certificateSubject = json.dumps(subject)

        declaredPermissions = json.dumps(a.get_declared_permissions())

        requestedPermissions = json.dumps(a.get_permissions())

        activities = json.dumps(a.get_activities())

        services = json.dumps(a.get_services())

        receivers = json.dumps(a.get_receivers())

        providers = json.dumps(a.get_providers())

        stop = process_time()
        analysisTime = stop - start

        connect = mysql.connect()
        cursor = connect.cursor()

        sql = "INSERT INTO tbl_apkinfo (md5, appName, fileSize, analysisTime, sha1, sha256, sha512, firstSubmission, lastSubmission, package, androidversionCode, androidversionName, minSDKVersion, maxSDKVersion, targetSDKVersion, mainActivity, certificateAttributes, certificateIssuer, certificateSubject,	declaredPermissions, requestedPermissions, activities, services, providers, receivers) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
        param = (md5, appName, fileSize, analysisTime, sha1, sha256, sha512,
                 timeOfSubmit, timeOfSubmit, package, androidversionCode,
                 androidversionName, minSDKVersion, maxSDKVersion,
                 targetSDKVersion, mainActivity, certificateAttributes,
                 certificateIssuer, certificateSubject, declaredPermissions,
                 requestedPermissions, activities, services, providers,
                 receivers)
        cursor.execute(sql, param)

        connect.commit()
        connect.close()

        androaxml_main(path,
                       os.path.join(app.config['OUTPUT_PATH'], md5 + '.xml'))
        return True
    except:
        return False
Example #23
0
def billpatient():
    if 'username' in session and 'AD' in session['username']:
        form=BillingForm(request.form)
        if request.method=='POST':
            if request.form['action'] == 'show':
                con=mysql.connect()
                cursor=con.cursor()
                query = "SELECT * FROM patient WHERE id = %s AND status='Active' "
                cursor.execute(query, (form.pid.data,))
                pdata=cursor.fetchall()
                q1 = "SELECT doadmission FROM patient WHERE id = %s "
                cursor.execute(query, (form.pid.data,))
                doa=cursor.fetchone()
                if doa:
                    doastr=str(doa[4])
                    bedtype= doa[5]
                    date_time_table = (datetime.strptime(doastr, '%Y-%m-%d'))
                    date_now_str = (datetime.today().strftime('%Y-%m-%d'))
                    date_now = (datetime.strptime(date_now_str, '%Y-%m-%d'))
                    delta = date_now - date_time_table
                    if(bedtype == 'Single'):
                        session['roomcharge']=(delta.days)*8000
                    elif(bedtype == 'Semi'):
                        session['roomcharge']=(delta.days)*4000
                    else:
                        session['roomcharge']=(delta.days)*2000
                    session['doa'] =abs(delta.days)
                    session['dod'] =date_now_str

                q2 = "SELECT medicine_inventory.mname,issued_medicines.quantity_issued,medicine_inventory.rate FROM medicine_inventory ,issued_medicines WHERE  medicine_inventory.mid =issued_medicines.mid AND issued_medicines.pid= %s "   
                cursor.execute(q2, (form.pid.data,))
                rdata=cursor.fetchall()
                i=0
                for row in rdata:
                    i=i+(row[1]*row[2])
                

                session['pharmtotal'] =i

                q3= "SELECT diagnostic_tests.tname,diagnostic_tests.charge FROM diagnostic_tests,diagnostic_tests_conducted WHERE diagnostic_tests.tid = diagnostic_tests_conducted.tid AND diagnostic_tests_conducted.pid= %s "
                cursor.execute(q3, (form.pid.data,))
                ddata=cursor.fetchall()
                i=0
                for row in ddata:
                    i=i+row[1]

                session['diagnostictotal'] =i

                cursor.close()
                con.commit()
                con.close()
                if pdata:
                    return render_template("desk/billing.html",pdata=pdata,rdata=rdata,ddata=ddata,form=form,desk_patient_billing_page=True)
                else:
                    flash("Patient not Found")
                    return render_template("desk/billing.html",pdata=pdata,rdata=rdata,ddata=ddata,form=form,desk_patient_billing_page=True)
            
            elif request.form['action'] == 'update':
                con=mysql.connect()
                cursor=con.cursor()
                query = "UPDATE patient SET status='Discharged' WHERE id = %s "
                cursor.execute(query, (form.pid.data,))
                cursor.close()
                con.commit()
                con.close()
                return render_template("desk/index.html")



        else:
            return render_template("desk/billing.html",form=form,desk_patient_billing_page=True)
    else:
        return redirect(url_for('login'))
Example #24
0
def handle():
    if 'id' not in session:
        return redirect(url_for('home'))
    elif session['extension'] == '.apk':
        id = session['id']
        extension = session['extension']
        tempPath =  os.path.join(app.config['TEMPORARY_PATH'], id + extension)
        if checkAPK(tempPath):
            md5 = getMD5(tempPath)
            if md5 != False:
                connect = mysql.connect()
                cursor = connect.cursor()
                cursor.execute("SELECT * FROM tbl_apkinfo WHERE md5 = %s", md5)
                data = cursor.fetchall()
                connect.close()
                if len(data) == 0:
                    if analyze(tempPath) != False:
                        copyfile(tempPath, os.path.join(app.config['UPLOADED_PATH'], md5 + extension))
                        os.remove(tempPath)
                        session.pop('id', None)
                        session.pop('extension', None)
                        return redirect(url_for('resultapk', md5 = md5))
                    else:
                        session.pop('id', None)
                        session.pop('extension', None)
                        os.remove(tempPath)
                        return redirect(url_for('invalidapk'))
                else:
                    connect = mysql.connect()
                    cursor = connect.cursor()
                    timeOfSubmit = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
                    cursor.execute("UPDATE tbl_apkinfo SET lastSubmission = %s WHERE md5 = %s", (timeOfSubmit, md5))
                    connect.commit()
                    connect.close()
                    session.pop('id', None)
                    session.pop('extension', None)
                    os.remove(tempPath)
                    return redirect(url_for('resultapk', md5=md5))
            else:
                session.pop('id', None)
                session.pop('extension', None)
                os.remove(tempPath)
                return redirect(url_for('invalidapk'))
        else:
            session.pop('id', None)
            session.pop('extension', None)
            os.remove(tempPath)
            return redirect(url_for('invalidapk'))
    elif session['extension'] == '.zip':
        id = session['id']
        extension = session['extension']
        tempPathZIP =  os.path.join(app.config['TEMPORARY_PATH'], id + extension)
        if checkZIP(tempPathZIP):
            zipFile= zipfile.ZipFile(tempPathZIP)
            zipFile.extractall(os.path.join(app.config['TEMPORARY_PATH'], id))
            zipFile.close()
            nameArr = []
            md5Arr = []
            tempPathFolder = os.path.join(app.config['TEMPORARY_PATH'], id)
            dirs = os.listdir(tempPathFolder)
            for file in dirs:
                tempPath = os.path.join(app.config['TEMPORARY_PATH'], id) + '/' + file
                if checkAPK(tempPath):
                    md5 = getMD5(tempPath)
                    extensionInFolder = os.path.splitext(file)[1]
                    if md5 != False:
                        connect = mysql.connect()
                        cursor = connect.cursor()
                        cursor.execute("SELECT * FROM tbl_apkinfo WHERE md5 = %s", (md5))
                        data = cursor.fetchall()
                        connect.close()
                        if len(data) == 0:
                            if analyze(tempPath) != False:
                                copyfile(tempPath, os.path.join(app.config['UPLOADED_PATH'], md5 + extensionInFolder))
                                nameArr.append (file)
                                md5Arr.append (md5)
                            else:
                                nameArr.append (file)
                                md5Arr.append (None)
                        else:
                            connect = mysql.connect()
                            cursor = connect.cursor()
                            timeOfSubmit = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d %H:%M:%S")
                            cursor.execute("UPDATE tbl_apkinfo SET lastSubmission = %s WHERE md5 = %s", (timeOfSubmit, md5))
                            connect.commit()
                            connect.close()
                            nameArr.append (file)
                            md5Arr.append (md5)
                    else:
                        nameArr.append (file)
                        md5Arr.append (None)
                else:
                    nameArr.append (file)
                    md5Arr.append (None)
            session.pop('id', None)
            session.pop('extension', None)
            rmtree(tempPathFolder)
            os.remove(tempPathZIP)
            session['nameArr'] = nameArr
            session['md5Arr'] = md5Arr
            return redirect(url_for('resultzip', id = id))
        else:
            session.pop('id', None)
            session.pop('extension', None)
            os.remove(tempPathZIP)
            return redirect(url_for('invalidzip'))