Jump to content

realWasabi

Members
  • Posts

    23
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

realWasabi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm looking for a way to find and capture the first number and all text after it in a string. Examples: I have the following entries: some text 23 text sometext 21 sometext some text 120 text I want the script to capture the number, and everything after it, and put it into a variable. At the same time, the captured part should be removed from the original string. So the above examples whould be: some text 23 text >> some text | 23 text sometext 21 >> sometext | 21 sometext some text 120 text >> sometext some text | 120 text How can this be done? I was suggested to use preg_match, but i can't figure out how to write that to do what I want.
  2. Hi I'm trying to write a script that searches through files in a folder and return the filenames matching the search criterias. It needs only read the filenames, and not the file contents (.pdf files). All the files are formatted like this: street name,housenumber,cust name,casetype,casenumber,archivedate.pdf (notice that the streetname+custname may contain spaces.) I need to be able to search freely on one or more criterias - while also using * as a wildcard (fx. searching for street* instead of full streatname) So far I have been using if statements to return search results, but as more and more files are being added (700+ at the moment), along with the large number of criterias, this does not seem like the most efficient way to do this - nor does it seem like the "correct" way. What would be the best way to go about this?
  3. Hi I have some servers running on my local network, which all support IPMI over http. In short, it's a web interface accessible in my browser. I want to be able to access these sites from outside my local network. This is a problem, as all of them runs on port 80, which can't be changed, and as such, I can't just NAT my way out of it. I also have a webserver that runs on the same local network - and I was thinking about using "file_get_html" in a iframe to access the site from that server - but this presents a few other problems, as the sites requires authentication (the htaccess basic authentication) and file_get_html doesn't seem to support that. Also, the site renders kinda wierd, not showing the top part of the logo etc. How can this be done? If it helps anything, I also have a proxy server running on the same local network which can be used.
  4. I'm trying to output the last 6 lines of a .txt file in reverse order. So if the file consists of this: line1 line2 line3 line4 line5 line6 line7 line8 line9 line10 I wan't it to output: line10 line9 line8 line7 line6 line5 I can get it to putput the 6 lines in "normal" order just fine, but are having problems reversing it. This is my code: I tried using $i-- but with no luck: $file = file("logs/accesslog.txt"); for ($i = count($file)-6; $i < count($file); $i++) { echo $file[$i] . "<br>"; } I would very much prefer not to use array_reverse() function, as the above script is used in quite a few different functions across my site, and modifying this would mean to modify them all. How could I modify it to reverse the output?
  5. I wasn't talking about you. But you were right as well I guess, I just didn't knew what you meant. So thank you too
  6. I completely misread his answer. I thought he had misunderstood my question, thus answering something else. What he answered were what I was looking for: $ex = get_browser(null, true); echo $ex['browser']; I'm sorry, thank you for pointing that out.
  7. Hello I'm using the get_browser function to display visitors browser, OS etc. for logging purposes. However, I don't want to log the complete output of get_browser as it's quite a few lines. How can I filter the output so this (example): becomes this: I tried using explode, but without any luck.
  8. *facepalm*. I read through the entire code 3 times without noticing that. Thanks again
  9. Woho, it works! Thanks to all of you, but especially PoulRyan for solving the puzzle. I added "else { break; }" after the header if-statement so it stops refreshing after the maxtries have been reached. Also I lowered the tries-number to 0 so it actually does retry 10 times. Just one thing - instead of specifying the IP directly in the meta line, I added the $ip variable. It works, but adds a "?" for every update. So after 10 updates, the url looks like this: http://domain.com/ping.php?ip=10.0.0.14?????????&tries=9 I can't figure out why. Any easy way around this? Current script: <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); $maxtries = 10; $timeout = 2; $ip = $_GET["ip"]; $pageurl = pageurl(); $tries = isset($_GET['tries']) ? (int)$_GET['tries'] : 0 ; function pageurl( ) { $pageurl = "HTTP"; if ( $_SERVER[ "HTTPS" ] == "on" ) { $pageurl .= "S"; } $pageurl .= "://"; if ( $_SERVER[ "SERVER_PORT" ] != "80" ) { $pageurl .= $_SERVER[ "SERVER_NAME" ] . ":" . $_SERVER[ "SERVER_PORT" ] . $_SERVER[ "REQUEST_URI" ]; } else { $pageurl .= $_SERVER[ "SERVER_NAME" ] . $_SERVER[ "REQUEST_URI" ]; } $urlarts = explode( "?", $pageurl ); $pageurl = $urlarts[ "0" ]; return $pageurl; } function htmlheader( ) { global $ip, $tries, $maxtries, $pageurl, $timeout; if ($stdout == 0 && $tries < $maxtries - 1 ) { $tries = $tries + 1; } else { exit; } $content = "<META HTTP-EQUIV=\"refresh\" CONTENT=\"$timeout;url=$pageurl?ip=$ip?&tries=$tries\">\n"; return $content; } if ($ip == NULL) { echo "error"; } else { $cmd = "/share/MD0_DATA/scripts/./webping $ip"; $process = proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { $stdin = stream_get_contents($pipes[0]); $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); // It is important that you close any pipes before calling proc_close in order to avoid a deadlock $return_value = proc_close($process); } if ($stdout == 2) { echo '<p style="color:green;">link up</p>'; } else if ($stdout == 1) { echo '<p style="color:yellow;">link up (warning)</p>'; } else if ($stdout == 0) { echo '<p style="color:red;">link down</p>'; echo htmlheader(); } else { echo 'error (no IP specified?)'; } } ?>
  10. Instead of the "$tries = 1;"? Or where do you mean? Because I'm a little unsure about what that string does?
  11. They don't have to be carried over as the URL changes on every update and it just adds 1 to the current 'tries'. This is another, similar script which makes it work without the use of session/cookie: <?php $device = "roadrunner"; // IP address of device, example "x.x.x.x". $deviceip = "10.0.0.14"; // TCP Port on device to check, example "3389" = RDP, "80" = WebServer. $deviceport = "3389"; // MAC address of NIC1 on device, example "00:00:00:00:00:00" or "00-00-00-00-00-00". $devicemac1 = "00-11-22-33-44-55"; // MAC address of NIC2 on device, example "00:00:00:00:00:00" or "00-00-00-00-00-00". - Optional set to "" if NIC2 not required. $devicemac2 = ""; // Number of times to attempt to connect to port on device after magic packet sent, example "10" $maxtries = "10"; // Broadcast address of network, example ""x.x.x.x". ("255.255.255.255" works in most cases.) $broadcast = "255.255.255.255"; // ICMP port number, default "7". $udport = "7"; // Timeout value for re-tries (in seconds), default "10". $timeout = "2"; // // $frame - used to determine which content to display when executed. $frame = "1"; // $tries - used to determine number of attempts at checking port beetween reloads, compared with maxtries. $tries = $_GET[ "tries" ]; // $pageurl - obtain URL used to access file, used when creating frameset & setting reloads. $pageurl = pageurl(); // Process variables used in frame2, increments tries & sets status to Success(1) or Failed(2) if ( $frame == 1 ) { processurl(); } // ###### Functions ###### // // function pageurl( ) - Returns URL of page via PHP variables. function pageurl( ) { $pageurl = "HTTP"; if ( $_SERVER[ "HTTPS" ] == "on" ) { $pageurl .= "S"; } $pageurl .= "://"; if ( $_SERVER[ "SERVER_PORT" ] != "80" ) { $pageurl .= $_SERVER[ "SERVER_NAME" ] . ":" . $_SERVER[ "SERVER_PORT" ] . $_SERVER[ "REQUEST_URI" ]; } else { $pageurl .= $_SERVER[ "SERVER_NAME" ] . $_SERVER[ "REQUEST_URI" ]; } $urlarts = explode( "?", $pageurl ); $pageurl = $urlarts[ "0" ]; return $pageurl; } // function processurl( ) - Processes variables used in frame2, increments tries & sets status to Success(1) or Failed(2) function processurl( ) { global $status, $tries, $maxtries; if ( $status == 0 && $tries < $maxtries - 1 ) { $tries = $tries + 1; } else { $status = 2; } if ( portcheck() == 0 ) { $status = 1; } } // function wakeonlan() - Attempts to send WoL packet and returns outcome. function wakeonlan( $device, $mac ) { global $broadcast, $udport; $mac = preg_replace( "/[^A-Za-z0-9]/", ":", $mac ); $broadcast_byte = explode( ':', $mac ); $hw_addr = ''; for ( $a = 0; $a < 6; $a++ ) $hw_addr .= chr( hexdec( $broadcast_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 ) { $content = "Error creating socket!\n"; } else { // setting a broadcast option to socket: $opt_ret = socket_set_option( $s, 1, 6, true ); if ( $opt_ret < 0 ) { $content = "setsockopt() failed, error: " . strerror( $opt_ret ) . "\n"; } if ( socket_sendto( $s, $msg, strlen( $msg ), 0, $broadcast, $udport ) ) { $content = "WoL packet sent to mac address " . $mac . "...\n"; socket_close( $s ); } else { $content = "Failed to send WoL packet!"; } } return $content; } // function portcheck( ) - Attempts to connect to TCP port on the device via a Socket, returns $errno. function portcheck( ) { global $deviceip, $deviceport; $file = fsockopen( $deviceip, $deviceport, $errno, $errstr, 50 ); if ( $errno == 0 ) { fclose( $file ); } return $errno; } // function htmlheader( ) - Returns HTML Header for TITLE and if Frame2 REFRESH set. function htmlheader( ) { global $device, $frame, $tries, $maxtries, $status, $pageurl, $timeout; // global "custom" header settings $content = "<TITLE>PHP WoL ($device) - by PRThomasUK </TITLE>\n"; //generate refresh header for frame2. if ( $status == 0 ) { $content .= "<META HTTP-EQUIV=\"refresh\" CONTENT=\"$timeout;url=$pageurl?&tries=$tries\">\n"; } return $content; } // function htmlheader( ) - Returns HTML content for mainpage, frame1 & frame2 based on value of $frame. function htmlcontent( ) { global $pageurl, $device, $deviceip, $deviceport, $devicemac1, $devicemac2, $frame, $tries, $maxtries, $status; if ( $frame == 1 ) { if ( $status == 0 ) { $content = "<script type=\"text/javascript\">function stopFrameload() { window.stop(); document.execCommand(\"Stop\");}</script>\n"; $content .= "<p>Checking connectivity... ($tries/$maxtries) &nbsp<a href=\"\" onclick=\"stopFrameLoad(); return false;\">Stop</a></p>\n"; } elseif ( $status == 1 ) { $content .= "<p>SUCCESS</p>\n"; } else { $content .= "<p>FAILED</p>\n"; } } else { $content = "<FRAMESET rows=\"10,*\" frameborder=0 border=0>\n"; $content .= "<FRAME SRC=\"$pageurl?frame=2\">\n"; $content .= "<NOFRAMES>\n"; if ( $devicemac2 ) { $content .= "<BR>\n"; $content .= wakeonlan( $device, $devicemac2 ); } $content .= "<BR>\n"; $content .= "<BR>\n"; $content .= "<FONT COLOR=\"red\">\n"; $content .= "<H2>Your browser does not support frames...</H2>\n"; $content .= "</FONT>\n"; $content .= "<H3>Status of $device will not be monitored!</H3>\n"; $content .= "</NOFRAMES>\n"; $content .= "</FRAMESET>\n"; } return $content; } ?> <?php echo htmlheader(); echo htmlcontent(); ?>
  12. <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); $maxtries = 10; $timeout = 2; $ip = $_GET["ip"]; $pageurl = pageurl(); $tries = 1; function pageurl( ) { $pageurl = "HTTP"; if ( $_SERVER[ "HTTPS" ] == "on" ) { $pageurl .= "S"; } $pageurl .= "://"; if ( $_SERVER[ "SERVER_PORT" ] != "80" ) { $pageurl .= $_SERVER[ "SERVER_NAME" ] . ":" . $_SERVER[ "SERVER_PORT" ] . $_SERVER[ "REQUEST_URI" ]; } else { $pageurl .= $_SERVER[ "SERVER_NAME" ] . $_SERVER[ "REQUEST_URI" ]; } $urlarts = explode( "?", $pageurl ); $pageurl = $urlarts[ "0" ]; return $pageurl; } function htmlheader( ) { global $tries, $maxtries, $pageurl, $timeout; if ($tries < $maxtries - 1 ) { $tries = $tries + 1; } $content = "<META HTTP-EQUIV=\"refresh\" CONTENT=\"$timeout;url=$pageurl?ip=10.0.0.14?&tries=$tries\">\n"; return $content; } if ($ip == NULL) { echo "error"; } else { $cmd = "/share/MD0_DATA/scripts/./webping $ip"; $process = proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { $stdin = stream_get_contents($pipes[0]); $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); // It is important that you close any pipes before calling proc_close in order to avoid a deadlock $return_value = proc_close($process); } if ($stdout == 2) { echo '<p style="color:green;">link up</p>'; } else if ($stdout == 1) { echo '<p style="color:yellow;">link up (warning)</p>'; } else if ($stdout == 0) { echo '<p style="color:red;">link down</p>'; echo htmlheader(); } else { echo 'error (no IP specified?)'; } } ?> I tried "if ($tries < 10 - 1 ) {" but that didn't work. I also tried to change the other "numbers" to "real" numbers like with the $tries variable.
  13. I tried adding $tries = "1" and changed if ($tries < 10 - 1) but that didn't work. Any other suggestions?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.