Exemple #1
0
def main():
  msg.init()
  debug("Spawned")

  m = msg.recv()
  if m[0] == msg.InitClient:
    rfile = m[1]
    wfile = m[2]
  else:
    debug("should have received InitClient message first")

  signal.signal(signal.SIGTERM, mkhandler(rfile, wfile))

  rdy = []
  while rdy == []:
    rdy, _, _ = select.select([rfile], [], [])
  data = rfile.readline()
  if data:
    req = HTTPRequest(rfile, data)
    if hasattr(req, 'path'):
      print('Resource: ' + req.path)
      msg.send(msg.FileReq, req.path)
      m = msg.recv()
      if m[0] == msg.FileRes:
        [_, name, fd] = m
        response = fd.read()
        contents = (
          "HTTP/1.0 200 OK\r\n"
          + "Content-Length: " + str(len(response)) + "\r\n"
          + "Content-Type: text/html\r\n\r\n"
          + response
        )
        debug("access to file " + name + " was authorized")
        wfile.write(contents)
      elif m[0] == msg.FileResF:
        debug("access to file " + m[1] + " was refused")
        response = "Access Forbidden"
        wfile.write(
          "HTTP/1.0 403 Forbidden\r\n"
          + "Content-Length: " + str(len(response)) + "\r\n"
          + "Content-Type: text/html\r\n\r\n"
          + response
        )
      else:
        debug("unexpected message " + str(m))

  debug('Shutting down')
  rfile.close()
  wfile.close()

  # YOU MUSTN'T DIE SOLDIER!
  while True:
    time.sleep(3600)
Exemple #2
0
def main():
    msg.init()
    while True:
        msg.send('M', 'Hello world!')
        m = msg.recv()
        print(m)
        time.sleep(1)
Exemple #3
0
def main():
  msg.init()
  while True:
    msg.send('M', 'Hello world!')
    m = msg.recv()
    print(m)
    time.sleep(1)
Exemple #4
0
def main():
  msg.init()
  debug("Spawned")
  while True:
    m = msg.recv()
    s = str(m)
    try:
      if m[0] == msg.ACLoginReq:
        [_, user, password, compid, rfile, wfile] = m
        try: ok = password == credentials[user]
        except KeyError: ok = False
        if ok:
          debug(user + " logged in")
          debug("RFile: " + str(rfile))
          debug("WFile: " + str(wfile))
          msg.send(msg.ACLoginResT, user, compid, rfile, wfile)
        else:
          debug(user + " refused (wrong password)")
          msg.send(msg.ACLoginResF, user, compid)
      elif m[0] == msg.ACFileReq:
        [_, user, compid, request] = m
        try: ok = user in owners[request]
        except KeyError: ok = False
        if ok:
          debug(user + " access to " + request + " authorized")
          msg.send(msg.ACFileResT, user, compid, request)
        else:
          debug(user + " access to " + request + " refused")
          msg.send(msg.ACFileResF, user, compid, request)
      else:
        debug("Unhandled message " + s)
    except ValueError:
      debug("Unexpected payload " + s)
Exemple #5
0
def main():
    msg.init()
    debug("Spawned")

    m = msg.recv()
    if m[0] == msg.InitClient:
        rfile = m[1]
        wfile = m[2]
    else:
        debug("should have received InitClient message first")

    signal.signal(signal.SIGTERM, mkhandler(rfile, wfile))

    rdy = []
    while rdy == []:
        rdy, _, _ = select.select([rfile], [], [])
    data = rfile.readline()
    if data:
        req = HTTPRequest(rfile, data)
        if hasattr(req, 'path'):
            print('Resource: ' + req.path)
            msg.send(msg.FileReq, req.path)
            m = msg.recv()
            if m[0] == msg.FileRes:
                [_, name, fd] = m
                response = fd.read()
                contents = ("HTTP/1.0 200 OK\r\n" + "Content-Length: " +
                            str(len(response)) + "\r\n" +
                            "Content-Type: text/html\r\n\r\n" + response)
                debug("access to file " + name + " was authorized")
                wfile.write(contents)
            elif m[0] == msg.FileResF:
                debug("access to file " + m[1] + " was refused")
                response = "Access Forbidden"
                wfile.write("HTTP/1.0 403 Forbidden\r\n" + "Content-Length: " +
                            str(len(response)) + "\r\n" +
                            "Content-Type: text/html\r\n\r\n" + response)
            else:
                debug("unexpected message " + str(m))

    debug('Shutting down')
    rfile.close()
    wfile.close()

    # YOU MUSTN'T DIE SOLDIER!
    while True:
        time.sleep(3600)
