def serveStaticResource(resource): """ Return a static image or resource """ # ban MJ12BOT, it ignores robots.txt user_agent = request.headers.get('User-Agent') if user_agent and user_agent.find('MJ12BOT') != -1: abort(403) # log certain kinds of files if resource.endswith('.cab'): try: db = LvfsDatabase(os.environ) clients = LvfsDatabaseClients(db) clients.log(datetime.date.today(), LvfsDownloadKind.FIRMWARE) clients.increment(_get_client_address(), os.path.basename(resource), user_agent) except CursorError as e: print str(e) # firmware blobs are stored on S3 now if resource.startswith('downloads/'): return redirect(os.path.join(CDN_URI, resource), 301) # static files served locally return send_from_directory('static/', resource)
def analytics(): """ A analytics screen to show information about users """ # security check if session['username'] != 'admin': return error_permission_denied('Unable to view analytics') db = LvfsDatabase(os.environ) db_clients = LvfsDatabaseClients(db) labels_days = _get_chart_labels_days()[::-1] data_days = db_clients.get_stats_for_month(LvfsDownloadKind.FIRMWARE)[::-1] labels_months = _get_chart_labels_months()[::-1] data_months = db_clients.get_stats_for_year(LvfsDownloadKind.FIRMWARE)[::-1] labels_user_agent, data_user_agent = db_clients.get_user_agent_stats() return render_template('analytics.html', labels_days=labels_days, data_days=data_days, labels_months=labels_months, data_months=data_months, labels_user_agent=labels_user_agent, data_user_agent=data_user_agent)
def serveStaticResource(resource): """ Return a static image or resource """ # log certain kinds of files kind = None if resource.endswith('.cab'): kind = LvfsDownloadKind.FIRMWARE elif resource.endswith('.xml.gz.asc'): kind = LvfsDownloadKind.SIGNING elif resource.endswith('.xml.gz'): kind = LvfsDownloadKind.METADATA if kind is not None: try: filename = os.path.basename(resource) db = LvfsDatabase(os.environ) clients = LvfsDatabaseClients(db) clients.increment(_get_client_address(), kind, filename, request.headers.get('User-Agent')) except CursorError as e: print str(e) # use apache for the static file so we can scale if 'OPENSHIFT_APP_DNS' in os.environ: if resource.startswith('download/'): # if the file does not exist get it from the database # (which means we can scale on OpenShift) if not os.path.exists(resource): db = LvfsDatabase(os.environ) db_cache = LvfsDatabaseCache(db) db_cache.to_file(resource) uri = "https://%s/static/%s" % (os.environ['OPENSHIFT_APP_DNS'], resource) return redirect(uri, 301) return send_from_directory('static/', resource)
def firmware_id(fwid): """ Show firmware information """ # get details about the firmware db = LvfsDatabase(os.environ) db_firmware = LvfsDatabaseFirmware(db) try: item = db_firmware.get_item(fwid) except CursorError as e: return error_internal(str(e)) if not item: return error_internal('No firmware matched!') # we can only view our own firmware, unless admin qa_group = item.qa_group if qa_group != session['qa_group'] and session['username'] != 'admin': return error_permission_denied('Unable to view other vendor firmware') if not qa_group: embargo_url = '/downloads/firmware.xml.gz' qa_group = 'None' else: embargo_url = '/downloads/firmware-%s.xml.gz' % _qa_hash(qa_group) db = LvfsDatabase(os.environ) db_clients = LvfsDatabaseClients(db) cnt_fn = db_clients.get_firmware_count_filename(item.filename) data_fw = db_clients.get_stats_for_fn(12, 30, item.filename) return render_template('firmware-details.html', fw=item, qa_capability=session['qa_capability'], orig_filename='-'.join(item.filename.split('-')[1:]), embargo_url=embargo_url, qa_group=qa_group, cnt_fn=cnt_fn, fwid=fwid, graph_labels=_get_chart_labels_months()[::-1], graph_data=data_fw[::-1])