def settings_form( request, template = 'settings_form.html' ): context = {} user = request.user if request.method == 'POST': form = SettingsForm(request.POST.copy()) if form.is_valid(): # Cycle through the settings and save them data = form.cleaned_data for setting in USER_SETTINGS: name = setting['name'] set_setting(user, name, data[name]) context['saved'] = True else: # Read user settings and build the form settings = {} for setting in USER_SETTINGS: name = setting['name'] settings[name] = get_setting(user, name) form = SettingsForm(settings) context['form'] = form return render_to_response(template, context, context_instance=RequestContext(request))
def file_download(uuid, url, filename, expires_at): print "task executing", url print "filename", filename server_uuid=get_setting("server_uuid") file_dir = create_file_directories(uuid) print "file_dir", file_dir #uuid_filename file_path = file_dir+"/"+filename urllib.urlretrieve(url, file_path) sha256_hash = hashfile(file_path) f=File.objects.create(uuid=uuid, name=filename, file_sha256=sha256_hash) f.save() data={ "username": username, "ip_address": clientserver_ip, 'file_uuid': uuid, 'file_hash': sha256_hash, } to_hash = 'FILE_DOWNLOADED%s%s%s%s' % (data["ip_address"], data["file_uuid"], data["file_hash"], server_uuid) test_hash = hashlib.sha256(to_hash).hexdigest() print (data["ip_address"], data["file_uuid"], data["file_hash"], server_uuid) print to_hash, test_hash data['sign_key_clientserver'] = test_hash results=call_api("/clientserver/file_downloaded", urllib.urlencode(data)) print results return uuid+url
def _can_create(self, user): vm_num = ICDVm.objects.filter(user = user, deleted=False).count() vm_num_limit = get_setting('vm_num_limit') if vm_num_limit.isdigit(): vm_num_limit = int(vm_num_limit) else: vm_num_limit = 3 return vm_num < vm_num_limit
def delete(request): server_uuid=get_setting("server_uuid") if request.method == "POST": uuid=request.POST["uuid"] sign_key_clientserver=request.POST["sign_key_clientserver"] to_hash = '%s%s%s%s' % ("DELETE", uuid, server_uuid) test_hash = hashlib.sha256(to_hash).hexdigest() if sign_key_clientserver!=test_hash: return HttpResponse('{"successful": false, "error": "signature invalid"}') try: original=File.objects.get(uuid=uuid) original.remove_file() except File.DoesNotExist: return HttpResponse('{"successful": false, "error": "file with that uuid not found"}') return HttpResponse('{"successful": false, "error": "wrong request method"}')
def add_file(request): server_uuid=get_setting("server_uuid") if request.method == "POST": uuid=request.POST["uuid"] sign_key_clientserver=request.POST["sign_key_clientserver"] url=request.POST["url"] filename=request.POST["filename"] expires_at=request.POST["expires_at"] # to_hash = 'ADD_FILE%s%s%s' % (file_uuid, url, server_uuid) to_hash = '%s%s%s%s' % ("ADD_FILE", uuid, url, server_uuid) print ("ADD_FILE", uuid, url, server_uuid), to_hash test_hash = hashlib.sha256(to_hash).hexdigest() if sign_key_clientserver!=test_hash: return HttpResponse('{"successful": false, "error": "signature invalid"}') file_download.delay(uuid, url, filename, expires_at) return HttpResponse('{"successful": true}') return HttpResponse('{"successful": false, "error": "wrong request method"}')
def alias(request): server_uuid=get_setting("server_uuid") if request.method == "POST": uuid=request.POST["uuid"] new_uuid=request.POST["new_uuid"] lifetime=request.POST["lifetime"] sign_key_clientserver=request.POST["sign_key_clientserver"] to_hash = '%s%s%s%s%s' % ("ALIAS", uuid, new_uuid, lifetime, server_uuid) test_hash = hashlib.sha256(to_hash).hexdigest() if sign_key_clientserver!=test_hash: return HttpResponse('{"successful": false, "error": "signature invalid"}') try: original=File.objects.get(uuid=uuid) file_alias=create_alias(original, new_uuid, lifetime) return HttpResponse('{"successful": true}') except File.DoesNotExist: return HttpResponse('{"successful": false, "error": "file with that uuid not found"}') return HttpResponse('{"successful": false, "error": "wrong request method"}')
def setting(): use_wifi_attendance, use_notice_email, account, cc, working = get_setting() return render_template('user/setting.html', **locals())
macs.append(data['mac']) while True: wifi_connected = utils.check_wifi_connected() if not wifi_connected: utils.connect_wifi() for ip in range(155): if ip not in [0, 1, 2, 5, 255]: network = utils.check_arp(ip) if network: # app.logger.info(network) if network['mac'] not in macs: macs.append(network['mac']) devices.new_post({'mac': network['mac']}) mac.post(network) time.sleep(5) if __name__ == '__main__': app = create_app() save_db() use_wifi_attendance, _, _, _, _ = get_setting() if use_wifi_attendance: th = threading.Thread(target=check_mac) th.daemon = True th.start() app.run(host='127.0.0.1', debug=False, threaded=True)