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