inc/classes/exceptions/result/.htaccess -text
inc/classes/exceptions/result/class_InvalidDatabaseResultException.php -text
inc/classes/exceptions/result/class_ResultUpdateException.php -text
+inc/classes/exceptions/socket/.htaccess -text
+inc/classes/exceptions/socket/class_InvalidSocketException.php -text
inc/classes/exceptions/template/.htaccess -text
inc/classes/exceptions/template/class_BasePathIsEmptyException.php -text
inc/classes/exceptions/template/class_BasePathIsNoDirectoryException.php -text
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * This exception is thrown when the socket resource is invalid or an error
+ * occurs while socket initialization phase.
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class InvalidSocketException extends FrameworkException {
+ /**
+ * A Constructor for this exception
+ *
+ * @param $messageArray Error message array
+ * @param $code Error code
+ * @return void
+ */
+ public function __construct(array $messageData, $code) {
+ // Construct the message
+ $message = sprintf("[%s:] Invalid socket (type %s != resource). errno=%s, errstr=%s",
+ $messageData[0]->__toString(),
+ $messageData[1],
+ $messageData[2],
+ $messageData[3]
+ );
+
+ // Call parent exception constructor
+ parent::__construct($message, $code);
+ }
+}
+
+// [EOF]
+?>
// Return the IP address
return $ip;
}
+
+ /**
+ * Determines own remote IP address (e.g. can be used to probe if we are
+ * reachable from outside by determining external IP and then connect to it.
+ * This is accomblished by connecting to the IP of www.ship-simu.org which
+ * should default to 217.172.186.31.
+ *
+ * This method is taken and lightly rewritten from a user comment on php.net:
+ * http://de.php.net/manual/en/function.socket-create.php#49368
+ *
+ * @param $dest IP destination we should connect to
+ * @param $port Port destination we should connect to
+ * @return $externalAddress The determined external IP address
+ * @throws InvalidSocketException If socket initialization wents wrong
+ */
+ public function determineExternalIp ($dest = '217.172.186.31', $port = 80) {
+ // First get a socket
+ $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
+ if (!is_resource($socket)) {
+ // Throw InvalidSocketException
+ throw new InvalidSocketException (array($this, gettype($socket), 0, 'unknown'));
+ } // END - if
+
+ // Connect to the destination
+ socket_connect($socket, $dest, $port);
+
+ // Get the socket address (our external IP) and port (ignored)
+ socket_getsockname($socket, $externalAddress, $ourPort);
+
+ // Close the socket
+ socket_close($socket);
+
+ // Return determined external IP
+ return $externalAddress;
+ }
}
// [EOF]