commit e038e89b434f5f419d37eebcca30dd24d4cbfda5
parent 537a3ffea71014be70b8aaee61f14a1067d789e5
Author: rob <rob@tarina.org>
Date: Thu, 20 Feb 2025 11:46:17 +0200
yes
Diffstat:
M | server.py | | | 158 | +++++++++++++++++++++++++++---------------------------------------------------- |
1 file changed, 53 insertions(+), 105 deletions(-)
diff --git a/server.py b/server.py
@@ -29,7 +29,6 @@ urls = (
'/dropitem/(.*)?', 'dropitem',
'/payln/(.*)', 'payln',
'/goodies/(.*)', 'goodies',
- "/stats", "stats",
'/lightning?', 'lightning',
'/paybtc/(.*)', 'paybtc',
'/payment/(.*)', 'payment',
@@ -46,10 +45,8 @@ urls = (
'/bitcoin', 'bitcoin',
'/shipping/(.*)', 'shipping',
'/propaganda?', 'propaganda',
- '/uploads?', 'uploads',
'/config', 'config',
- '/payments?', 'payments',
- '/cv', 'cv')
+ '/payments?', 'payments')
bag = ''
@@ -73,6 +70,7 @@ rendersplash = web.template.render(templatedir, base="splash")
db = web.database(dbn='sqlite', db=basedir + "db/cyberpunkcafe.db")
session = web.session.Session(app,store,initializer={'login':0, 'privilege':0, 'bag':[], 'sessionkey':'empty'})
+
allowedchar = '_','-','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0'
#----------- Database setup -------------
@@ -95,24 +93,6 @@ def logged():
else:
return False
-
-#-------------Get files and sort em by date modified---------------
-
-def getfiles(filmfolder):
- #get a list of films, in order of settings.p file last modified
- films_sorted = []
- films = next(os.walk(filmfolder))[1]
- for i in films:
- uploaded = os.listdir(filmfolder + i + '/')
- for f in uploaded:
- if os.path.isfile(filmfolder + i + '/'+f) == True:
- lastupdate = os.path.getmtime(filmfolder + i + '/' + f)
- films_sorted.append((i,f,lastupdate))
- else:
- films_sorted.append((i,f,0))
- films_sorted = sorted(films_sorted, key=lambda tup: tup[2], reverse=True)
- return films_sorted
-
def sendmail(email, subject, msg):
#Send mail
echomsg = subprocess.Popen(('echo', msg), stdout=subprocess.PIPE)
@@ -217,31 +197,61 @@ def getavailable(productid):
return ''
return name.available
+def getbtcrate():
+ btc_to_euro = db.select("btcrate", where="currency='EUR'")
+ #shippinginfo = db.select('shipping', where="country='" + pendinginfo.country + "'", what='price, days')[0]
+ try:
+ if time.time() - btc_to_euro[0].timeadded > 6000:
+ btcrate = 64485
+ b = BtcConverter()
+ btcrate = int(b.get_latest_price('EUR'))
+ db.update('btcrate', where='currency="EUR"', rate=btcrate, timeadded=time.time())
+ else:
+ btc_to_euro = db.select("btcrate", where="currency='EUR'")
+ btcrate = btc_to_euro[0].rate
+ except:
+ db.insert('btcrate', currency='EUR', rate=64485, timeadded=time.time())
+ return btcrate
+
+def getbtcratetime():
+ btc_to_euro = db.select("btcrate", where="currency='EUR'")
+ btctime = btc_to_euro[0].timeadded
+ return datetime.datetime.fromtimestamp(btctime).strftime('%c')
+
def getprice(productid):
p = db.query("SELECT * FROM products WHERE id='"+str(productid)+"';")[0]
- b = BtcConverter()
+ #b = BtcConverter()
+ btcrate=getbtcrate()
if p.currency=='euro':
- sat = b.convert_to_btc(p.price/100, 'EUR') * 100000000
+ sat = 1/btcrate*(p.price/100) * 100000000
+ #sat = b.convert_to_btc(p.price/100, 'EUR') * 100000000
euro = p.price/100
if p.currency=='bitcoin':
- euro = b.convert_btc_to_cur(p.price/100000000,'EUR')
+ euro = btcrate*p.price/100000000
+ #euro = b.convert_btc_to_cur(p.price/100000000,'EUR')
sat = p.price
return int(sat), round(euro,2)
def btc_to_eur(amount):
- b = BtcConverter()
- euro = round(b.convert_btc_to_cur(amount/100000000,'EUR'),2)
+ #b = BtcConverter()
+ btcrate=getbtcrate()
+ #euro = round(b.convert_btc_to_cur(amount/100000000,'EUR'),2)
+ euro = round(btcrate*amount/100000000)
return euro
def eur_to_sat(amount):
- b = BtcConverter()
- btc = b.convert_to_btc(amount/100, 'EUR')
+ btcrate=getbtcrate()
+ #b = BtcConverter()
+ #btc = b.convert_to_btc(amount/100, 'EUR')
+ btc = 1/btcrate*(amount/100)
sat=btc*100000000
return int(sat)
def getrate():
- b = BtcConverter()
- return int(b.get_latest_price('EUR'))
+ #b = BtcConverter()
+ btcrate=getbtcrate()
+ #return int(b.get_latest_price('EUR'))
+ return int(btcrate)
def checkforoldbags():
print('checking for old bags')
@@ -315,10 +325,6 @@ def getpendinginfo():
class index():
def GET(self):
- ip = web.ctx['ip']
- referer = web.ctx.env.get('HTTP_REFERER', 'none')
- environ = web.ctx.env.get('HTTP_USER_AGENT', 'dunno')
- visitorlog(ip,referer,environ)
checkforoldbags()
i = web.input(dropitem=None, putinbag=None,error=None,prod=None,category=None)
if session.sessionkey == 'empty':
@@ -343,15 +349,10 @@ class index():
inbag = None
if inbag < 1:
session.sessionkey = 'empty'
- return render.index(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown)
+ return render.index(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown,getbtcratetime)
class almost():
def GET(self):
- ip = web.ctx['ip']
- referer = web.ctx.env.get('HTTP_REFERER', 'none')
- environ = web.ctx.env.get('HTTP_USER_AGENT', 'dunno')
- visitorlog(ip,referer,environ)
- visitors, total, unique = getvisits()
checkforoldbags()
i = web.input(dropitem=None, putinbag=None,error=None,prod=None,category=None)
if session.sessionkey == 'empty':
@@ -376,51 +377,8 @@ class almost():
inbag = None
if inbag < 1:
session.sessionkey = 'empty'
- return rendersplash.almost(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown, visitors, total, unique)
+ return rendersplash.almost(products,bag,session.sessionkey,productname,inbag,db,getprice,getrate,i.category, markdown)
-def visitorlog(ip, referer, environ):
- last = db.query('SELECT ip AS ip FROM visitors WHERE id=(SELECT MAX(id) FROM visitors)')
- try:
- lastip = last[0].ip
- except:
- lastip = 'none'
- if lastip != ip:
- country = ''
- country = os.popen('geoiplookup '+ip).read()
- #print(soundtype)
- countrycode = country.split(':')[1].split(',')[0].lower().strip()
- country = country.split(':')[1].split(',')[1].strip()
- #print('fuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu: '+ country)
- db.insert('visitors', ip=ip, referer=referer, environ=environ, country=country, countrycode=countrycode, time=datetime.datetime.now())
- print("added to visitor log")
- return
-
-def getvisitors():
- visitors = db.select('visitors')
- total = db.query('SELECT COUNT(*) AS total_visits FROM visitors')
- unique = db.query('SELECT COUNT(DISTINCT ip) AS unique_visits FROM visitors')
- return visitors, total[0].total_visits, unique[0].unique_visits
-
-def getvisits():
- limit=100
- visits = db.query("SELECT * FROM visitors ORDER BY time DESC LIMIT " + str(limit))
- visitors = db.select('visitors')
- total = db.query('SELECT COUNT(*) AS total_visits FROM visitors')
- unique = db.query('SELECT COUNT(DISTINCT ip) AS unique_visits FROM visitors')
- countrylist=[]
- for i in visits:
- if i.countrycode not in countrylist:
- countrylist.append(i.countrycode)
- #print('fuuuuuuuuuuuuuuu: '+i.countrycode)
- return countrylist, total[0].total_visits, unique[0].unique_visits
-
-class stats:
- def GET(self):
- if logged():
- visitors, total, unique = getvisitors()
- return render.stats(visitors, total, unique)
- else:
- raise web.seeother('/login')
class putinbag:
def GET(self, p):
@@ -586,13 +544,13 @@ class payln:
msg = 'You got a new order, from ' + customer.firstname + ' ' + customer.lastname + ' from ' + customer.country + ' email: ' + customer.email + ' this dude wantz ' + lninvoice['description']
else:
msg='sup?'
- sendmail(webmaster, 'Robs Shop', msg)
+ sendmail(webmaster, 'Gonzo Pi Shop', msg)
# send mail to customer
if ordertype()=='physical':
- msg = "Thank you for order " + lninvoice['description'] + " at Robins webshop, we'll be processing your order as soon as possible and send it to " + customer.firstname + ' ' + customer.lastname + ', ' + customer.address + ', ' + str(customer.postalcode) + ', ' + customer.town + ', ' + customer.country + '. To pay/view status or take a look at the digital goodies of your order please visit ' + baseurl + '/goodies/'+digitalkey
+ msg = "Thank you for order " + lninvoice['description'] + " at Tarina shop, we'll be processing your order as soon as possible and send it to " + customer.firstname + ' ' + customer.lastname + ', ' + customer.address + ', ' + str(customer.postalcode) + ', ' + customer.town + ', ' + customer.country + '. To pay/view status or take a look at the digital goodies of your order please visit ' + baseurl + '/goodies/'+digitalkey
else:
- msg="sup? thanks! here's a link to the digital goodies "+baseurl+'/goodies/'+digitalkey
- sendmail(customer.email, 'A message from Robins webshop', msg)
+ msg='sup? thanks! here the goodies '+baseurl+'/goodies/'+digitalkey
+ sendmail(customer.email, 'Gonzo Pi Shop', msg)
web.seeother('/payln/'+invoice_key)
if lninvoice['status'] == 'paid':
bag = db.query("SELECT * FROM paidbags WHERE sessionkey='"+invoice_key+"';")
@@ -624,9 +582,9 @@ class paybtc:
confirmations = int(i['confirmations'])
print(str(confirmations))
if invoice.datepaid == None and confirmations > 6:
- msg = 'Robins webshop order update! someone sent you Bitcoin! ' + baseurl + '/paybtc/' + invoice.invoice_key
+ msg = 'Gonzo Pi shop order update! someone sent you Bitcoin! ' + baseurl + '/paybtc/' + invoice.invoice_key
print(msg)
- sendmail(webmaster, 'Robs Shop', msg)
+ sendmail(webmaster, 'Gonzo Pi Shop', msg)
db.update('invoices', where="invoice_key='" + invoice.invoice_key + "'", status='paid', datepaid=time.strftime('%Y-%m-%d %H:%M:%S'))
pendinginfo = getpendinginfo()
bag = db.query("SELECT * FROM customerbag WHERE sessionkey='"+invoice_key+"';")
@@ -648,16 +606,16 @@ class orders():
paylink = 'payln/'
if i.status == 'thankyou':
msg="Hi " + customer.email + ", thank you for your order! You can track the status of your order at "+baseurl+'/'+paylink+i.key
- sendmail(customer.email, 'Robs Shop, a thank you!', msg)
+ sendmail(customer.email, 'Gonzo Pi Shop, a thank you!', msg)
elif i.status == 'shipped':
msg="Hi " + customer.email + ", your order has been shipped!. You can track the status of your order at "+baseurl+'/'+paylink+i.key
- sendmail(customer.email, 'Rob Shop, your order has been shipped!', msg)
+ sendmail(customer.email, 'Gonzo Pi Shop, your order has been shipped!', msg)
elif i.status == 'paynotice':
msg="Hi " + customer.email + ", we noticed you have an unpaid order in our shop, thank you. You can track the status of your order at " + baseurl + paylink + payment.invoice_key
- sendmail(customer.email, 'Rob Shop, order waiting for payment!', msg)
+ sendmail(customer.email, 'Gonzo Pi Shop, order waiting for payment!', msg)
elif i.status == 'paid':
msg="Hi " + customer.email + ", thank you! payment received. You can track the status of your order at " + baseurl + paylink + payment.invoice_key
- sendmail(customer.email, 'Rob Shop, order payment received', msg)
+ sendmail(customer.email, 'Gonzo Pi Shop, order payment received', msg)
raise web.seeother(referer)
payments = db.select('invoices', what='btc, ln, invoice_key, products, payment, amount, totsats, timestamp, status, datepaid, dateshipped', order='timestamp DESC')
if i.key == None and i.status != None:
@@ -863,12 +821,6 @@ class propaganda:
image.save(imgdir + '/thumb/'+soundname)
raise web.seeother('/propaganda')
-class uploads:
- def GET(self):
- if logged():
- uploaded = getfiles(staticdir+'upload/')
- return render.uploads(uploaded)
-
class config:
form = web.form.Form(
web.form.Textbox('name', web.form.notnull, description="Site name:"),
@@ -1162,10 +1114,6 @@ class shipping:
else:
raise web.seeother('/login')
-class cv:
- def GET(self):
- return render.cv()
-
class bitcoin:
def GET(self):
if logged():