light.cgi 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/usr/bin/python3
  2. import cgi
  3. import cgitb; cgitb.enable() # for troubleshooting
  4. print( "Content-type: text/html")
  5. print()
  6. print( """
  7. <html>
  8. <head><title>Licht WEB</title></head>
  9. <body>
  10. <h3> Licht WEB </h3>
  11. """)
  12. #form = cgi.FieldStorage()
  13. #message = form.getvalue("message", "(no message)")
  14. print("<br>")
  15. import os
  16. ENV = os.environ
  17. for env in ENV:
  18. val=ENV[env]
  19. #print(env)
  20. #print(" = ")
  21. #print(val)
  22. #print("<br>")
  23. ARGS = {}
  24. if "QUERY_STRING" in ENV:
  25. _args = ENV["QUERY_STRING"]
  26. if "&" in _args:
  27. args = _args.split("&")
  28. else:
  29. args = _args
  30. for arg in args:
  31. import urllib.parse
  32. if "=" in arg:
  33. k,v = arg.split("=",1)
  34. v = urllib.parse.unquote(v)
  35. ARGS[k]=v
  36. print("{} = {} <br>".format(k,v))
  37. js = """
  38. <script>
  39. function xGET(){
  40. dmx = document.getElementById("DMX").value;
  41. val = document.getElementById("VALUE").value;
  42. fade = document.getElementById("FADE").value;
  43. xget(dmx,val,fade)
  44. }
  45. function cmd2(){
  46. xcmd2 = document.getElementById("cmd2").value;
  47. _cmd2(xcmd2)
  48. }
  49. function _cmd2(xcmd2=""){
  50. const http = new XMLHttpRequest();
  51. url = './light.cgi?&CMD2=' + xcmd2
  52. http.open("GET", url);
  53. http.send();
  54. http.onreadystatechange = (e) => {
  55. console.log('done',e)
  56. }
  57. }
  58. function xget(dmx=1,val=100,fade=1){
  59. const http = new XMLHttpRequest();
  60. url = './light.cgi?&CMD=[{"VALUE": '+val+', "args": [], "FADE": '+fade+', "DMX": "'+dmx+'"}]'
  61. http.open("GET", url);
  62. http.send();
  63. http.onreadystatechange = (e) => {
  64. console.log('done',e)
  65. }
  66. }
  67. function hN(){ // NEXT
  68. dmx = document.getElementById("highlight").value;
  69. dmx = parseInt(dmx) +1
  70. document.getElementById("highlight").value = dmx;
  71. if( dmx != 63 && dmx != 66){
  72. xget(dmx,255,0)
  73. }
  74. dmx -= 1
  75. if( dmx != 63 && dmx != 66){
  76. xget(dmx,0,0)
  77. }
  78. }
  79. function hP(){ // PREVIEW
  80. dmx = document.getElementById("highlight").value;
  81. dmx = parseInt(dmx)-1
  82. document.getElementById("highlight").value = dmx;
  83. if( dmx != 63 && dmx != 66){
  84. xget(dmx,255,0)
  85. }
  86. dmx += 1
  87. if( dmx != 63 && dmx != 66){
  88. xget(dmx,0,0)
  89. }
  90. }
  91. </script>
  92. DMX<input type=number id=DMX value=10>
  93. <br>
  94. VALUE<input type=number id=VALUE value=255>
  95. <br>
  96. FADE<input type=number id=FADE value=1>
  97. <br>
  98. <input type=button value=GO onclick=xGET()>
  99. <br>
  100. <br>
  101. <br>
  102. Highlight
  103. <input type=button value="-" onclick=hP() size=10>
  104. <input type=number id=highlight value=10 size=5>
  105. <input type=button value="+" onclick=hN() size=10>
  106. <br>
  107. <br>
  108. <br>
  109. CMD2:
  110. <input id=cmd2 value=10 size=5 type=text value='10,200;11,200'>
  111. <input type=button value="GO" onclick=cmd2() size=10>
  112. <br>
  113. <br>
  114. """
  115. #if "CMD" not in ARGS:
  116. # pass
  117. #elif "CMD2" not in ARGS:
  118. # pass
  119. #else:
  120. if 1:
  121. print(js)
  122. print("<br>")
  123. print("beispiel <br>")
  124. print('&CMD=[{"VALUE": 55, "args": [], "FADE": 3, "DMX": "1"}]')
  125. print("<br>")
  126. if "CMD" in ARGS:
  127. CMD = ARGS["CMD"]
  128. CMD = CMD.replace("'","")
  129. CMD = CMD.replace("<","")
  130. CMD = CMD.replace(">","")
  131. CMD = CMD.replace(";","")
  132. CMD = CMD.replace("|","")
  133. #python3 /opt/LibreLight/Xdesk/lib/zchat.py data '[{"VALUE": 255, "args": [], "FADE": 0, "DMX": "1"}]
  134. cmd = 'python3 /opt/LibreLight/Xdesk/lib/zchat.py data \'{}\''.format(CMD)
  135. print("$ ",cmd, "<br>")
  136. print("<br>")
  137. r=os.popen(cmd)
  138. for l in r:
  139. l=l.replace("<","&lt;")
  140. l=l.replace(">","&gt;")
  141. print(">",l,"<br>")
  142. if "CMD2" in ARGS:
  143. import lib.zchat as zchat
  144. import json
  145. c = zchat.Client()
  146. cmd2 = ARGS["CMD2"]
  147. print("<br>")
  148. print("CMD2",cmd2)
  149. print("<br>")
  150. for j in cmd2.split(";"):
  151. if "," in j:
  152. fade= 0.3
  153. dmx,val = j.split(",")
  154. val = int(val)
  155. try:
  156. data =[{"VALUE": val, "args": [], "FADE": fade, "DMX": str(dmx)}]
  157. i = json.dumps(data)
  158. print("i",i)
  159. print("<br>")
  160. #i = input("cmd:")
  161. c.send(bytes(i,"utf8"))
  162. except Exception as e:
  163. print("e",e)
  164. print( """
  165. </html>
  166. """)