PDA

View Full Version : Need help - custom ping script!


rayw
10-20-2007, 05:23 AM
Using this mod (https://vborg.vbsupport.ru/showthread.php?t=62164) I want to imbed a custom Ping script into the page.

The script works fine, it pings a web address or IP fine however, the results are outputted to the very top of the web page, above the logo. I want the results to output right underneath the field that you type the web address/IP into.

Here is the ping script:
<?php

error_reporting(E_ALL & ~E_NOTICE);

define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'page_ping'); // change this depending on your filename

$phrasegroups = array(

);

$specialtemplates = array(

);

$globaltemplates = array(
'page_ping',
);

$actiontemplates = array(

);

chdir('/home/USERNAME/public_html/');
require_once('./global.php');

// Start Ping
$_ip = $_SERVER['REMOTE_ADDR'];
if($_GET['do'] == 'ping')
{
$_domain = $_POST['domain'];
echo "<pre>";
system ("ping -w 10 -c 5 $_domain");

echo "</pre>";
}

// End Ping

$pingresult = $_POST['ping -w 10 -c 5 $_domain'];

$navbits = array();
$navbits[$parent] = 'Ping';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('page_ping') . '");');

?>


Here is my template:
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">Ping</td>
</tr>
<tr>
<td class="alt1">

Enter the IP Address or domain name of the server that you want to ping.<br>


<form method='post' action='page_ping.php?do=ping'><input type='text' name='domain' value=''>&nbsp;<input type='submit' value='Ping'></form>

<br /><br />

$pingresult

<br />

</td>
</tr>
</table>

$footer
</body>
</html>

You can try it yourself here: http://www.itresource.com.au/page_ping.php

What do I need to do to get this working correctly? I've tried many different things to get this working - currently this seems to be the most 'functional' for lack of a better word.

Any help would be greatly appreciated.

Thanks! :)

Marco van Herwaarden
10-20-2007, 05:58 AM
Create a template for it instead of using 'echo'.

Regular echo is only suitable for debug with vBulletin.

rayw
10-20-2007, 10:35 AM
Sorry, I'm going to need a bit more detail. I don't understand! :(

Dismounted
10-20-2007, 12:07 PM
All your display should be in your templates. The PHP code should not print any output into the browser (except for the final print_output), but instead assign all the data into variables for use in the template.

rayw
10-23-2007, 09:21 AM
Hmmm! Not having much luck with this. I even tried dynamic AJAX inclusions using a script from dynamic drive and I still couldn't get it to work properly.

Unfortunately, I'm not the most talented coder out there. :(

Dismounted
10-23-2007, 09:54 AM
Use this PHP instead of yours. The template doesn't need to be changed (keep the one you posted above).
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'page_ping');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
'page_ping'
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
chdir('/home/USERNAME/public_html');
require_once('./global.php');

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

// do pinging
if ($_GET['do'] == 'ping')
{
$domain = $_POST['domain'];
system("ping -w 10 -c 5 $domain", $pingresult);
}

// prepare navbits
$navbits = array();
$navbits[] = 'Ping';
$navbits = construct_navbits($navbits);

// spit out html
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('page_ping') . '");');
?>

rayw
10-23-2007, 10:08 AM
I had something similar to what you have posted but I there were a few errors in mine when I tried to run it.

There are no errors in yours but check it out now (http://www.itresource.com.au/page_ping.php). I wont bother explaining, you will see the results yourself.

Dismounted
10-23-2007, 10:24 AM
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'page_ping');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
'page_ping'
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
chdir('/home/USERNAME/public_html');
require_once('./global.php');

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

// do pinging
if ($_GET['do'] == 'ping')
{
$domain = $_POST['domain'];
exec("ping -w 10 -c 5 $domain", $temp, $pingresult);
}

// prepare navbits
$navbits = array();
$navbits[] = 'Ping';
$navbits = construct_navbits($navbits);

// spit out html
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('page_ping') . '");');
?>

rayw
10-23-2007, 11:04 AM
Now no results appear, just a 0 under the form.

Dismounted
10-23-2007, 11:22 AM
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'page_ping');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
'page_ping'
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
chdir('/home/USERNAME/public_html');
require_once('./global.php');

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

// do pinging
if ($_GET['do'] == 'ping')
{
$domain = $_POST['domain'];
exec("ping -w 10 -c 5 $domain", $output);
}

// implode output
$pingresult = implode('<br />', $output);

// prepare navbits
$navbits = array();
$navbits[] = 'Ping';
$navbits = construct_navbits($navbits);

// spit out html
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('page_ping') . '");');
?>

rayw
10-23-2007, 12:17 PM
So close!

When the page loads, "Warning: implode() [function.implode]: Bad arguments. in /page_ping.php on line 39" appears at the top. The ping works though - the results appear where they should. Once the ping is complete, the implode error disappears.

Dismounted
10-24-2007, 06:40 AM
Sorry, I was a bit careless :p.
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'page_ping');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
'page_ping'
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ########################## REQUIRE BACK-END ############################
chdir('/home/USERNAME/public_html');
require_once('./global.php');

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

// do pinging
if ($_GET['do'] == 'ping')
{
$domain = $_POST['domain'];
exec("ping -w 10 -c 5 $domain", $output);
$pingresult = implode('<br />', $output);
}

// prepare navbits
$navbits = array();
$navbits[] = 'Ping';
$navbits = construct_navbits($navbits);

// spit out html
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('page_ping') . '");');
?>