Exemplo n.º 1
0
def before_request():
	if not request.path.startswith('/static'):
		now=datetime.datetime.now().strftime(config.DBDATEFORMAT)
		try:
			a=request.remote_addr
		except:
			a='Unknown'
		try:
			host=str(socket.gethostbyaddr(request.remote_addr)[0])
		except:
			host='Unknown'
		db=util.db_get()
		with db:
			c=db.cursor()
			q="INSERT INTO ACCESS VALUES (?,?,?,?,?)"
			r=request.method+' '+request.path
			c.execute(q,(now,a,host,r,repr(request.user_agent)))
		return
Exemplo n.º 2
0
def conf():
	cloud='on' if util.isCloudActive() else 'off'
	now=datetime.datetime.now().strftime(config.DATEFORMAT)
	res=None
	# if arrived here by submitting the form
	if request.method == 'POST':
		# get setting for webcam resolution
		res=request.form['res']
		util.db_setvalue(config.DB_WEBCAMRES,res)
		# get setting for cloud save desired state
		clds=request.form['cloud']
		# and try to start it if it was stopped
		if cloud=='off' and clds=='on':
			ps=subprocess.Popen("sudo /etc/init.d/thingspeak start", shell=True, stdout=subprocess.PIPE)
			flash('ThingSpeak daemon started')
		elif cloud=='on' and clds=='off':
			ps=subprocess.Popen("sudo /etc/init.d/thingspeak stop", shell=True, stdout=subprocess.PIPE)
			flash('ThingSpeak daemon stopped')
		flash('Settings saved')
	else:
		res=util.nvl(util.db_getvalue(config.DB_WEBCAMRES),'640x480')

	db=util.db_get()
	with db:
		c=db.cursor()
		q="SELECT * FROM ACCESS ORDER BY DATETIME DESC LIMIT 100"
		c.execute(q)
		rows=c.fetchall()
		log=''
		for row in rows:
			log=log+row[0]+';'+row[1]+';'+row[2]+';'+row[3]+';'+row[4]+'\n'
	tData={
		'cloud':cloud,
		'res':res,
		'time':now,
		'log':log
	}
	return render_template('conf.html',**tData)