예제 #1
0
 def _Edit( self ):
     
     do_refresh = False
     
     selected_mappings = self._mappings_list_ctrl.GetData( only_selected = True )
     
     for selected_mapping in selected_mappings:
         
         ( description, internal_ip, internal_port, external_port, protocol, duration ) = selected_mapping
         
         with ClientGUIDialogs.DialogInputUPnPMapping( self, external_port, protocol, internal_port, description, duration ) as dlg:
             
             if dlg.exec() == QW.QDialog.Accepted:
                 
                 ( external_port, protocol, internal_port, description, duration ) = dlg.GetInfo()
                 
                 HydrusNATPunch.RemoveUPnPMapping( external_port, protocol )
                 
                 internal_client = HydrusNATPunch.GetLocalIP()
                 
                 HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, protocol, description, duration = duration )
                 
                 do_refresh = True
                 
             else:
                 
                 break
                 
             
         
     
     if do_refresh:
         
         self._RefreshMappings()
예제 #2
0
 def test_upnp( self ):
     
     internal_client = HydrusNATPunch.GetLocalIP()
     
     internal_port = random.randint( 1000, 1500 )
     
     external_port = random.randint( 1000, 1500 )
     
     description_tcp = 'hydrus test tcp'
     description_udp = 'hydrus test udp'
     
     HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, 'TCP', description_tcp )
     HydrusNATPunch.AddUPnPMapping( internal_client, internal_port, external_port, 'UDP', description_udp )
     
     mappings = HydrusNATPunch.GetUPnPMappings()
     
     mappings_without_lease_times = [ mapping[:-1] for mapping in mappings ]
     
     self.assertIn( ( description_tcp, internal_client, internal_port, external_port, 'TCP' ), mappings_without_lease_times )
     self.assertIn( ( description_udp, internal_client, internal_port, external_port, 'UDP' ), mappings_without_lease_times )
     
     HydrusNATPunch.RemoveUPnPMapping( external_port, 'TCP' )
     HydrusNATPunch.RemoveUPnPMapping( external_port, 'UDP' )
     
     mappings = HydrusNATPunch.GetUPnPMappings()
     
     mappings_without_lease_times = [ mapping[:-1] for mapping in mappings ]
     
     self.assertNotIn( ( description_tcp, internal_client, internal_port, external_port, 'TCP' ), mappings_without_lease_times )
     self.assertNotIn( ( description_udp, internal_client, internal_port, external_port, 'UDP' ), mappings_without_lease_times )
    def _Add(self):

        do_refresh = False

        external_port = HC.DEFAULT_SERVICE_PORT
        protocol = 'TCP'
        internal_port = HC.DEFAULT_SERVICE_PORT
        description = 'hydrus service'
        duration = 0

        with ClientGUIDialogs.DialogInputUPnPMapping(self, external_port,
                                                     protocol, internal_port,
                                                     description,
                                                     duration) as dlg:

            if dlg.exec() == QW.QDialog.Accepted:

                (external_port, protocol, internal_port, description,
                 duration) = dlg.GetInfo()

                for (existing_description, existing_internal_ip,
                     existing_internal_port, existing_external_port,
                     existing_protocol, existing_lease) in self._mappings:

                    if external_port == existing_external_port and protocol == existing_protocol:

                        QW.QMessageBox.critical(
                            self, 'Error',
                            'That external port already exists!')

                        return

                internal_client = HydrusNATPunch.GetLocalIP()

                HydrusNATPunch.AddUPnPMapping(internal_client,
                                              internal_port,
                                              external_port,
                                              protocol,
                                              description,
                                              duration=duration)

                do_refresh = True

        if do_refresh:

            self._RefreshMappings()
예제 #4
0
                def work_callable():

                    if remove_existing:

                        HydrusNATPunch.RemoveUPnPMapping(
                            external_port, protocol)

                    internal_client = HydrusNATPunch.GetLocalIP()

                    HydrusNATPunch.AddUPnPMapping(internal_client,
                                                  internal_port,
                                                  external_port,
                                                  protocol,
                                                  description,
                                                  duration=duration)

                    return True