function WakeOnLan($addr, $mac_address, $socket_number) { $addr_byte = explode(':', $mac_address); $hw_addr = ''; for ($a = 0; $a < 6; $a++) { $hw_addr .= chr(hexdec($addr_byte[$a])); $msg = chr(255) . chr(255) . chr(255) . chr(255) . chr(255) . chr(255); for ($a = 1; $a <= 16; $a++) { $msg .= $hw_addr; // send it to the broadcast address using UDP // SQL_BROADCAST option isn't help!! $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == false) { echo "Error creating socket!\n"; echo "Error code is '" . socket_last_error($s) . "' - " . socket_strerror(socket_last_error($s)); return FALSE; } else { // setting a broadcast option to socket: $opt_ret = socket_set_option($s, 1, 6, TRUE); if ($opt_ret < 0) { echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n"; return FALSE; } if (socket_sendto($s, $msg, strlen($msg), 0, $ip_address, $socket_number)) { echo "Magic Packet sent successfully!"; socket_close($s); return TRUE; } else { echo "Magic packet failed!"; return FALSE; } } } } }
function comm_init_server() { global $COMM_SOCK; global $_USER; global $_CONFIG; // Create socket $COMM_SOCK = socket_create(AF_INET, SOCK_STREAM, 0); if (!$COMM_SOCK) { perihelion_die("Communication Error", "socket(): " . strerror($COMM_SOCK)); } // Connect socket @socket_connect($COMM_SOCK, $_CONFIG['COMM_HOST'], $_CONFIG['COMM_PORT']) or perihelion_die("Communcation Error", "Connect(): " . socket_strerror(socket_last_error($COMM_SOCK)) . ". Please try again..."); // Send ID package and exit when no correct ID was given... $data['user'] = $_CONFIG['COMM_USER']; $data['pass'] = $_CONFIG['COMM_PASS']; if ($_USER == "") { $data['uid'] = 0; $data['cdb'] = $_CONFIG['default_db']; } else { $data['uid'] = $_USER['id']; $data['cdb'] = $_USER['galaxy_db']; } comm_s2s("ID", $data); $pkg = comm_recv_from_server(); if ($pkg['status'] != "STATUS_OK") { comm_fini_server(); perihelion_die("Communcation Error", "Error while authorising to the server..."); } }
/** * Wake machine * * @return array Machines * @author Ralf Hortt <*****@*****.**> **/ function wakeMachine($addr, $mac, $socket_number) { if (strlen($mac) != 17) { return array('status' => 'error', 'error' => 'MAC Address', 'message' => 'Error: Wrong MAC Address length'); } if (preg_match('/[^A-Fa-f0-9:]/', $mac)) { return array('status' => 'error', 'error' => 'MAC Address', 'message' => 'Error: Wrong MAC Address pattern'); } $addr_byte = explode(':', $mac); $hw_addr = ''; for ($a = 0; $a < 6; $a++) { $hw_addr .= chr(hexdec($addr_byte[$a])); } $msg = chr(255) . chr(255) . chr(255) . chr(255) . chr(255) . chr(255); for ($a = 1; $a <= 16; $a++) { $msg .= $hw_addr; } $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == FALSE) { return array('status' => 'error', 'error' => 'Can\'t create socket!', 'message' => "Error: '" . socket_last_error($s) . "' - " . socket_strerror(socket_last_error($s))); } else { $opt_ret = socket_set_option($s, SOL_SOCKET, SO_BROADCAST, TRUE); if ($opt_ret < 0) { return array('status' => 'error', 'error' => 'setsockopt() failed', 'message' => 'Error: ' . strerror($opt_ret)); } if (socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) { $content = bin2hex($msg); return array('status' => 'ok'); /* echo "<div class=\"messageOK\">Magic Packet Sent!</div>\n"; echo "<b>Port:</b> ".$socket_number." <b>MAC:</b> ".$_GET['wake_machine']." <b>Data:</b>\n"; echo "<textarea readonly class=\"textarea\" name=\"content\" >".$content."</textarea><br />\n"; socket_close($s); return TRUE; */ } else { return array('status' => 'error', 'error' => '', 'message' => 'Magic Packet failed to send!'); } } }
function WakeOnLan($addr, $mac, $socket_number) { $addr_byte = explode(':', $mac); $hw_addr = ''; for ($a = 0; $a < 6; $a++) { $hw_addr .= chr(hexdec($addr_byte[$a])); } $msg = chr(255) . chr(255) . chr(255) . chr(255) . chr(255) . chr(255); for ($a = 1; $a <= 16; $a++) { $msg .= $hw_addr; } $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == false) { echo "Can't create socket!<BR>\n"; echo "Error: '" . socket_last_error($s) . "' - " . socket_strerror(socket_last_error($s)); return FALSE; } else { $opt_ret = socket_set_option($s, 1, 6, TRUE); if ($opt_ret < 0) { echo "setsockopt() failed, error: " . strerror($opt_ret) . "<BR>\n"; return FALSE; } if (socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) { $content = bin2hex($msg); echo "Magic Packet Sent!<BR>\n"; echo "Data: <textarea readonly rows=\"1\" name=\"content\" cols=\"" . strlen($content) . "\">" . $content . "</textarea><BR>\n"; echo "Port: " . $socket_number . "<br>\n"; echo "MAC: " . $_GET['wake_machine'] . "<BR>\n"; socket_close($s); return TRUE; } else { echo "Magic Packet failed to send!<BR>"; return FALSE; } } }
function DoTransaction() { $Values = ""; $host = "apidns.be"; $port = 86; $address = gethostbyname($host); $socket = fsockopen($host, 80); if (!$socket) { $this->AddError("socket() failed: " . strerror($socket)); return null; } $in = "GET /api/api.php?" . $this->PostString . (" HTTP/1.1\nHost: " . $host . "\n" . "\nConnection: Close\n\n"); $out = ""; fputs($socket, $in); if ($out = fread($socket, 2048)) { $this->RawData .= $out; } fclose($socket); if (!is_null($this->RawData)) { if (eregi("HTTP/1.1 200", $this->RawData)) { list(, $this->OutputData) = explode("\n\r\n", $this->RawData); $this->OutputData = explode("\n", $this->OutputData); $this->OutputData[0] = ""; $this->OutputData = trim(implode("\n", $this->OutputData)); if (substr($this->OutputData, 0, 5) != "<?xml") { $this->Values = false; return false; } } else { $this->Values = false; return false; } } $this->Values = false; return false; }
function WakeOnLan($addr, $mac, $socket_number) { debug("sende WOL an mac '{$mac}' IP '{$addr}'"); $addr_byte = explode(':', $mac); $hw_addr = ''; for ($a = 0; $a < 6; $a++) { $hw_addr .= chr(hexdec($addr_byte[$a])); } $msg = chr(255) . chr(255) . chr(255) . chr(255) . chr(255) . chr(255); for ($a = 1; $a <= 16; $a++) { $msg .= $hw_addr; } // UDP Socket erstellen $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == false) { echo "Fehler bei socket_create!\n"; echo "Fehlercode ist '" . socket_last_error($s) . "' - " . socket_strerror(socket_last_error($s)); return FALSE; } else { // Socket Optionen setzen: $opt_ret = socket_set_option($s, SOL_SOCKET, SO_BROADCAST, TRUE); if ($opt_ret < 0) { echo "setsockopt() fehlgeschlagen, Fehler: " . strerror($opt_ret) . "\n"; return FALSE; } // Paket abschicken if (socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) { debug("WOL erfolgreich gesendet!"); socket_close($s); return TRUE; } else { echo "WOL fehlerhaft! \n"; return FALSE; } } }
function DoTransaction() { $enduserip = $REMOTE_ADDR; $sitename = 'eNomiTron PHP'; global $string; global $testmode; global $host; // Clear values $Values = ""; if ($testmode == "1") { $host = 'resellertest.enom.com'; } elseif ($testmode == "0") { $host = 'reseller.enom.com'; } $port = 443; $socket = fsockopen("ssl://" . $host, $port); if (!$socket) { function strerror() { global $message; $message .= "Could not connect to Server -Please try again Later"; return $message; } $this->AddError("socket() failed: " . strerror($socket)); } else { // Send GET command with our parameters $in = "GET /interface.asp?" . $this->PostString . "HTTPS/1.0\r\n\r\n"; $out = ''; fputs($socket, $in); // Read response while ($out = fread($socket, 2048)) { // Save in rawdata $this->RawData .= $out; } // Close the socket fclose($socket); // Parse the output for name=value pairs $this->ParseResponse($this->RawData); } }
function DoTransaction() { // include ("sessions.php"); // Clear values // global $UseSSL; // global $Server; $UseSSL = 0; $Server = 1; $Values = ""; if ($Server == '1') { $host = 'resellertest.enom.com'; } elseif ($Server == '0') { $host = 'reseller.enom.com'; } else { $host = 'resellertest.enom.com'; } if ($UseSSL == 1) { $port = 443; $address = gethostbyname($host); $socket = fsockopen("ssl://" . $host, $port); } else { $port = 80; $address = gethostbyname($host); $socket = fsockopen($host, $port); } if (!$socket) { function strerror() { echo "Could not connect to Server -Please try again Later"; } $this->AddError("socket() failed: " . strerror($socket)); } else { // Send GET command with our parameters $in = "GET /interface.asp?" . $this->PostString . "HTTP/1.0\r\n\r\n"; $out = ''; fputs($socket, $in); // Read response while ($out = fread($socket, 2048)) { // Save in rawdata $this->RawData .= $out; } // Close the socket fclose($socket); // Parse the output for name=value pairs $this->ParseResponse($this->RawData); } }
function DoTransaction() { if ($this->user != "" && $this->pass != "" && $this->authtype != "") { $this->AddParam("user", $this->user); $this->AddParam("pass", $this->pass); $this->AddParam("authtype", $this->authtype); } $Values = ""; if ($this->useSSL) { $port = 443; $address = gethostbyname($this->host); $socket = fsockopen("ssl://" . $this->host, $port); } else { $port = 80; $address = gethostbyname($this->host); $socket = fsockopen($this->host, $port, $errno, $errstr, 30); } if (!$socket) { function strerror() { echo "Could not connect to Server -Please try again Later ({$errno}, {$errstr})"; } $this->AddError("socket() failed: " . strerror($socket)); } else { // Send GET command with our parameters $out = ''; $in = "GET " . $this->url . $this->PostString . " HTTP/1.0\r\n"; $in .= "Host: " . $this->host . "\r\n"; $in .= "Connection: Close\r\n\r\n"; fputs($socket, $in); // Read response while ($out = fread($socket, 2048)) { // Save in rawdata $this->RawData .= $out; } // Close the socket fclose($socket); // Parse the output for name=value pairs $this->ParseResponse($this->RawData); } }
function sendMagicPacket($macaddress, $ip = null, $netmask = null) { $packet = $this->doMagicPacket($macaddress); $ip = ip2long($ip); $mask = ip2long($netmask); $broadcast = null; // Si l'IP et le masque sont fournis (et sont valides) on tente de calculer l'adresse de broadcast du reseau if ($ip !== false && $mask !== false) { $mask = ~$mask; $broadcast = long2ip($ip | $mask); } $error = 0; $mcastaddr = "224.0.0.1"; /* TO BE TESTED $addr_byte = explode(':', $macaddress); $hw_addr = ''; for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a])); $packet = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255); for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr; */ if (is_null($broadcast)) { //j'arrive pas a faire du broadcast avec cette methode alors c'est du multicast pour tous les //postes d'un ss reseau $sock = fsockopen("udp://" . $mcastaddr, 9, $errno, $errostr); //$sock = fsockopen("udp://255.255.255.255", 9, $errno, $errostr); if (!$sock) { echo __('There is an error with socket creation', 'shellcommands') . " : "; echo Toolbox::encodeInUtf8($errostr) . " " . Toolbox::encodeInUtf8($errno); echo "<br />"; $error = 1; } else { fwrite($sock, $packet); fclose($sock); } } else { // Cette methode necessite que php soit compile avec les sockets $sock = socket_create(AF_INET, SOCK_DGRAM, 0); //TO BE TESTED $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($sock < 0) { echo "Error creating socket : " . strerror($sock) . "\n"; echo "Error code is '" . socket_last_error($sock) . "' - "; echo socket_strerror(socket_last_error($sock)); $error = 1; } else { $opt_ret = socket_set_option($sock, 1, 6, TRUE); if ($opt_ret < 0) { echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n"; $error = 1; } else { $send_ret = socket_sendto($sock, $packet, strlen($packet), 0, $broadcast, 9); //TO BE TESTED $send_ret = socket_sendto($sock, $packet, strlen($packet), 0, $ip, $socket_number) $socket_number=7 ? if ($send_ret < 0) { echo "Error when sending packet " . strerror($send_ret) . "<BR>\n"; $error = 1; } else { socket_close($sock); } } } } if ($error != 1) { $txt = is_null($broadcast) ? $mcastaddr : $broadcast; echo __('Magic packet sending to', 'shellcommands') . " " . $macaddress . " (" . $txt . ")"; } else { echo __('The packet cannot be send', 'shellcommands'); } }
function ftp_GetPasv() { global $FTP; // client issued 'pasv' command // so lets try to bind a socket to a port $result = false; if ($FTP->DC["socket_desc"]) { // we alread got a socket open.. let's use it $result = $FTP->DC["socket_desc"]; } else { $socket = socket_create(AF_INET, SOCK_STREAM, 0); if ($socket >= 0) { debug("ftp: open socket ({$socket}) (pasv mode)"); // FIXME: make this configurable! $bound = 0; $port = 12000; while (!$bound && $port <= 12100) { $bound = socket_bind($socket, $FTP->server_ip, $port); debug("ftp::pasv socket_bind port {$port} ({$bound})"); if (!$bound) { $port++; } } if ($bound) { $ret = socket_listen($socket, 1); socket_set_nonblock($socket); if ($ret < 0) { ftp_Tell(425, "Couldn't build data connection (rm: socket error:" . strerror($socket) . ")"); } else { $FTP->DC["mode"] = "passive"; $FTP->DC["socket"] = $socket; debug("ftp: listening on port {$port}"); $result = str_replace(".", ",", $FTP->server_ip); $result .= "," . ((int) $port >> 8); $result .= "," . ($port & 0xff); //$FTP->DC["socket_desc"]=$result; } } else { ftp_Tell(425, "Couldn't build data connection: couldn't bind to a socket"); } } else { ftp_Tell(425, "Couldn't build data connection (rm: socket error:" . strerror($socket) . ")"); } } return $result; }