UPnP: expose more functionality

This commit is contained in:
Dylan K. Taylor 2021-06-13 22:48:38 +01:00
parent 80bf948588
commit ec7ea98ead
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 7 additions and 7 deletions

View File

@ -187,14 +187,14 @@ class UPnP{
return $serviceURL;
}
public static function portForward(string $serviceURL, int $port) : void{
public static function portForward(string $serviceURL, string $internalIP, int $internalPort, int $externalPort) : void{
$body =
'<u:AddPortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">' .
'<NewRemoteHost></NewRemoteHost>' .
'<NewExternalPort>' . $port . '</NewExternalPort>' .
'<NewExternalPort>' . $externalPort . '</NewExternalPort>' .
'<NewProtocol>UDP</NewProtocol>' .
'<NewInternalPort>' . $port . '</NewInternalPort>' .
'<NewInternalClient>' . Internet::getInternalIP() . '</NewInternalClient>' .
'<NewInternalPort>' . $internalPort . '</NewInternalPort>' .
'<NewInternalClient>' . $internalIP . '</NewInternalClient>' .
'<NewEnabled>1</NewEnabled>' .
'<NewPortMappingDescription>PocketMine-MP</NewPortMappingDescription>' .
'<NewLeaseDuration>0</NewLeaseDuration>' .
@ -215,11 +215,11 @@ class UPnP{
}
}
public static function removePortForward(string $serviceURL, int $port) : void{
public static function removePortForward(string $serviceURL, int $externalPort) : void{
$body =
'<u:DeletePortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">' .
'<NewRemoteHost></NewRemoteHost>' .
'<NewExternalPort>' . $port . '</NewExternalPort>' .
'<NewExternalPort>' . $externalPort . '</NewExternalPort>' .
'<NewProtocol>UDP</NewProtocol>' .
'</u:DeletePortMapping>';

View File

@ -52,7 +52,7 @@ final class UPnPNetworkInterface implements NetworkInterface{
$this->logger->info("Attempting to portforward...");
$this->serviceURL = UPnP::getServiceUrl();
UPnP::portForward($this->serviceURL, $this->port);
UPnP::portForward($this->serviceURL, Internet::getInternalIP(), $this->port, $this->port);
$this->logger->info("Forwarded $this->ip:$this->port to external port $this->port");
}