cm.php
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 22k
Category:

WEB Mail

Development Platform:

PHP

  1. <?php
  2. /* Copyright 2002-2003 Phillip Stansell & Damien Heiser
  3.  *
  4.  * This file is part of Caffeine Monkey.
  5.  *
  6.  * Caffeine Monkey is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * Caffeine Monkey is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with Caffeine Monkey; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  */
  20. require_once "HTML/IT.php";
  21. // parse the config.ini file and place the result in an array
  22. $settings = parse_ini_file( './includes/config.ini', TRUE );
  23. // initialize an integrated template object and set the path for template files
  24. $tpl = new IntegratedTemplate( $settings['include_path'] );
  25. /**
  26.  * html_header(array $params)
  27.  *
  28.  * Optional more detailed description.
  29.  *
  30.  * @param $params - array - An array containing variables and replacement
  31.  * values for the Integrated Template. If this variable is null
  32.  * the header is not processed as a template.
  33.  *
  34.  * @return A single string containing the final HTML header
  35.  *
  36.  */
  37. function html_header($params = NULL)
  38. {
  39. global $settings;
  40. $file_name = $settings['html_header'];
  41. $file_path = $settings['include_path'];
  42. if ( is_null($params) ) {
  43. return include_html($file_path . $file_name);
  44. } else {
  45. return include_IT($file_name, $params);
  46. }
  47. }
  48. /**
  49.  * html_footer(array $params)
  50.  *
  51.  * Optional more detailed description.
  52.  *
  53.  * @param $params - array - An array containing variables and replacement
  54.  * values for the Integrated Template. If this variable is null
  55.  * the footer is not processed as a template.
  56.  *
  57.  * @return A single string containing the final HTML footer
  58.  *
  59.  */
  60. function html_footer($params = NULL)
  61. {
  62. global $settings;
  63. $file_name = $settings['html_footer'];
  64. $file_path = $settings['include_path'];
  65. if ( is_null($params) ) {
  66. return include_html($file_path . $file_name);
  67. } else {
  68. return include_IT($file_name, $params);
  69. }
  70. }
  71. /**
  72.  * include_html(string $file_name)
  73.  *
  74.  * Optional more detailed description.
  75.  *
  76.  * @param $file_name - string - The name of the file containing the HTML
  77.  * code you wish to include
  78.  *
  79.  * @return A single string containing unmodified HTML
  80.  *
  81.  */
  82. function include_html($file_name)
  83. {
  84.         $htmlfile = file($file_name);
  85.         return implode ("n", $htmlfile);
  86. }
  87. /**
  88.  * include_IT(string $file_name, array $params)
  89.  *
  90.  * Optional more detailed description.
  91.  *
  92.  * @param $file_name - string - The name of the file containing the HTML
  93.  * template to be processed
  94.  * @param $params - array - An array containing key/value pairs to be
  95.  * used in processing the template. If a key matches a variable
  96.  * in the template, that variable is replaced the corresponding
  97.  * value.
  98.  *
  99.  * @return A single string containing the parsed HTML template
  100.  *
  101.  */
  102. function include_IT($file_name, $params)
  103. {
  104. global $tpl;
  105. $tpl->loadTemplatefile( $file_name, true, true );
  106. $tpl->setCurrentBlock();
  107. $tpl->setVariable( $params );
  108. $tpl->parseCurrentBlock();
  109. return $tpl->get();
  110. }
  111. /**
  112.  * include_ping()
  113.  *
  114.  * Includes the ping form into your index.html
  115.  *
  116.  * Usage <?php echo include_ping();?>
  117.  *
  118.  */
  119. function include_ping()
  120. {
  121. global $tpl;
  122. global $settings;
  123. $tpl->loadTemplatefile( "ping.inc", true, true );
  124. $ping_form = $settings['PING_FORM'];
  125. foreach ( explode( ',', $ping_form['form_options'] ) as $value ) {
  126. if ( strcasecmp( $value, 'count' ) == 0 ) {
  127. foreach ( explode( ',', $ping_form['count_options'] ) as $key => $value ) {
  128. $tpl->setCurrentBlock( "coptions" );
  129. if ( strcasecmp( $key, 'SELECTED' ) == 0 ) {
  130. $tpl->setVariable( 'SELECTED', $key );
  131. } else {
  132. $tpl->setVariable( 'SELECTED', '' );
  133. }
  134. $tpl->setVariable( 'VALUE', $value );
  135. $tpl->parseCurrentBlock( "coptions" );
  136. }
  137. } elseif ( strcasecmp( $value, 'size' ) == 0 ) {
  138. foreach ( explode( ',', $ping_form['size_options'] ) as $key => $value ) {
  139. $tpl->setCurrentBlock( 'soptions' );
  140. if ( strcasecmp( $key, 'SELECTED' ) == 0 ) {
  141. $tpl->setVariable( 'SELECTED', $key );
  142. } else {
  143. $tpl->setVariable( 'SELECTED', '' );
  144. }
  145. $tpl->setVariable( 'VALUE', $value );
  146. $tpl->parseCurrentBlock( 'soptions' );
  147. }
  148. $tpl->setCurrentBlock( 'size' );
  149. $tpl->setVariable( 'SIZE_UNITS', $ping_form['size_units'] );
  150. $tpl->parseCurrentBlock( 'size' );
  151. } elseif ( strcasecmp( $value, 'timeout' ) == 0 ) {
  152. foreach ( explode( ',', $ping_form['timeout_options'] ) as $key => $value ) {
  153. $tpl->setCurrentBlock( "toptions" );
  154. if ( strcasecmp( $key, 'SELECTED' ) == 0 ) {
  155. $tpl->setVariable( 'SELECTED', $key );
  156. } else {
  157. $tpl->setVariable( 'SELECTED', '' );
  158. }
  159. $tpl->setVariable( 'VALUE', $value );
  160. $tpl->parseCurrentBlock( "toptions" );
  161. }
  162. $tpl->setCurrentBlock( 'timeout' );
  163. $tpl->setVariable( 'TIMEOUT_UNITS', $ping_form['timeout_units'] );
  164. $tpl->parseCurrentBlock( 'timeout' );
  165. } elseif ( strcasecmp( $value, 'n' ) == 0 ) {
  166. $tpl->setCurrentBlock( 'line_break' );
  167. $tpl->setVariable( 'BR', '<br>' );
  168. $tpl->parseCurrentBlock( 'line_break' );
  169. }
  170. }
  171. $tpl->setCurrentBlock();
  172. $tpl->setVariable( 'ACTION', $ping_form['action'] );
  173. $tpl->setVariable( 'ENCODING', $ping_form['encoding'] );
  174. $tpl->setVariable( 'TARGET', $ping_form['target'] );
  175. $tpl->parseCurrentBlock();
  176. return $tpl->get();
  177. }
  178. /**
  179.  * include_trace()
  180.  *
  181.  * Includes the traceroute form into your index.html
  182.  *
  183.  * Usage <?php echo include_trace();?>
  184.  *
  185.  */
  186. function include_trace()
  187. {
  188. global $tpl;
  189. global $settings;
  190. $tpl->loadTemplatefile( "trace.inc", true, true );
  191. $trace_form = $settings['TRACE_FORM'];
  192. foreach ( explode( ',', $trace_form['form_options'] ) as $value ) {
  193. if ( strcasecmp( $value, 'hops' ) == 0 ) {
  194. foreach ( explode( ',', $trace_form['hops_options'] ) as $value ) {
  195. $tpl->setCurrentBlock( "hoptions" );
  196. $tpl->setVariable( 'VALUE', $value );
  197. $tpl->parseCurrentBlock( "hoptions" );
  198. }
  199. } elseif ( strcasecmp( $value, 'size' ) == 0 ) {
  200. foreach ( explode( ',', $trace_form['size_options'] ) as $value ) {
  201. $tpl->setCurrentBlock( "soptions" );
  202. $tpl->setVariable( 'VALUE', $value );
  203. $tpl->parseCurrentBlock( "soptions" );
  204. }
  205. $tpl->setCurrentBlock( 'size' );
  206. $tpl->setVariable( 'SIZE_UNITS', $trace_form['size_units'] );
  207. $tpl->parseCurrentBlock( 'size' );
  208. } elseif ( strcasecmp( $value, 'timeout' ) == 0 ) {
  209. foreach ( explode( ',', $trace_form['timeout_options'] ) as $value ) {
  210. $tpl->setCurrentBlock( "toptions" );
  211. $tpl->setVariable( 'VALUE', $value );
  212. $tpl->parseCurrentBlock( "toptions" );
  213. }
  214. $tpl->setCurrentBlock( 'timeout' );
  215. $tpl->setVariable( 'TIMEOUT_UNITS', $trace_form['timeout_units'] );
  216. $tpl->parseCurrentBlock( 'timeout' );
  217. } elseif ( strcasecmp( $value, 'dodns' ) == 0 ) {
  218. $tpl->setCurrentBlock( "dodns" );
  219. $tpl->setVariable( 'CHECKED', $trace_form['dodns'] );
  220. $tpl->parseCurrentBlock( "dodns" );
  221. }
  222. }
  223. $tpl->setCurrentBlock();
  224. $tpl->setVariable( 'ACTION', $trace_form['action'] );
  225. $tpl->setVariable( 'ENCODING', $trace_form['encoding'] );
  226. $tpl->setVariable( 'TARGET', $trace_form['target'] );
  227. $tpl->parseCurrentBlock();
  228. return $tpl->get();
  229. }
  230. /**
  231.  * include_nslookup()
  232.  *
  233.  * Includes the nslookup form into your index.html
  234.  *
  235.  * Usage <?php echo include_nslookup();?>
  236.  *
  237.  */
  238. function include_nslookup()
  239. {
  240. global $tpl;
  241. global $settings;
  242. $tpl->loadTemplatefile( "nslookup.inc", true, true );
  243. $ns_form = $settings['NS_FORM'];
  244. foreach ( explode(',', $ns_form['query_options']) as $type ) {
  245. $radio_options = explode( ',', $ns_form[$type] );
  246. $radio_options[] = $type;
  247. $tpl->setCurrentBlock( "radio-input" );
  248. $tpl->setVariable( 'LABEL', $radio_options[0] );
  249. $tpl->setVariable( 'ID', $radio_options[1] );
  250. $tpl->setVariable( 'VALUE', $radio_options[2] );
  251. $tpl->parseCurrentBlock( "radio-input" );
  252. }
  253. $tpl->setCurrentBlock();
  254. $tpl->setVariable( "ACTION", $ns_form['action'] );
  255. $tpl->setVariable( "ENCODING", $ns_form['encoding'] );
  256. $tpl->setVariable( "TARGET", $ns_form['target'] );
  257. $tpl->parseCurrentBlock();
  258. return $tpl->get();
  259. }
  260. /**
  261.  * include_whois()
  262.  *
  263.  * Includes the whois form into your index.html
  264.  *
  265.  * Usage <?php echo include_whois();?>
  266.  *
  267.  */
  268. function include_whois()
  269. {
  270. global $tpl;
  271. global $settings;
  272. $tpl->loadTemplatefile( 'whois.inc', true, true );
  273. $whois_form = $settings['WHOIS_FORM'];
  274. $tpl->setCurrentBlock();
  275. $tpl->setVariable( 'ACTION', $whois_form['action'] );
  276. $tpl->setVariable( 'ENCODING', $whois_form['encoding'] );
  277. $tpl->setVariable( 'TARGET', $whois_form['target'] );
  278. $tpl->parseCurrentBlock();
  279. return $tpl->get();
  280. }
  281. /**
  282.  * include_portscan()
  283.  *
  284.  * Includes the portscan form into your index.html
  285.  *
  286.  * Usage <?php echo include_portscan();?>
  287.  *
  288.  */
  289. function include_portscan()
  290. {
  291. global $tpl;
  292. global $settings;
  293. $tpl->loadTemplatefile( 'scan.inc', true, true );
  294. $scan_form = $settings['SCAN_FORM'];
  295. $tpl->setCurrentBlock();
  296. $tpl->setVariable( 'ACTION', $scan_form['action'] );
  297. $tpl->setVariable( 'ENCODING', $scan_form['encoding'] );
  298. $tpl->setVariable( 'TARGET', $scan_form['target'] );
  299. $tpl->parseCurrentBlock();
  300. return $tpl->get();
  301. }
  302. /**
  303.  * include_rangescan()
  304.  *
  305.  * Includes the ranged portscan form into your index.html
  306.  *
  307.  * Usage <?php echo include_rangescan();?>
  308.  *
  309.  */
  310. function include_rangescan()
  311. {
  312. global $tpl;
  313. global $settings;
  314. $tpl->loadTemplatefile( 'rangescan.inc', true, true );
  315. $scan_form = $settings['SCAN_FORM'];
  316. $tpl->setCurrentBlock();
  317. $tpl->setVariable( 'ACTION', $scan_form['action'] );
  318. $tpl->setVariable( 'ENCODING', $scan_form['encoding'] );
  319. $tpl->setVariable( 'TARGET', $scan_form['target'] );
  320. $tpl->setVariable( 'RANGE', $scan_form['range'] );
  321. $tpl->parseCurrentBlock();
  322. return $tpl->get();
  323. }
  324. /**
  325.  * nslookup(string $host, string $server, string $type)
  326.  *
  327.  * Optional more detailed description.
  328.  *
  329.  * @param $host - string - name or IP address of host about which to query
  330.  * @param $server - string - name or IP address of DNS server to query
  331.  * @param $type - string - the type of lookup to perform
  332.  *
  333.  * @return an nslookup command string built from the flags and options
  334.  * provided 
  335.  */
  336. function nslookup($host, $server, $type)
  337. {
  338. global $settings;
  339. $query_flag = &$settings['NSLOOKUP_CMD']['query_flag'];
  340. $query_default = &$settings['NSLOOKUP_CMD']['query_default'];
  341. $query_mx = &$settings['NSLOOKUP_CMD']['query_mx'];
  342. $query_ns = &$settings['NSLOOKUP_CMD']['query_ns'];
  343. if ( strcmp($settings['bind_version'], "8") == 0 ) {
  344. $ns_command = &$settings['NSLOOKUP_CMD']['ns_command_8'];
  345. } elseif ( strcmp($settings['bind_version'], "9") == 0 ) {
  346. $ns_command = &$settings['NSLOOKUP_CMD']['ns_command_9'];
  347. }
  348. //set lookup type; if no type is given use the default
  349. if ( isset($type) ) {
  350. if ( strcasecmp($type, "a") == 0 ) {
  351. $ns_command = $ns_command.$query_flag.$query_default;
  352. } elseif ( strcasecmp($type, "mx") == 0 ) {
  353. $ns_command = $ns_command.$query_flag.$query_mx;
  354. } elseif ( strcasecmp($type, "ns") == 0 ) {
  355. $ns_command = $ns_command.$query_flag.$query_ns;
  356. }
  357. } else {
  358. $ns_command = $ns_command.$query_flag.$query_default;
  359. }
  360. //check that host is set, escape any special characters and append 
  361. //it to the command
  362. if ( isset($host) ) {
  363. $host = escapeshellarg($host);
  364. $ns_command = $ns_command.$host;
  365. } else {
  366. return "In function nslookup(): No host entered.";
  367. }
  368. //if server is set, escape any special characters and append it to 
  369. //the command
  370. if ( isset($server) ) {
  371. $server = escapeshellarg($server);
  372. $ns_command = $ns_command.' '.$server;
  373. }
  374. return $ns_command . " 2>&1"; // return the command we've built
  375. }
  376. /**
  377.  * ping(string $host, string $packets, string $size, string $timeout)
  378.  *
  379.  * Optional more detailed description.
  380.  *
  381.  * @param $host - string - name or IP address of host to ping
  382.  * @param $packets - string - number of packets to send
  383.  * @param $size - string - size of packets to send
  384.  * @param $timeout - string - maximum time before ping exits
  385.  *
  386.  * @return A ping command string built from the parameters which were
  387.  * passed and settings in the .ini file
  388.  */
  389. function ping($host, $count, $size, $timeout)
  390. {
  391. global $settings;
  392. $ping_command = &$settings['PING_CMD']['ping_command'];
  393. $posix_type = &$settings['posix_type'];
  394. $count_flag = &$settings['PING_CMD']['count_flag'];
  395. $size_flag = &$settings['PING_CMD']['size_flag'];
  396. $timeout_flag = &$settings['PING_CMD']['timeout_flag'];
  397. //check that count is set, is a number and is within a reasonable range
  398. if ( isset($count) && is_numeric($count) ) {
  399. if ( ( max((int) $count, 100) == 100 ) && ( min((int) $count, 0) == 0 ) ) {
  400. $ping_command = $ping_command.$count_flag.$count;
  401. } else {
  402. return "In function ping(): Packet count entered was out of range.  Acceptable range is 0 to 100.";
  403. }
  404. } else {
  405. return "In function ping(): Packet count entered was not a number.";
  406. }
  407. //check that size is set, is a number and is within a reasonable range
  408. if ($posix_type == "linux")
  409. {
  410. if ( isset($size) && is_numeric($size) ) {
  411. if ( ( max((int) $size, 1024) == 1024 ) && ( min((int) $size, 32) == 32 ) ) {
  412. $size -= 8;
  413. $ping_command = $ping_command.$size_flag.$size;
  414. } else {
  415. return "In function ping(): Packet size entered was out of range.  Acceptable range is 32 to 1024.";
  416. }
  417. } else {
  418. return "In function ping(): Packet size entered was not a number.";
  419. }
  420. }
  421. elseif ($posix_type == "freebsd")
  422. {
  423. }
  424. //check that timeout is set, is a number and is within a reasonable range
  425. if ( isset($timeout) && is_numeric($timeout) ) {
  426. if ( ( max((int) $timeout, 5) == 5 ) && ( min((int) $timeout, 1) == 1 ) ) {
  427. $ping_command = $ping_command.$timeout_flag.$timeout;
  428. } else {
  429. return "In function ping(): Ping timeout entered was out of range.  Acceptable range is 1 to 5.";
  430. }
  431. } else {
  432. return "In function ping(): Timeout entered was not a number.";
  433. }
  434. //check that host is set and escape any special characters
  435. if ( isset($host) ) {
  436. $host = escapeshellarg($host);
  437. $ping_command = $ping_command." ".$host;
  438. } else {
  439. return "In function ping(): No host entered.";
  440. }
  441. return $ping_command . " 2>&1";
  442. }
  443. /**
  444.  * traceroute(string $host, string $hops, string $size, string $timeout, string $dodns)
  445.  *
  446.  * Optional more detailed description.
  447.  *
  448.  * @param $host - string - name or IP address of destination host
  449.  * @param $hops - string - maximum number of hops before ending trace
  450.  * @param $timeout - string - time to wait in seconds for each probe
  451.  * response
  452.  * @param $dodns - string - determines whether DNS lookups are performed;
  453.  * TRUE by default
  454.  * @param $size - string - size of packets to send
  455.  *
  456.  * @return string - A traceroute command string built from the parameters
  457.  * which were passed and settings in the .ini file
  458.  */
  459. function traceroute($host, $hops, $size, $timeout, $dodns)
  460. {
  461. global $settings;
  462. $trace_command = &$settings['TRACE_CMD']['trace_command'];
  463. $disable_dns_flag = &$settings['TRACE_CMD']['disable_dns_flag'];
  464. $max_hops_flag = &$settings['TRACE_CMD']['max_hops_flag'];
  465. $trace_timeout_flag = &$settings['TRACE_CMD']['trace_timeout_flag'];
  466. $trace_size_flag = &$settings['TRACE_CMD']['trace_size_flag'];
  467. //check that dodns is set and disable DNS lookups if its value is 
  468. //not TRUE
  469. if ( isset($dodns) ) {
  470. if ( strcasecmp($dodns, 'YES') != 0 ) {
  471. $trace_command = $trace_command.$disable_dns_flag;
  472. }
  473. } else {
  474. $trace_command = $trace_command.$disable_dns_flag;
  475. }
  476. //check that hops is set, is a number and is within a reasonable range
  477. if ( isset($hops) && is_numeric($hops) ) {
  478. if ( ( max((int) $hops, 50) == 50 ) && ( min((int) $hops, 0) == 0 ) ) {
  479. $trace_command = $trace_command.$max_hops_flag.$hops;
  480. } else {
  481. return "In function traceroute(): Hops entered was out of range.  Acceptable rang is 0 to 50.";
  482. }
  483. } else {
  484. return "In function traceroute(): Hops entered was not a number.";
  485. }
  486. //check that timeout is set, is a number and is within a reasonable range
  487. if ( isset($timeout) && is_numeric($timeout) ) {
  488. if ( ( max((int) $timeout, 5) == 5 ) && ( min((int) $timeout, 2) == 2 ) ) {
  489. $trace_command = $trace_command.$trace_timeout_flag.$timeout;
  490. } elseif ( (int) $timeout == 1 ) {
  491. true;
  492. } else {
  493. return "In function traceroute(): Timeout entered was out of range.  Acceptable range is 1 to 5.";
  494. }
  495. } else {
  496. return "In function traceroute(): Timeout entered was not a number.";
  497. }
  498. //check that host is set and escape any special characters
  499. if ( isset($host) ) {
  500. $host = escapeshellarg($host);
  501. $trace_command = $trace_command." ".$host;
  502. } else {
  503. return "In function traceroute(): No host entered.";
  504. }
  505. //check that size is set, is a number and is within a reasonable range
  506. if ( isset($size) && is_numeric($size) ) {
  507. if ( ( max((int) $size, 1024) == 1024 ) && ( min((int) $size, 38) == 38 ) ) {
  508. $trace_command = $trace_command.$trace_size_flag.$size;
  509. } else {
  510. return "In function traceroute(): Packet size entered was out of range.  Acceptable range is 38 to 1024.";
  511. }
  512. } else {
  513. return "In function traceroute(): Packet size entered was not a number.";
  514. }
  515. return $trace_command . " 2>&1";
  516. }
  517. /**
  518.  * whois(string $domain, string $server)
  519.  *
  520.  * Optional more detailed description.
  521.  *
  522.  * @param $domain - string - domain name to about which query
  523.  * @param $server - string - name of whois server to query
  524.  *
  525.  * @return A whois command string built from the parameters which were
  526.  * passed and settings in the .ini file
  527.  */
  528. function whois($domain, $server)
  529. {
  530. require_once "Net/CheckIP.php";
  531. global $settings;
  532. $whois_command = &$settings['WHOIS_CMD']['whois_command'];
  533. $whois_svr_flag = &$settings['WHOIS_CMD']['whois_svr_flag'];
  534. $whois_command_order = explode(',', &$settings['WHOIS_CMD']['whois_command_order']);
  535. //check that $domain is set and escape any special characters
  536. //if $domain is an IP address, set $server to whois.arin.net
  537. if ( isset($domain) && Net_CHeckIP::check_ip($domain) ) {
  538. $server = 'whois.arin.net';
  539. $domain = escapeshellarg($domain);
  540. } elseif ( isset($domain) ) {
  541. $domain = escapeshellarg($domain);
  542. } else {
  543. return "In function whois(): No domain or IP address entered.";
  544. }
  545. //if server is set and not empty, escape any special characters and 
  546. //append it to the command
  547. if ( isset($server) && strlen($server) > 0 ) {
  548. $server = escapeshellarg($server);
  549. } else {
  550. $whois_svr_flag = '';
  551. }
  552. foreach ( $whois_command_order as $value ) {
  553. if ( !strcmp( $value, "whois_command" ) ) {
  554. continue;
  555. } elseif ( !strcmp( $value, "whois_svr_flag" ) ) {
  556. $whois_command = $whois_command.' '.$whois_svr_flag;
  557. } elseif ( !strcmp( $value, "server" ) ) {
  558. $whois_command = $whois_command.' '.$server;
  559. } elseif ( !strcmp( $value, "domain" ) ) {
  560. $whois_command = $whois_command.' '.$domain;
  561. }
  562. }
  563. return $whois_command . " 2>&1";
  564. }
  565. /**
  566.  * scan(string $domain, int $scan1, int $scan2, int $scan3, int $scan4, int $scan5, int $scan6)
  567.  *
  568.  * Optional more detailed description.
  569.  *
  570.  * @param $domain - string - domain name to about which query
  571.  * @param $scan1::$scan6 - int - port scans to perform
  572.  * @return string which is basically a dump of the output of the portscan command
  573.  */
  574. function scan($domain, $scan1, $scan2, $scan3, $scan4, $scan5, $scan6)
  575. {
  576. require_once "Net/Portscan.php";
  577. // Run Portscans
  578. if ($scan1 == "YES"){if (Net_Portscan::checkPort($domain, 21) == NET_PORTSCAN_SERVICE_FOUND) {$scan_result[$i] = 1; $scan_port[$i] = 21;} else {$scan_result[$i] = 0; $scan_port[$i] = 21;}$i++;}
  579. if ($scan2 == "YES"){if (Net_Portscan::checkPort($domain, 23) == NET_PORTSCAN_SERVICE_FOUND) {$scan_result[$i] = 1; $scan_port[$i] = 23;} else {$scan_result[$i] = 0; $scan_port[$i] = 23;}$i++;}
  580. if ($scan3 == "YES"){if (Net_Portscan::checkPort($domain, 53) == NET_PORTSCAN_SERVICE_FOUND) {$scan_result[$i] = 1; $scan_port[$i] = 53;} else {$scan_result[$i] = 0; $scan_port[$i] = 53;}$i++;}
  581. if ($scan4 == "YES"){if (Net_Portscan::checkPort($domain, 80) == NET_PORTSCAN_SERVICE_FOUND) {$scan_result[$i] = 1; $scan_port[$i] = 80;} else {$scan_result[$i] = 0; $scan_port[$i] = 80;}$i++;}
  582. if ($scan5 == "YES"){if (Net_Portscan::checkPort($domain, 110) == NET_PORTSCAN_SERVICE_FOUND) {$scan_result[$i] = 1; $scan_port[$i] = 110;} else {$scan_result[$i] = 0; $scan_port[$i] = 110;}$i++;}
  583. if ($scan6 != NULL){if (Net_Portscan::checkPort($domain, $scan6) == NET_PORTSCAN_SERVICE_FOUND) {$scan_result[$i] = 1; $scan_port[$i] = $scan6;} else {$scan_result[$i] = 0; $scan_port[$i] = $scan6;}$i++;}
  584. // Display active ports
  585. for ($j == 1; $j < $i; $j++)
  586. {
  587. if ($scan_result[$j] == 1)
  588. {
  589. $result = $result."The host $domain has a service running on port $scan_port[$j] (" . Net_Portscan::getService($scan_port[$j]) . ").n";
  590. $a = 1;
  591. }
  592. }
  593. if ($a == 1)
  594. {
  595. $result = $result."n";
  596. }
  597. // Display non-active ports
  598. for ($k == 1; $k < $i; $k++)
  599. {
  600. if ($scan_result[$k] == 0)
  601. {
  602. $result = $result."The host $domain does not have a service running on port $scan_port[$k] (" . Net_Portscan::getService($scan_port[$k]) . ").n";
  603. }
  604. }
  605. return $result;
  606. }
  607. /**
  608.  * rangescan(string $domain, int $scan1, int $scan2)
  609.  *
  610.  * Optional more detailed description.
  611.  * @param $domain - string - domain name to query with the port scan
  612.  * @param $scan1::$scan2 - int - port range to scan
  613.  *
  614.  */
  615. function rangescan($domain, $scan1, $scan2)
  616. {
  617. $result = $result."Port scanning host $domain with the range of ports $scan1 - $scan2n";
  618. $result = $result."The following ports have services running.nn";
  619. $scan_result = Net_Portscan::checkPortRange($domain, $scan1, $scan2);
  620. foreach ($scan_result as $port=>$element) {if ($element == NET_PORTSCAN_SERVICE_FOUND) {$result = $result."$port (" . Net_Portscan::getService($port) .") ";} else { }}
  621. return $result;
  622. }
  623. ?>