def hdmi_post(request): action = None output = '0' inputs = '0' for key in request.POST.keys(): if key.startswith('output'): action = key[6:] break if action != None: inputs = action[1] output = action[0] outputint = int(output) status_labor = controller.status_powerstrip_labor() status_studio = controller.status_powerstrip_studio() status = media_template.get_template() if status['beamer_' + output + inputs] == "output_on": media_template.change_template('beamer_headline_' + output, 'off') media_template.change_template('beamer_onoff_' + output, 'beamer_off') media_template.change_template('beamer_' + output + inputs, 'output_off') else: media_template.change_template('beamer_headline_' + output, 'on') media_template.change_template('beamer_onoff_' + output, 'beamer_on') media_template.change_template('beamer_' + output + inputs, 'output_on') for i in range(1, 5): if str(i) != inputs: media_template.change_template('beamer_' + output + str(i), 'output_off') controller.control_hdmi_switch(inputs, output) return render(request, 'media.html', media_template.get_template())
def login(request): global account if request.META['REMOTE_ADDR'][0:8] == "132.199.": if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): post = form.save(commit=False) username = post.Benutzername try: auth = LDAPBackend() user = auth.authenticate(request, username, post.Passwort) if user is not None: request.session['Benutzername'] = username request.session['stream'] = False django_login( request, user, backend='django.contrib.auth.backends.ModelBackend' ) return render(request, 'media.html', media_template.get_template()) else: form = LoginForm() return redirect('login') except: print('exceptLDAP') form = LoginForm() return redirect('login') else: form = LoginForm() return render(request, 'login.html', {'form': form}) else: form = LoginForm() return render(request, 'login.html', {'form': form})
def video_stream(request): global new_stream new_stream = ffstr.Stream() all_sessions = Session.objects.filter(expire_date__gte=timezone.now()) is_online = False for session in all_sessions: session_data = session.get_decoded() if session_data['stream'] == True: if session_data['Benutzername'] == request.session['Benutzername']: response = render(request, 'stream.html', {}) response['stream'] = 'true' return response else: is_online = True if is_online is False: usb_switch.USBSwitch().find_usb_switch() new_stream.start_live(session_data['Benutzername']) request.session['stream'] = True media_template.change_template('stream', 'output_on stream_disable') response = render(request, 'stream.html', {}) response['stream'] = 'true' return response else: return render(request, 'media.html', media_template.get_template())
def powerstrip_post(request): room = 0 socket = 0 action = "" for key in request.POST.keys(): if key.startswith('socket'): action = key[6:] break if action is not None: room = action[0] socket = action[1] control = controller.control_powerstrip(room, socket) if control == 'on': media_template.change_template('powerstrip_' + room, 'on') media_template.change_template('socket_' + room + socket, 'output_on') else: if room == '2': status = controller.status_powerstrip_labor() if status['2'] == 0: if status['3'] == 0: media_template.change_template('powerstrip_' + room, 'off') else: media_template.change_template('powerstrip_' + room, 'off') media_template.change_template('socket_' + room + socket, 'output_off') return render(request, 'media.html', media_template.get_template())
def beamer_post(request): output = 0 for key in request.POST.keys(): if key.startswith('beamer'): output = key[6] break if output is not None: status_labor = controller.status_powerstrip_labor() status_studio = controller.status_powerstrip_studio() if int(output) > 2: if status_labor['beamer_' + output] == 1: media_template.change_template('beamer_headline_' + output, 'off') media_template.change_template('beamer_onoff_' + output, 'beamer_off') feedback = controller.hdmi_status(output) try: media_template.change_template( 'beamer_' + output + feedback, 'output_off') except: pass else: media_template.change_template('beamer_headline_' + output, 'on') media_template.change_template('beamer_onoff_' + output, 'beamer_on') feedback = controller.hdmi_status(output) try: media_template.change_template( 'beamer_' + output + feedback, 'output_on') except: pass else: if status_studio['beamer_' + output] == 1: media_template.change_template('beamer_headline_' + output, 'off') media_template.change_template('beamer_onoff_' + output, 'beamer_off') feedback = controller.hdmi_status(output) try: media_template.change_template( 'beamer_' + output + feedback, 'output_off') except: pass else: media_template.change_template('beamer_headline_' + output, 'on') media_template.change_template('beamer_onoff_' + output, 'beamer_on') feedback = controller.hdmi_status(output) try: media_template.change_template( 'beamer_' + output + feedback, 'output_on') except: pass controller.control_beamer(output) return render(request, 'media.html', media_template.get_template())
def light_post(request): change = controller.control_light() if change == "on": media_template.change_template('light_1', 'on') media_template.change_template('lamp_1', 'light_on') else: media_template.change_template('light_1', 'off') media_template.change_template('lamp_1', 'light_off') return render(request, 'media.html', media_template.get_template())
def delete_all_files(request): username = request.session['Benutzername'] os.chdir('/home/roomuser/Roomware/' + username) path = '/home/roomuser/Roomware/' + username files = os.listdir(path) for i in range(len(files)): filepath = path + '/' + files[i] os.remove(filepath) os.chdir('/home/roomuser/Roomware') os.rmdir(path) return render(request, 'media.html', media_template.get_template())
def stream_file(request, file=None): username = request.session['Benutzername'] try: path = '/home/roomuser/Roomware/' + username + '/' files = os.listdir(path) if files is not None: if file is not None: filepath = path + file return serve(request, os.path.basename(filepath), os.path.dirname(filepath)) else: return render(request, 'stream_files.html', {'files': files}) except: return render(request, 'media.html', media_template.get_template())
def delete_file(request, file=None): if file is not None: username = request.session['Benutzername'] path = '/home/roomuser/Roomware/' + username filepath = path + '/' + file os.remove(filepath) if len(os.listdir(path)) == 0: os.chdir('/home/roomuser/Roomware') os.rmdir(path) return render(request, 'media.html', media_template.get_template()) else: files = os.listdir(path) return render(request, 'stream_files.html', {'files': files}) else: return redirect('link')
def usb_switch(request): output = 0 for key in request.POST.keys(): if key.startswith('usb_output'): output = key[10] break if output is not None: controller.control_usb_switch(output) if output != "1": media_template.change_template('usb', 'on') for i in range(1, 5): if str(i) != output: media_template.change_template('usb_output_' + str(i), 'output_off') else: media_template.change_template('usb_output_' + str(i), 'output_on') else: media_template.change_template('usb', 'off') media_template.change_template('usb_output_2', 'output_off') media_template.change_template('usb_output_3', 'output_off') media_template.change_template('usb_output_4', 'output_off') return render(request, 'media.html', media_template.get_template())
def post_media(request): if request.user.is_authenticated: return render(request, 'media.html', media_template.get_template()) else: return redirect('login')
def stream_stop(request): new_stream.stop_stream() request.session['stream'] = False media_template.change_template('stream', 'output_off') return render(request, 'media.html', media_template.get_template())