summaryrefslogtreecommitdiff
path: root/ext/snmp/tests/snmp3.phpt
blob: 91eb92ea3bd90afd59aff43220d1fe392fb030fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
--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)