File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / snmp / tests / snmp3.phpt
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:34:42 2012 UTC (12 years, 5 months ago) by misho
Branches: php, MAIN
CVS tags: v5_4_3elwix, v5_4_29p0, v5_4_29, v5_4_20p0, v5_4_20, v5_4_17p0, v5_4_17, HEAD
php 5.4.3+patches

--TEST--                                 
SNMPv3 Support
--CREDITS--
Boris Lytochkin
--SKIPIF--
<?php
require_once(dirname(__FILE__).'/skipif.inc');
?>
--FILE--
<?php
require_once(dirname(__FILE__).'/snmp_include.inc');

//int snmp3_get(string host, string sec_name, string sec_level, string auth_protocol, 
//              string auth_passphrase, string priv_protocol, string priv_passphrase, 
//              string object_id [, int timeout [, int retries]]);

echo "Working version\n";
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
echo "GET single: noAuthNoPriv\n";
var_dump(snmp3_get($hostname, $user_noauth, 'noAuthNoPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));

foreach(array('MD5', 'SHA') as $signalg) {
	echo "GET single: $signalg\n";
	var_dump(snmp3_get($hostname, $user_auth_prefix . $signalg, 'authNoPriv', $signalg, $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
}

foreach(array('AES', 'DES', 'AES128') as $chipher) {
	echo "GET single: MD5/$chipher\n";
	var_dump(snmp3_get($hostname, $user_auth_prefix . 'MD5' . $chipher, 'authPriv', 'MD5', $auth_pass, $chipher, $priv_pass, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
}
$username = $user_auth_prefix . 'MD5';
echo "GET multiple\n";
var_dump(snmp3_get($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0'), $timeout, $retries));
echo "GETNEXT single\n";
var_dump(snmp3_getnext($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));

echo "WALK single on single OID\n";
$z = snmp3_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump($z);

echo "REALWALK single on single OID\n";
$z = snmp3_real_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump($z);

echo "WALK multiple on single OID\n";
$z = snmp3_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump(key($z));
var_dump(array_shift($z));

echo "REALWALK multiple on single OID\n";
$z = snmp3_real_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, 'AES', '', '.1.3.6.1.2.1.1', $timeout, $retries);
var_dump(gettype($z));
var_dump(count($z));
var_dump(key($z));
var_dump(array_shift($z));

echo "SET single OID\n";
$oid1 = 'SNMPv2-MIB::sysContact.0';
$oldvalue1 = snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries);
$newvalue1 = $oldvalue1 . '0';

$z = snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, 's', $newvalue1, $timeout, $retries);
var_dump($z);
var_dump((snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries) === $newvalue1));
$z = snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, 's', $oldvalue1, $timeout, $retries);
var_dump($z);
var_dump((snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries) === $oldvalue1));

?>
--EXPECTF--
Working version
GET single: noAuthNoPriv
%string|unicode%(%d) "%s"
GET single: MD5
%string|unicode%(%d) "%s"
GET single: SHA
%string|unicode%(%d) "%s"
GET single: MD5/AES
%string|unicode%(%d) "%s"
GET single: MD5/DES
%string|unicode%(%d) "%s"
GET single: MD5/AES128
%string|unicode%(%d) "%s"
GET multiple
array(2) {
  ["%s"]=>
  %string|unicode%(%d) "%s"
  ["%s"]=>
  %string|unicode%(%d) "%s"
}
GETNEXT single
%string|unicode%(%d) "%s"
WALK single on single OID
%string|unicode%(5) "array"
int(1)
array(1) {
  [0]=>
  %string|unicode%(%d) "%s"
}
REALWALK single on single OID
%string|unicode%(5) "array"
int(1)
array(1) {
  ["%s"]=>
  %string|unicode%(%d) "%s"
}
WALK multiple on single OID
%string|unicode%(5) "array"
int(%d)
int(0)
%string|unicode%(%d) "%s"
REALWALK multiple on single OID
%string|unicode%(5) "array"
int(%d)
%string|unicode%(%d) "%s"
%string|unicode%(%d) "%s"
SET single OID
bool(true)
bool(true)
bool(true)
bool(true)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>