예제 #1
0
    def send_prescence(self):
        data = {"id": common.get_id(), "local_ip": spkwifi.get_ip_adress()}
        if common.get_id() is not None:
            if self.channel_thread.token == None:
                if self.channel_thread.bad_token != None:
                    data["bad_token"] = self.channel_thread.bad_token
                data["get_token"] = True

            if self.routine != None:
                data["routine"] = self.routine.type

                data["current_cut_job"] = self.routine.job_id
                data["can_stop"] = self.routine.status.can_stop
                data["stop_requested"] = self.routine.status.stop_requested
                data["cut_fase"] = self.routine.status.fase
            if self.last_job_status is not None:
                data["last_job_status"] = self.last_job_status.as_dict()

                self.last_job_status = None
            if self.message is not None:
                data["popup_message"] = self.message
                self.message = None
        try:
            #print data
            response_object = common.send_data(data)
            #print data
            #print response_object
        except Exception as error:
            print error
            response_object = {}
            time.sleep(1)  #durmamos 10 segundos, hubo un error con el servidor
        return response_object
예제 #2
0
 def send_prescence(self):
     data={"id":common.get_id(),"local_ip":spkwifi.get_ip_adress()}
     if common.get_id() is not None:
         if self.channel_thread.token==None:
             if self.channel_thread.bad_token!=None:
                 data["bad_token"]=self.channel_thread.bad_token
             data["get_token"]=True
             
         if self.routine!=None:
             data["routine"]=self.routine.type
             
             data["current_cut_job"]=self.routine.job_id
             data["can_stop"]=self.routine.status.can_stop
             data["stop_requested"]=self.routine.status.stop_requested
             data["cut_fase"]=self.routine.status.fase
         if self.last_job_status is not None:
             data["last_job_status"]=self.last_job_status.as_dict()
                                      
             self.last_job_status=None
         if self.message is not None:
             data["popup_message"]=self.message
             self.message=None
     try:
         #print data
         response_object=common.send_data(data)
         #print data
         #print response_object
     except Exception as error:
         print error
         response_object={}
         time.sleep(1) #durmamos 10 segundos, hubo un error con el servidor
     return response_object
예제 #3
0
    def run(self):

        # Get the 3 keys from the client
        client_pub_a = pickle.loads(recv_data(conn)).get_msg()
        client_pub_b = pickle.loads(recv_data(conn)).get_msg()
        client_pub_c = pickle.loads(recv_data(conn)).get_msg()

        # Generate private keys and public keys with same large prime and
        # primitive root
        private_a_server = random.randint(1, client_pub_a.q - 1)
        server_pub_a = PubKey(client_pub_a.q, client_pub_a.alpha)
        server_pub_a.gen_pub_key(private_a_server)

        private_b_server = random.randint(1, client_pub_b.q - 1)
        server_pub_b = PubKey(client_pub_b.q, client_pub_b.alpha)
        server_pub_b.gen_pub_key(private_b_server)

        private_c_server = random.randint(1, client_pub_c.q - 1)
        server_pub_c = PubKey(client_pub_c.q, client_pub_c.alpha)
        server_pub_c.gen_pub_key(private_c_server)

        # Generate shared keys
        shared_a = sharedKey(client_pub_a, private_a_server)
        shared_b = sharedKey(client_pub_b, private_b_server)
        shared_c = sharedKey(client_pub_c, private_c_server)

        # Send the 3 public keys of server to client
        hdr = Hdr(10, settings.TCP_PORT, self.port)
        msg_a = Msg(hdr, server_pub_a)
        msg_b = Msg(hdr, server_pub_b)
        msg_c = Msg(hdr, server_pub_c)

        send_data(conn, pickle.dumps(msg_a))
        send_data(conn, pickle.dumps(msg_b))
        send_data(conn, pickle.dumps(msg_c))

        while True:  # serve the client according to the requests arrived
            msg = pickle.loads(recv_data(conn))

            if msg.type() == "REQSERV":
                file_name = msg.get_msg()
                # now check if this file is present in the file system
                if os.path.isfile(
                        'data/' +
                        file_name):  # Check if file available in the server
                    send_file(conn, 'data/' + file_name, settings.TCP_PORT,
                              self.port, [shared_a, shared_b, shared_c])
                else:
                    # send disconnect
                    file_not_present(conn, settings.TCP_PORT, self.port)

            if msg.type() == "DISCONNECT":
                # Disconnect this client from the server
                print("Client disconnected from the server")
                break
