#!/usr/bin/python
# -*- coding: utf-8 -*-

import cgi, cgitb, os, sys, time, subprocess

cgitb.enable()

form = cgi.FieldStorage()
action = form['action'].value

print "Content-type:text/html\r\n\r\n"

if action == "1":
    os.system("echo 1 > /var/tmp/wui_actions")
    print("Defaults Restored Successfully")

elif action == "2":
    os.system("echo 2 > /var/tmp/wui_actions")
    print("Resetting Codec")

elif action == "3":
    os.system("echo 3 > /var/tmp/wui_actions")
    print("Rebooting Unit")

elif action == "4":
    cid = form['cid'].value
    os.system("echo 4" + cid + " > /var/tmp/wui_actions")
    print("Custom ID " + cid + " Set, Rebooting Unit")

elif action == "5":
    os.system("echo 5 > /var/tmp/wui_actions")
    print("Upgrading Controller")

elif action == "6":
    fs = form['fs'].value
    os.system("echo 6" + fs + " > /var/tmp/wui_actions")
    print("Formatting Device " + fs)

elif action == "7":
    pw = form['pw'].value
    if pw == "":
        os.system("echo 7 > /var/tmp/wui_actions")
        print("Clearing admin Password")
    else:
        os.system("echo 7" + pw + " > /var/tmp/wui_actions")
        print("Setting admin Password")

elif action == "8":
    os.system("echo 8 > /var/tmp/wui_actions")
    print("Creating download package")

else:
    print("Invalid Action")
	