#!/usr/bin/python # -*- coding: Windows-1251 # # Version 2.6 # # # ver. 2.7 / 29.03.2006 Victor import sys import cgi import urllib import MySQLdb import string import paybill, os, re, time, socket ip_allow = ['127.0.0.1','85.14.38.102','85.14.38.98','217.18.252.229' ,'217.18.252.226','213.91.242.127','84.242.131.159','91.191.217.235','91.191.223.101','78.130.201.66'] remote_addr = os.environ['REMOTE_ADDR'] def check_ip(remote_addr): for ip in ip_allow: if ip == remote_addr: return True return False def check_eik(string): chars = "^[0-9]{9,9}$" rx = re.compile(chars) chars = "^[0-9]{13,13}$" rx1 = re.compile(chars) if rx.match(string) or rx1.match(string) : return True else: return False def write_log(error): f=open('/home/daxyweb/log/ebg.log', 'a') global company_eik global remote_addr try: host=socket.gethostbyaddr(remote_addr)[0] except: host = "unknown" string=str(time.strftime('%H:%M:%S %d-%b-%Y'))+"\t"+company_eik+"\t"+remote_addr+"\t("+str(host)+")\t"+error+'\n' f.write(string) f.close() return # checkin for invalid chars in the string def check( firma): if( len(firma)!=0 ) : line = string.strip(firma) if ( line.find( "&" ) >= 0 ): return line.replace("&", "&" ) else: return firma else: return "-" def getbulnom( nom1, nom3 ): if( (nom1 is None) or (nom3 is None) ): return "#" cursor = db.cursor() cursor.execute("select nom2 from bulnom where nom1="+`int(nom1)`+" and nom3="+`int(nom3)`) resultSet = cursor.fetchall() for cursorRecord in resultSet: return check(cursorRecord[0]) return "#" def getbuliso( iso1 ): cursor = db.cursor() cursor.execute("select iso2 from buliso where iso1='"+iso1+"'") resultSet = cursor.fetchone() return check(resultSet[0]) def getbulnok( nok ): cursor = db.cursor() cursor.execute("select nok2 from bulnok where nok1='"+nok+"'") resultSet = cursor.fetchone() return check(resultSet[0]) def getekkatename( ekatte ): cursor = db.cursor() cursor2 = db.cursor() cursor.execute("select * from ek_atte where ekatte='"+ekatte+"'") resultSet = cursor.fetchone() try: result = "" result = result + resultSet[1]; result = result + resultSet[2] except: result="" try: cursor2.execute("select * from ek_obl where oblast='"+resultSet[3]+"'") resultSet2 = cursor2.fetchone() result = result + ", област "+resultSet2[2] except: pass try: cursor2 = db.cursor() cursor2.execute("select * from ek_obst where obstina='"+resultSet[4]+"'") resultSet2 = cursor2.fetchone() result = result + ", община "+resultSet2[2] except: pass return check(result) def get_bulstat_for_EGN( EGN ): cursor.execute("select u1, u11 from bulstatu where u4 = '"+EGN+"'") resultSet = cursor.fetchall() if( len(resultSet)!=0 ) : connections = 1; company = [] for cursorRecord in resultSet: try: company.index( cursorRecord[0] ) continue except ValueError: company.append(cursorRecord[0]) #print "" print ""+check(cursorRecord[0])+"" cursor2.execute("select n5 from bulstatn where n1 = '"+cursorRecord[0]+"'") resultSet2 = cursor2.fetchone() print ""+check(resultSet2[0])+"" #print "" print "Content-Type: text/xml" print # blank line, end of headers print "" # XML encoding form = cgi.FieldStorage() company_eik = form.getvalue("num", "") try: db = MySQLdb.Connect(db='bulstat') cursor = db.cursor() cursor2 = db.cursor() except: print "Временно няма достъп до БД" error="Временно няма достъп до БД" write_log(error) exit(-1) if check_ip(remote_addr)== False: print "Нямате достъп" error="Нямате достъп" write_log(error) sys.exit(0) if check_eik(company_eik)==False: print "Грешен ЕИК" error="Грешен ЕИК" write_log(error) sys.exit(0) write_log("OK") cursor.execute("select * from bulstatn where n1='"+company_eik+"'") resultSet = cursor.fetchall() if( len(resultSet) == 0 ) : print "Няма открити резултати за фирма с БУЛСТАТ "+company_eik+"" error="Няма открити резултати за фирма с БУЛСТАТ "+company_eik write_log(error) sys.exit(0) company_name = '' for cursorRecord in resultSet: company_name = cursorRecord[5] for cursorRecord in resultSet: print "" print ""+check(company_name)+"" print ""+check(cursorRecord[1])+"" print ""+getbulnom( cursorRecord[4], 4)+", "+getbulnom( cursorRecord[3], 3)+", "+getbulnom( cursorRecord[2], 2)+"" cursor2.execute("select h3 from bulstath where h1 = '"+company_eik+"' and h2=8") resultSet2 = cursor2.fetchone() if( not (resultSet2 is None) ) : print ""+getbulnom( int(resultSet2[0]), 8)+"" if(cursorRecord[7] is None or cursorRecord[7]==0) : livetime = "безсрочно" else: livetime = `cursorRecord[7]`+ " месеца" print ""+check(livetime)+"" cursor2.execute("select * from bulstata where a1 = '"+company_eik+"'") resultSet2 = cursor2.fetchall() out2 = "" for cursorRecord2 in resultSet2: # print ""+cursorRecord2[4]+"" out = "
"+getbulnom( int(cursorRecord2[2]), 22) out = out + ": " out = out + getbuliso( cursorRecord2[3] ) + " " out = out + getekkatename( cursorRecord2[4] ) out = out + " пощ. код: "+ cursorRecord2[6] if( cursorRecord2[7] is not None and cursorRecord2[7]!=""): out = out + " п.к. "+cursorRecord2[7]+" " out = out + " " + cursorRecord2[8]+ " " if( out!=out2 ): out2 = out print check(out); print " ["+str(cursorRecord2[9])+"] ", print "
" cursor2.execute("select * from bulstatk where k1 = '"+company_eik+"' order by k3") resultSet2 = cursor2.fetchall() if( resultSet2 is not None and len(resultSet2) != 0) : print "" out2="" for cursorRecord2 in resultSet2: out = getbulnom(cursorRecord2[2], 23)+" " if( cursorRecord2[4]==1 ): out = out + "служебен" if(cursorRecord2[4]==2): out = out + "домашен" if(cursorRecord2[4]==3): out = out + "служебен/домашен" out = out + " " + cursorRecord2[3] if( out!=out2 ): out2 = out print check(out); print " ["+str(cursorRecord2[5])+"]" print "" cursor2.execute("select * from bulstatd where d1 = '"+company_eik+"'") resultSet2 = cursor2.fetchall() out2 = "" cursor2.execute("select h3 from bulstath where h1 = '"+company_eik+"' and h2=67") resultSet2 = cursor2.fetchall() for cursorRecord2 in resultSet2: print ""+getbulnok(cursorRecord2[0])+"" cursor2.execute("select * from bulstatc where c1 = '"+company_eik+"'") resultSet2 = cursor2.fetchall() out2 = "" for cursorRecord2 in resultSet2: if( cursorRecord2[4] is not None and cursorRecord2[5] is not None ) : all = float( cursorRecord2[4] ) * float( cursorRecord2[5] ) out =""+`all`+" лв."+getbulnom(cursorRecord2[6],48)+" курс " if( out!=out2 ): out2=out print check(out) print check(str(cursorRecord2[7])) +"" cursor2.execute("select * from bulstatw where w1 = '"+company_eik+"'") resultSet2 = cursor2.fetchall() for cursorRecord2 in resultSet2: print "Номера" if( not (cursorRecord2[1] is None )) : print "Данъчен: "+check(cursorRecord2[1]) if( not (cursorRecord2[2]=="" )) : print "Митнически: "+check(cursorRecord2[2]) if( not (cursorRecord2[3]=="" )) : print "Осигурителен: "+check(cursorRecord2[3]) if( not (cursorRecord2[4]=="" )) : print "ЕКПОУ: "+check(cursorRecord2[4]) cursor.execute("select u7, u4, u3, u5, u2 from bulstatu where u4!='1111111110' and u1 = '"+company_eik+"'") resultSet = cursor.fetchall() if( len(resultSet)!=0 ) : print "" for cursorRecord in resultSet: if( cursorRecord[2]=='ЕИК' ) : print ""+check(cursorRecord [1])+"" + check(cursorRecord [0])+" "+check(cursorRecord [3])+"" elif ( cursorRecord[2]=='ЕГН' ): # print ""+cursorRecord[1]+"" + cursorRecord [0]+" - "+getbulnom( cursorRecord[4], 15)+" "+cursorRecord [3]+" " print ""+check(cursorRecord[1])+"" + check(cursorRecord [0])+"" # get_bulstat_for_EGN( cursorRecord[1] ) else: print ""+check(cursorRecord[1])+"" + check(cursorRecord [0])+"" print "" cursor.execute("select s8, s4, s3, s5, s7 from bulstats where s4!='999999995' and s1 = '"+company_eik+"'") resultSet = cursor.fetchall() if( len(resultSet)!=0 ) : for cursorRecord in resultSet: print "" percent = cursorRecord[4]*1000; percent = int(percent) perc_10 = `int(percent/1000)` perc_01 = `percent%1000` if( (percent%1000) < 100 ): perc_01 = "0"+perc_01 if( (percent%1000) < 10 ): perc_01 = "0"+perc_01 if( (percent%1000) == 0 ): perc_01 = "0" if( cursorRecord[2]=='ЕИК' ) : print ""+check(cursorRecord [1])+" " + check(cursorRecord[0])+" "+perc_10+"."+perc_01+"% "+check(cursorRecord [3])+"" else: if( cursorRecord [1]=="" ) : print ""+check(cursorRecord[0])+" "+perc_10+"."+perc_01+"% "+check(cursorRecord[3])+"" else: print ""+check(cursorRecord [1])+" " + check(cursorRecord[0])+" "+perc_10+"."+perc_01+"% "+check(cursorRecord [3])+"" print "" cursor.execute("select s1, s7 from bulstats where s4 = '"+company_eik+"'") resultSet = cursor.fetchall() """if( len(resultSet)!=0 ) : for cursorRecord in resultSet: cursor2.execute("select n1, n5 from bulstatn where n1 = '"+cursorRecord[0]+"'") resultSet2 = cursor2.fetchone() if(resultSet2 is not None) : percent = cursorRecord[1]*1000; percent = int(percent) perc_10 = `int(percent/1000)` perc_01 = `percent%1000` if( (percent%1000) < 100 ): perc_01 = "0"+perc_01 if( (percent%1000) < 10 ): perc_01 = "0"+perc_01 if( (percent%1000) == 0 ): perc_01 = "0" print ""+check(cursorRecord[0])+" "+check(resultSet2[1])+ " "+perc_10+"."+perc_01+"%" """ cursor.execute("select u1, u11 from bulstatu where u4 = '"+company_eik+"'") resultSet = cursor.fetchall() if( len(resultSet)!=0 ) : company = [] for cursorRecord in resultSet: try: company.index( cursorRecord[0] ) continue except ValueError: company.append(cursorRecord[0]) print ""+check(cursorRecord[0])+"" cursor2.execute("select n5 from bulstatn where n1 = '"+cursorRecord[0]+"'") resultSet2 = cursor2.fetchone() print check(resultSet2[0]) print "
"