xref: /PHP-5.4/ext/snmp/tests/snmp3.phpt (revision 5e82e334)
1--TEST--
2SNMPv3 Support
3--CREDITS--
4Boris Lytochkin
5--SKIPIF--
6<?php
7require_once(dirname(__FILE__).'/skipif.inc');
8?>
9--FILE--
10<?php
11require_once(dirname(__FILE__).'/snmp_include.inc');
12
13//int snmp3_get(string host, string sec_name, string sec_level, string auth_protocol,
14//              string auth_passphrase, string priv_protocol, string priv_passphrase,
15//              string object_id [, int timeout [, int retries]]);
16
17echo "Working version\n";
18snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
19echo "GET single: noAuthNoPriv\n";
20var_dump(snmp3_get($hostname, $user_noauth, 'noAuthNoPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
21
22foreach(array('MD5', 'SHA') as $signalg) {
23	echo "GET single: $signalg\n";
24	var_dump(snmp3_get($hostname, $user_auth_prefix . $signalg, 'authNoPriv', $signalg, $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
25}
26
27foreach(array('AES', 'DES', 'AES128') as $chipher) {
28	echo "GET single: MD5/$chipher\n";
29	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));
30}
31$username = $user_auth_prefix . 'MD5';
32echo "GET multiple\n";
33var_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));
34echo "GETNEXT single\n";
35var_dump(snmp3_getnext($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
36
37echo "WALK single on single OID\n";
38$z = snmp3_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
39var_dump(gettype($z));
40var_dump(count($z));
41var_dump($z);
42
43echo "REALWALK single on single OID\n";
44$z = snmp3_real_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1.1.0', $timeout, $retries);
45var_dump(gettype($z));
46var_dump(count($z));
47var_dump($z);
48
49echo "WALK multiple on single OID\n";
50$z = snmp3_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, '', '', '.1.3.6.1.2.1.1', $timeout, $retries);
51var_dump(gettype($z));
52var_dump(count($z));
53var_dump(key($z));
54var_dump(array_shift($z));
55
56echo "REALWALK multiple on single OID\n";
57$z = snmp3_real_walk($hostname, $username, 'authNoPriv', 'MD5', $auth_pass, 'AES', '', '.1.3.6.1.2.1.1', $timeout, $retries);
58var_dump(gettype($z));
59var_dump(count($z));
60var_dump(key($z));
61var_dump(array_shift($z));
62
63echo "SET single OID\n";
64$oid1 = 'SNMPv2-MIB::sysContact.0';
65$oldvalue1 = snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries);
66$newvalue1 = $oldvalue1 . '0';
67
68$z = snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, 's', $newvalue1, $timeout, $retries);
69var_dump($z);
70var_dump((snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries) === $newvalue1));
71$z = snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, 's', $oldvalue1, $timeout, $retries);
72var_dump($z);
73var_dump((snmp3_get($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $oid1, $timeout, $retries) === $oldvalue1));
74
75?>
76--EXPECTF--
77Working version
78GET single: noAuthNoPriv
79%string|unicode%(%d) "%s"
80GET single: MD5
81%string|unicode%(%d) "%s"
82GET single: SHA
83%string|unicode%(%d) "%s"
84GET single: MD5/AES
85%string|unicode%(%d) "%s"
86GET single: MD5/DES
87%string|unicode%(%d) "%s"
88GET single: MD5/AES128
89%string|unicode%(%d) "%s"
90GET multiple
91array(2) {
92  ["%s"]=>
93  %string|unicode%(%d) "%s"
94  ["%s"]=>
95  %string|unicode%(%d) "%s"
96}
97GETNEXT single
98%string|unicode%(%d) "%s"
99WALK single on single OID
100%string|unicode%(5) "array"
101int(1)
102array(1) {
103  [0]=>
104  %string|unicode%(%d) "%s"
105}
106REALWALK single on single OID
107%string|unicode%(5) "array"
108int(1)
109array(1) {
110  ["%s"]=>
111  %string|unicode%(%d) "%s"
112}
113WALK multiple on single OID
114%string|unicode%(5) "array"
115int(%d)
116int(0)
117%string|unicode%(%d) "%s"
118REALWALK multiple on single OID
119%string|unicode%(5) "array"
120int(%d)
121%string|unicode%(%d) "%s"
122%string|unicode%(%d) "%s"
123SET single OID
124bool(true)
125bool(true)
126bool(true)
127bool(true)
128