Exemple #6
0
    def handle_msgs(self, source, condition):
        m = msg.recv()
        if m[0] == msg.ResResource:
            print "Resource Response"
            tf = tempfile.NamedTemporaryFile(delete=False)
            tf.write(m[1].read())
            tf_name = tf.name
            tf.close()

            self.browser.open('file://' + tf_name)
        elif m[0] == msg.Go:
            print "Go"
            self.req_resource(m[1])
        elif m[0] == msg.MouseClick:
            if m[3] == 1:
                e_type = gtk.gdk.BUTTON_PRESS
                e_str = 'button-press-event'
            else:
                e_type = gtk.gdk.BUTTON_RELEASE
                e_str = 'button-release-event'

            e = gtk.gdk.Event(e_type)
            e.button = 1
            e.x = float(m[1])
            e.y = float(m[2])
            e.window = self.browser.get_window()
            self.browser.emit(e_str, e)
        elif m[0] == msg.KeyPress:
            e = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
            e.window = self.browser.get_window()

            if int(m[1]) == 19:
                e.keyval = int(keysyms.Page_Up)
                e.hardware_keycode = gtk.gdk.keymap_get_default(
                ).get_entries_for_keyval(int(keysyms.Page_Up))[0][0]
            elif int(m[1]) == 20:
                e.keyval = int(keysyms.Page_Down)
                e.hardware_keycode = gtk.gdk.keymap_get_default(
                ).get_entries_for_keyval(int(keysyms.Page_Down))[0][0]
            elif int(m[1]) == 8:
                e.keyval = int(keysyms.BackSpace)
                e.hardware_keycode = gtk.gdk.keymap_get_default(
                ).get_entries_for_keyval(int(keysyms.BackSpace))[0][0]
            elif int(m[1]) == 9:
                e.keyval = int(keysyms.Tab)
                e.hardware_keycode = gtk.gdk.keymap_get_default(
                ).get_entries_for_keyval(int(keysyms.Tab))[0][0]
            elif int(m[1]) == 10:
                e.keyval = int(keysyms.Return)
                e.hardware_keycode = gtk.gdk.keymap_get_default(
                ).get_entries_for_keyval(int(keysyms.Return))[0][0]
            else:
                e.keyval = int(m[1])

            self.browser.emit('key-press-event', e)

        return True
Exemple #7
0
def main():
  msg.init()
  debug("Spawned")
  while True:
    m = msg.recv()
    if m[0] == msg.DFileReq:
      [_, user, compid, request] = m
      fd = open("../../../test/webserver/" + request)
      msg.send(msg.DFileRes, user, compid, request, fd)
    else:
      debug("Unhandled message " + str(m))
    debug(str(m))
Exemple #8
0
def main():
    msg.init()
    debug("Spawned")
    while True:
        m = msg.recv()
        if m[0] == msg.DFileReq:
            [_, user, compid, request] = m
            fd = open("../../../test/webserver/" + request)
            msg.send(msg.DFileRes, user, compid, request, fd)
        else:
            debug("Unhandled message " + str(m))
        debug(str(m))
Exemple #9
0
  def handle_msgs(self, source, condition):
    m = msg.recv()
    if m[0] == msg.ResResource:
      print "Resource Response"
      tf = tempfile.NamedTemporaryFile(delete=False)
      tf.write(m[1].read())
      tf_name = tf.name
      tf.close()

      self.browser.open('file://' + tf_name)
    elif m[0] == msg.Go:
      print "Go"
      self.req_resource(m[1])
    elif m[0] == msg.MouseClick:
      if m[3] == 1:
        e_type = gtk.gdk.BUTTON_PRESS
        e_str = 'button-press-event'
      else:
        e_type = gtk.gdk.BUTTON_RELEASE
        e_str = 'button-release-event'

      e = gtk.gdk.Event(e_type)
      e.button = 1
      e.x = float(m[1])
      e.y = float(m[2])
      e.window = self.browser.get_window()
      self.browser.emit(e_str, e)
    elif m[0] == msg.KeyPress:
      e = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
      e.window = self.browser.get_window()
      
      if int(m[1]) == 19:
        e.keyval = int(keysyms.Page_Up)
        e.hardware_keycode = gtk.gdk.keymap_get_default().get_entries_for_keyval(int(keysyms.Page_Up))[0][0]
      elif int(m[1]) == 20:
        e.keyval = int(keysyms.Page_Down)
        e.hardware_keycode = gtk.gdk.keymap_get_default().get_entries_for_keyval(int(keysyms.Page_Down))[0][0]
      elif int(m[1]) == 8:
        e.keyval = int(keysyms.BackSpace)
        e.hardware_keycode = gtk.gdk.keymap_get_default().get_entries_for_keyval(int(keysyms.BackSpace))[0][0]
      elif int(m[1]) == 9:
        e.keyval = int(keysyms.Tab)
        e.hardware_keycode = gtk.gdk.keymap_get_default().get_entries_for_keyval(int(keysyms.Tab))[0][0]
      elif int(m[1]) == 10:
        e.keyval = int(keysyms.Return)
        e.hardware_keycode = gtk.gdk.keymap_get_default().get_entries_for_keyval(int(keysyms.Return))[0][0]
      else :
        e.keyval = int(m[1])
        
      self.browser.emit('key-press-event', e)
        
    return True
Exemple #10
0
def main():
    msg.init()
    debug("Spawned")
    while True:
        m = msg.recv()
        s = str(m)
        try:
            if m[0] == msg.ACLoginReq:
                [_, user, password, compid, rfile, wfile] = m
                try:
                    ok = password == credentials[user]
                except KeyError:
                    ok = False
                if ok:
                    debug(user + " logged in")
                    debug("RFile: " + str(rfile))
                    debug("WFile: " + str(wfile))
                    msg.send(msg.ACLoginResT, user, compid, rfile, wfile)
                else:
                    debug(user + " refused (wrong password)")
                    msg.send(msg.ACLoginResF, user, compid)
            elif m[0] == msg.ACFileReq:
                [_, user, compid, request] = m
                try:
                    ok = user in owners[request]
                except KeyError:
                    ok = False
                if ok:
                    debug(user + " access to " + request + " authorized")
                    msg.send(msg.ACFileResT, user, compid, request)
                else:
                    debug(user + " access to " + request + " refused")
                    msg.send(msg.ACFileResF, user, compid, request)
            else:
                debug("Unhandled message " + s)
        except ValueError:
            debug("Unexpected payload " + s)
Exemple #11
0
 def handle_msgs(self, source, condition):
   m = msg.recv()
   if m[0] == msg.Display:
     self.handle_display_shm(m)
   return True