예제 #4
0
    def check_version(self):
        with open(os.path.join(common.get_current_path(), VERSIONFILE),
                  'r') as f:
            version = f.read().strip()
        print u"Verificando actualizaciones"
        data = {"checking_version": True, "version": version}
        try:
            response = common.send_data(data)
        except:
            return
        if response.get("command", None) == "update":
            print u"Nueva version disponible (Actual: %s,Nueva: %s)" % (
                version, response["new_version"])
            file_url = common.URL + response["file_url"]
            response = urllib2.urlopen(file_url)
            _file = StringIO(response.read())
            if zipfile.is_zipfile(_file):

                zfl = zipfile.ZipFile(_file)
                members = zfl.namelist()[:]
                root_path = None
                for n in members[:]:
                    if os.path.basename(n) == "cncid":
                        members.remove(n)
                    elif os.path.basename(n) == "main.py":
                        if not root_path:
                            root_path = os.path.dirname(n)
                if root_path is not None:
                    for n in members[:]:
                        if not n.startswith(root_path):
                            members.remove(n)
                for m in members:
                    source = zfl.open(m)
                    file_target = os.path.join(common.get_current_path(),
                                               os.path.relpath(m, root_path))
                    if os.path.basename(m) == "":  #es directorio
                        if not os.path.exists(file_target):
                            os.makedirs(file_target)
                    else:  #es archivo
                        target = file(file_target, "wb")
                        with source, target:
                            shutil.copyfileobj(source, target)
                print u"Reiniciando script..."
                common.restart_please()
        else:
            print u"Versión más reciente (%s)" % version
예제 #5
0
 def check_version(self):
     with open(os.path.join(common.get_current_path(),VERSIONFILE), 'r') as f:
         version=f.read().strip()
     print u"Verificando actualizaciones"
     data={"checking_version":True,"version":version}
     try:
         response= common.send_data(data)
     except:
         return 
     if response.get("command",None)=="update":
         print u"Nueva version disponible (Actual: %s,Nueva: %s)"%(version,response["new_version"])
         file_url=common.URL+response["file_url"]
         response = urllib2.urlopen(file_url)
         _file = StringIO(response.read())
         if zipfile.is_zipfile(_file):
             
             
             zfl=zipfile.ZipFile(_file)
             members=zfl.namelist()[:]
             root_path=None
             for n in members[:]:
                 if os.path.basename(n)=="cncid":
                     members.remove(n)
                 elif os.path.basename(n)=="main.py":
                     if not root_path:
                         root_path=os.path.dirname(n)
             if root_path is not None:
                 for n in members[:]:
                     if not n.startswith(root_path):
                         members.remove(n)
             for m in members:       
                 source = zfl.open(m)
                 file_target=os.path.join(common.get_current_path(),os.path.relpath(m, root_path))
                 if os.path.basename(m)=="": #es directorio
                     if not os.path.exists(file_target):
                         os.makedirs(file_target)
                 else: #es archivo
                     target = file(file_target, "wb")
                     with source, target:
                         shutil.copyfileobj(source, target)  
             print u"Reiniciando script..."
             common.restart_please()
     else:
         print u"Versión más reciente (%s)"%version
예제 #6
0
                               a.q - 1)  # Random number between 1 and a.q - 1
    private_b = random.randint(1,
                               b.q - 1)  # Random number between 1 and b.q - 1
    private_c = random.randint(1,
                               c.q - 1)  # Random number between 1 and c.q - 1
    a.gen_pub_key(private_a)
    b.gen_pub_key(private_b)
    c.gen_pub_key(private_c)

    # Create header for public key sharing
    hdr = Hdr(settings.PUBKEY, tcpClientA.getsockname(), port)
    msg_a = Msg(hdr, a)
    msg_b = Msg(hdr, b)
    msg_c = Msg(hdr, c)

    send_data(tcpClientA, pickle.dumps(msg_a))
    send_data(tcpClientA, pickle.dumps(msg_b))
    send_data(tcpClientA, pickle.dumps(msg_c))

    # Recieve server public keys
    server_pub_a = pickle.loads(recv_data(tcpClientA)).get_msg()
    server_pub_b = pickle.loads(recv_data(tcpClientA)).get_msg()
    server_pub_c = pickle.loads(recv_data(tcpClientA)).get_msg()

    # Generate shared keys at client
    shared_a = sharedKey(server_pub_a, private_a)
    shared_b = sharedKey(server_pub_b, private_b)
    shared_c = sharedKey(server_pub_c, private_c)

    print("Sharing of key over\n")
def start(start_text):
    send_data(data_file, start_text, other_pid, send_signal)
def receive_signal(signum, stack):
    data = read_from_file(other_data_file)
    print(f'Received from app2 data: {data}')
    out_data = input('What do you want to send?')
    send_data(data_file, out_data, other_pid, send_signal)
예제 #9
0
 def save(self):
     """save by sending order to the assistant server"""
     send_data("post", HISTORY_ENDPOINT, **self.dict())
     return self
def receive_signal(signum, stack):
    data = read_from_file(other_data_file)
    print(f'Received from app1 data: {data}')
    out_data = data[len(data)::-1]
    print(f'Replying with: {out_data}')
    send_data(data_file, out_data, other_pid, send_signal)