changeset 1461:517cbb905d4c

remote suspend, wifi group arg Ignore-this: 76cd196b934298df35125bd180ede9c6 darcs-hash:1893e27489c5537950d377dfde761497f906df6c
author drewp <drewp@bigasterisk.com>
date Sat, 23 Nov 2019 12:02:32 -0800
parents 6c6b14c39cd2
children 2b29f14eb6bd
files service/wifi/Dockerfile service/wifi/index.html service/wifi/wifi.py
diffstat 3 files changed, 20 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/service/wifi/Dockerfile	Wed Sep 25 17:56:28 2019 -0700
+++ b/service/wifi/Dockerfile	Sat Nov 23 12:02:32 2019 -0800
@@ -9,7 +9,7 @@
 # not sure why this doesn't work from inside requirements.txt
 RUN pip3 install --index-url https://projects.bigasterisk.com/ --extra-index-url https://pypi.org/simple -U 'https://github.com/drewp/cyclone/archive/python3.zip?v2'
 
-COPY *.py *.n3 *.html ./
+COPY *.py *.n3 *.html *.js  ./
 
 EXPOSE 9070
 
--- a/service/wifi/index.html	Wed Sep 25 17:56:28 2019 -0700
+++ b/service/wifi/index.html	Sat Nov 23 12:02:32 2019 -0800
@@ -17,15 +17,7 @@
 <body class="rdfBrowsePage">
   <template id="t" is="dom-bind">
     <style>
-     body {
-         background: black;
-         color: white;
-     }
-     a {
-         color: #b1b1fd;
-         text-shadow: 1px 1px 0px #0400ff94;
-         text-decoration-color: #00007714;
-     }
+
      #subjectRequest {
          width: 50em;
      }
@@ -53,7 +45,7 @@
           if (!dirty) {
             return;
           }
-          render(graphView(sg.graph.graph), out);
+          render(graphView(sg.graph.graph, /*showGroups=*/false), out);
           dirty = false;
         };
 
@@ -69,6 +61,10 @@
   <script>
 
   </script>
+
+  <form method="POST" action="remoteSuspend"><button>Suspend windows/VR machine</button></form>
+  <!-- also put wakeonlan actions down here -->
+
 </body>
 
 </html>
--- a/service/wifi/wifi.py	Wed Sep 25 17:56:28 2019 -0700
+++ b/service/wifi/wifi.py	Sat Nov 23 12:02:32 2019 -0800
@@ -39,7 +39,7 @@
         age = time.time() - self.settings.poller.lastPollTime
         if age > 10:
             raise ValueError("poll data is stale. age=%s" % age)
-            
+
         self.set_header("Content-Type", "text/html")
         self.write(open("index.html").read())
 
@@ -59,7 +59,7 @@
 
 def connectedAgoString(conn):
     return ago.human(conn.astimezone(tz.tzutc()).replace(tzinfo=None))
-    
+
 class Table(PrettyErrorHandler, cyclone.web.RequestHandler):
     def get(self):
         def rowDict(row):
@@ -107,7 +107,7 @@
         assert dt < 10, "last poll was %s sec ago" % dt
 
     @inlineCallbacks
-    def poll(self):     
+    def poll(self):
         try:
             newAddrs = yield self.wifi.getPresentMacAddrs()
             self.onNodes(newAddrs)
@@ -146,7 +146,7 @@
             'fields': {'value': value},
             'time': now,
         }
-        
+
     def computeActions(self, newWithSignal):
         actions = []
 
@@ -159,7 +159,7 @@
                 # wifi but don't have an ip yet. We'll record an
                 # action with no ip and then never record your ip.
                 d['ip'] = addr.ip
-            return d                             
+            return d
 
         for addr in newWithSignal:
             if addr.mac not in [r.mac for r in self.lastWithSignal]:
@@ -212,6 +212,11 @@
                 g.add((dev.uri, ROOM['connected'], Literal(conn), ctx))
         masterGraph.setToGraph(g)
 
+class RemoteSuspend(PrettyErrorHandler, cyclone.web.RequestHandler):
+    def post(self):
+        # windows is running shutter (https://www.den4b.com/products/shutter)
+        fetch('http://DESKTOP-GOU4AC4:8011/action', postdata={'id': 'Sleep'})
+
 
 if __name__ == '__main__':
     args = docopt.docopt('''
@@ -234,7 +239,7 @@
 
     config = ConjunctiveGraph()
     config.parse(open('private_config.n3'), format='n3')
-    
+
     masterGraph = PatchableGraph()
     wifi = Wifi(config)
     poller = Poller(wifi, mongo)
@@ -245,10 +250,12 @@
         cyclone.web.Application(
             [
                 (r"/", Index),
+                (r"/(wifi\.js)", cyclone.web.StaticFileHandler, {"path": '.'}),
                 (r'/json', Json),
                 (r'/graph', CycloneGraphHandler, {'masterGraph': masterGraph}),
                 (r'/graph/events', CycloneGraphEventsHandler, {'masterGraph': masterGraph}),
                 (r'/table', Table),
+                (r'/remoteSuspend', RemoteSuspend),
                 #(r'/activity', Activity),
             ],
             wifi=wifi,