Ref/radius-Phpdoc专题
radius_acct_open
Creates a Radius handle for accounting
说明
resource <span class="methodname">radius_acct_open ( <span class="methodparam">void )
返回值
Returns a handle on success, false on error. This function only
fails if insufficient memory is available.
范例
示例 #1 radius_acct_open example
<?php
$res = radius_acct_open ()
or die ("Could not create handle");
print("Handle successfully created");
?>
radius_add_server
Adds a server
说明
bool <span
class="methodname">radius_add_server ( <span
class="methodparam">resource
$radius_handle , <span
class="type">string $hostname , <span
class="methodparam">int $port , <span
class="methodparam">string $secret ,
int
$timeout , <span
class="type">int $max_tries )
radius_add_server may be called multiple
times, and it may be used together with <span
class="function">radius_config. At most 10 servers may be
specified. When multiple servers are given, they are tried in
round-robin fashion until a valid response is received, or until each
server's max_tries limit has been reached.
参数
radius_handle
hostname
The hostname parameter specifies the server host, either as a fully
qualified domain name or as a dotted-quad IP address in text form.
port
The port specifies the UDP port to contact on the server. If port is
given as 0, the library looks up the radius/udp or radacct/udp
service in the network services database, and uses the port found there.
If no entry is found, the library uses the standard Radius ports, 1812
for authentication and 1813 for accounting.
secret
The shared secret for the server host is passed to the secret
parameter. The Radius protocol ignores all but the leading 128 bytes of
the shared secret.
timeout
The timeout for receiving replies from the server is passed to the
timeout parameter, in units of seconds.
max_tries
The maximum number of repeated requests to make before giving up is
passed into the max_tries.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 radius_add_server example
<?php
if (!radius_add_server($res, 'radius.example.com', 1812, 'testing123', 3, 3)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br>";
exit;
}
?>
参见
- radius_config
radius_auth_open
Creates a Radius handle for authentication
说明
resource <span class="methodname">radius_auth_open ( <span class="methodparam">void )
返回值
Returns a handle on success, false on error. This function only
fails if insufficient memory is available.
范例
示例 #1 radius_auth_open example
<?php
$radh = radius_auth_open()
or die ("Could not create handle");
echo "Handle successfully created";
?>
radius_close
Frees all ressources
说明
bool <span
class="methodname">radius_close ( <span
class="methodparam">resource
$radius_handle )
It is not needed to call this function because php frees all resources at the end of each request.
返回值
成功时返回 true, 或者在失败时返回 false。
radius_config
Causes the library to read the given configuration file
说明
bool <span
class="methodname">radius_config ( <span
class="methodparam">resource
$radius_handle , <span
class="type">string $file )
Before issuing any Radius requests, the library must be made aware of the servers it can contact. The easiest way to configure the library is to call radius_config. <span class="function">radius_config causes the library to read a configuration file whose format is described in » radius.conf.
参数
radius_handle
file
The pathname of the configuration file is passed as the file argument to
radius_config. The library can also be
configured programmatically by calls to <span
class="function">radius_add_server.
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- radius_add_server
radius_create_request
Create accounting or authentication request
说明
bool <span
class="methodname">radius_create_request ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $type )
A Radius request consists of a code specifying the kind of request, and zero or more attributes which provide additional information. To begin constructing a new request, call <span class="function">radius_create_request.
Note: Attention: You must call this function, before you can put any attribute!
参数
radius_handle
type
Type is RADIUS_ACCESS_REQUEST or RADIUS_ACCOUNTING_REQUEST.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 radius_create_request example
<?php
if (!radius_create_request($res, RADIUS_ACCESS_REQUEST)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br />";
exit;
}
?>
参见
- radius_send_request
radius_cvt_addr
Converts raw data to IP-Address
说明
string <span
class="methodname">radius_cvt_addr ( <span
class="methodparam">string $data )
范例
示例 #1 radius_cvt_addr example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf ("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
switch ($attr) {
case RADIUS_FRAMED_IP_ADDRESS:
$ip = radius_cvt_addr($data);
echo "IP: $ip<br>\n";
break;
case RADIUS_FRAMED_IP_NETMASK:
$mask = radius_cvt_addr($data);
echo "MASK: $mask<br>\n";
break;
}
}
?>
参见
- radius_cvt_int
- radius_cvt_string
radius_cvt_int
Converts raw data to integer
说明
int <span
class="methodname">radius_cvt_int ( <span
class="methodparam">string $data )
范例
示例 #1 radius_cvt_int example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf ("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
switch ($attr) {
case RADIUS_FRAMED_MTU:
$mtu = radius_cvt_int($data);
echo "MTU: $mtu<br>\n";
break;
}
}
?>
参见
- radius_cvt_addr
- radius_cvt_string
radius_cvt_string
Converts raw data to string
说明
string <span
class="methodname">radius_cvt_string ( <span
class="methodparam">string $data )
范例
示例 #1 radius_cvt_string example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf ("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
switch ($attr) {
case RADIUS_FILTER_ID:
$id = radius_cvt_string($data);
echo "Filter ID: $id<br>\n";
break;
}
}
?>
参见
- radius_cvt_addr
- radius_cvt_int
radius_demangle_mppe_key
Derives mppe-keys from mangled data
说明
string <span
class="methodname">radius_demangle_mppe_key ( <span
class="methodparam">resource
$radius_handle , <span
class="type">string $mangled )
When using MPPE with MS-CHAPv2, the send- and recv-keys are mangled (see » RFC 2548), however this function is useless, because I don't think that there is or will be a PPTP-MPPE implementation in PHP.
返回值
Returns the demangled string, or false on error.
radius_demangle
Demangles data
说明
string <span
class="methodname">radius_demangle ( <span
class="methodparam">resource
$radius_handle , <span
class="type">string $mangled )
Some data (Passwords, MS-CHAPv1 MPPE-Keys) is mangled for security reasons, and must be demangled before you can use them.
返回值
Returns the demangled string, or false on error.
radius_get_attr
Extracts an attribute
说明
mixed <span
class="methodname">radius_get_attr ( <span
class="methodparam">resource
$radius_handle )
Like Radius requests, each response may contain zero or more attributes. After a response has been received successfully by <span class="function">radius_send_request, its attributes can be extracted one by one using <span class="function">radius_get_attr. Each time <span class="function">radius_get_attr is called, it gets the next attribute from the current response.
返回值
Returns an associative array containing the attribute-type and the data, or error number \<= 0.
范例
示例 #1 radius_get_attr example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
printf("Got Attr:%d %d Bytes %s\n", $attr, strlen($data), bin2hex($data));
}
?>
参见
- radius_put_attr
- radius_get_vendor_attr
- radius_put_vendor_attr
- radius_send_request
radius_get_tagged_attr_data
Extracts the data from a tagged attribute
说明
string<span
class="type">false <span
class="methodname">radius_get_tagged_attr_data ( <span
class="methodparam">string $data )
If a tagged attribute has been returned from <span class="function">radius_get_attr, <span class="function">radius_get_tagged_attr_data will return the data from the attribute.
参数
data
The tagged attribute to be decoded.
返回值
Returns the data from the tagged attribute 或者在失败时返回 false.
范例
示例 #1 radius_get_tagged_attr_data example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf ("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
$tag = radius_get_tagged_attr_tag($data);
$value = radius_get_tagged_attr_data($data);
printf("Got tagged attribute with tag %d and value %s\n", $tag, $value);
}
?>
参见
- radius_get_attr
- radius_get_tagged_attr_tag
radius_get_tagged_attr_tag
Extracts the tag from a tagged attribute
说明
int<span
class="type">false <span
class="methodname">radius_get_tagged_attr_tag ( <span
class="methodparam">string $data )
If a tagged attribute has been returned from <span class="function">radius_get_attr, <span class="function">radius_get_tagged_attr_data will return the tag from the attribute.
参数
data
The tagged attribute to be decoded.
返回值
Returns the tag from the tagged attribute 或者在失败时返回 false.
范例
示例 #1 radius_get_tagged_attr_tag example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf ("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
$tag = radius_get_tagged_attr_tag($data);
$value = radius_get_tagged_attr_data($data);
printf("Got tagged attribute with tag %d and value %s\n", $tag, $value);
}
?>
参见
- radius_get_attr
- radius_get_tagged_attr_data
radius_get_vendor_attr
Extracts a vendor specific attribute
说明
array <span
class="methodname">radius_get_vendor_attr ( <span
class="methodparam">string $data )
If radius_get_attr returns
RADIUS_VENDOR_SPECIFIC, <span
class="function">radius_get_vendor_attr may be called to
determine the vendor.
返回值
Returns an associative array containing the attribute-type, vendor and
the data, or false on error.
范例
示例 #1 radius_get_vendor_attr example
<?php
while ($resa = radius_get_attr($res)) {
if (!is_array($resa)) {
printf ("Error getting attribute: %s\n", radius_strerror($res));
exit;
}
$attr = $resa['attr'];
$data = $resa['data'];
printf("Got Attr:%d %d Bytes %s\n", $attr, strlen($data), bin2hex($data));
if ($attr == RADIUS_VENDOR_SPECIFIC) {
$resv = radius_get_vendor_attr($data);
if (is_array($resv)) {
$vendor = $resv['vendor'];
$attrv = $resv['attr'];
$datav = $resv['data'];
printf("Got Vendor Attr:%d %d Bytes %s\n", $attrv, strlen($datav), bin2hex($datav));
}
}
}
?>
参见
- radius_get_attr
- radius_put_vendor_attr
radius_put_addr
Attaches an IP address attribute
说明
bool <span
class="methodname">radius_put_addr ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $type , <span
class="type">string $addr [, <span
class="methodparam">int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches an IP address attribute to the current RADIUS request.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
type
The attribute type.
addr
An IPv4 address in string form, such as 10.0.0.1.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
radius_put_attr
Attaches a binary attribute
说明
bool <span
class="methodname">radius_put_attr ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $type , <span
class="type">string $value [, <span
class="methodparam">int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches a binary attribute to the current RADIUS request.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
type
The attribute type.
value
The attribute value, which will be treated as a raw binary string.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 radius_put_attr example
<?php
mt_srand(time());
$chall = mt_rand();
$chapval = md5(pack('Ca*',1 , 'sepp' . $chall));
$pass = pack('CH*', 1, $chapval);
if (!radius_put_attr($res, RADIUS_CHAP_PASSWORD, $pass)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br />";
exit;
}
?>
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
参见
- radius_get_attr
- radius_get_vendor_attr
- radius_put_vendor_attr
radius_put_int
Attaches an integer attribute
说明
bool <span
class="methodname">radius_put_int ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $type , <span
class="type">int $value [, <span
class="methodparam">int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches an integer attribute to the current RADIUS request.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
type
The attribute type.
value
The attribute value.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
范例
示例 #1 radius_put_int example
<?php
if (!radius_put_int($res, RAD_FRAMED_PROTOCOL, RAD_PPP)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br />";
exit;
}
?>
参见
- radius_put_string
- radius_put_vendor_int
- radius_put_vendor_string
radius_put_string
Attaches a string attribute
说明
bool <span
class="methodname">radius_put_string ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $type , <span
class="type">string $value [, <span
class="methodparam">int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches a string attribute to the current RADIUS request. In general, radius_put_attr is a more useful function for attaching string attributes, as it is binary safe.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
type
The attribute type.
value
The attribute value. This value is expected by the underlying library to
be null terminated, therefore this parameter is not binary safe.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
范例
示例 #1 radius_put_string example
<?php
if (!radius_put_string($res, RADIUS_USER_NAME, 'billy')) {
echo 'RadiusError:' . radius_strerror($res). "\n<br />";
exit;
}
?>
参见
- radius_put_int
- radius_put_vendor_int
- radius_put_vendor_string
radius_put_vendor_addr
Attaches a vendor specific IP address attribute
说明
bool <span
class="methodname">radius_put_vendor_addr ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $vendor , <span
class="methodparam">int $type , <span
class="methodparam">string $addr )
Attaches an IP address vendor specific attribute to the current RADIUS request.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
vendor
The vendor ID.
type
The attribute type.
addr
An IPv4 address in string form, such as 10.0.0.1.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
radius_put_vendor_attr
Attaches a vendor specific binary attribute
说明
bool <span
class="methodname">radius_put_vendor_attr ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $vendor , <span
class="methodparam">int $type , <span
class="methodparam">string $value [,
int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches a vendor specific binary attribute to the current RADIUS request.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
vendor
The vendor ID.
type
The attribute type.
value
The attribute value, which will be treated as a raw binary string.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
范例
示例 #1 radius_put_vendor_attr example
<?php
if (!radius_put_vendor_attr($res, RADIUS_VENDOR_MICROSOFT, RAD_MICROSOFT_MS_CHAP_CHALLENGE, $challenge)) {
echo 'RadiusError:' . radius_strerror($res). "\n<br />";
exit;
}
?>
参见
- radius_get_vendor_attr
radius_put_vendor_int
Attaches a vendor specific integer attribute
说明
bool <span
class="methodname">radius_put_vendor_int ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $vendor , <span
class="methodparam">int $type , <span
class="methodparam">int $value [,
int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches a vendor specific integer attribute to the current RADIUS request.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
vendor
The vendor ID.
type
The attribute type.
value
The attribute value.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
参见
- radius_put_vendor_string
radius_put_vendor_string
Attaches a vendor specific string attribute
说明
bool <span
class="methodname">radius_put_vendor_string ( <span
class="methodparam">resource
$radius_handle , <span
class="type">int $vendor , <span
class="methodparam">int $type , <span
class="methodparam">string $value [,
int $options<span
class="initializer"> = 0 [, <span
class="methodparam">int $tag ]] )
Attaches a vendor specific string attribute to the current RADIUS request. In general, <span class="function">radius_put_vendor_attr is a more useful function for attaching string attributes, as it is binary safe.
Note:
A request must be created via <span class="function">radius_create_request before this function can be called.
参数
radius_handle
The RADIUS resource.
vendor
The vendor ID.
type
The attribute type.
value
The attribute value. This value is expected by the underlying library to
be null terminated, therefore this parameter is not binary safe.
options
A bitmask of the attribute options. The available options include
RADIUS_OPTION_TAGGED
and
RADIUS_OPTION_SALT.
tag
The attribute tag. This parameter is ignored unless the
RADIUS_OPTION_TAGGED
option is set.
返回值
成功时返回 true, 或者在失败时返回 false。
更新日志
| 版本 | 说明 |
|---|---|
| PECL radius 1.3.0 | The options and tag parameters were added. |
参见
- radius_put_vendor_int
radius_request_authenticator
Returns the request authenticator
说明
string <span
class="methodname">radius_request_authenticator ( <span
class="methodparam">resource
$radius_handle )
The request authenticator is needed for demangling mangled data like passwords and encryption-keys.
返回值
Returns the request authenticator as string, or false on error.
参见
- radius_demangle
radius_salt_encrypt_attr
Salt-encrypts a value
说明
string<span
class="type">false <span
class="methodname">radius_salt_encrypt_attr ( <span
class="methodparam">resource
$radius_handle , <span
class="type">string $data )
Applies the RADIUS salt-encryption algorithm to the given value.
In general, this is achieved automatically by providing the
RADIUS_OPTION_SALT option to an attribute setter function, but
this function can be used if low-level request construction is required.
参数
data
The data to be salt-encrypted.
返回值
Returns the salt-encrypted data 或者在失败时返回 false.
参见
- radius_put_addr
- radius_put_attr
- radius_put_int
- radius_put_string
radius_send_request
Sends the request and waits for a reply
说明
int <span
class="methodname">radius_send_request ( <span
class="methodparam">resource
$radius_handle )
After the Radius request has been constructed, it is sent by <span class="function">radius_send_request.
The radius_send_request function sends the request and waits for a valid reply, retrying the defined servers in round-robin fashion as necessary.
返回值
If a valid response is received, <span
class="function">radius_send_request returns the Radius code
which specifies the type of the response. This will typically be
RADIUS_ACCESS_ACCEPT, RADIUS_ACCESS_REJECT, or
RADIUS_ACCESS_CHALLENGE. If no valid response is received, <span
class="function">radius_send_request returns false.
参见
- radius_create_request
radius_server_secret
Returns the shared secret
说明
string <span
class="methodname">radius_server_secret ( <span
class="methodparam">resource
$radius_handle )
The shared secret is needed as salt for demangling mangled data like passwords and encryption-keys.
返回值
Returns the server's shared secret as string, or false on error.
radius_strerror
Returns an error message
说明
string <span
class="methodname">radius_strerror ( <span
class="methodparam">resource
$radius_handle )
If Radius-functions fail then they record an error message. This error message can be retrieved with this function.
返回值
Returns error messages as string from failed radius functions.
目录
- radius_acct_open — Creates a Radius handle for accounting
- radius_add_server — Adds a server
- radius_auth_open — Creates a Radius handle for authentication
- radius_close — Frees all ressources
- radius_config — Causes the library to read the given configuration file
- radius_create_request — Create accounting or authentication request
- radius_cvt_addr — Converts raw data to IP-Address
- radius_cvt_int — Converts raw data to integer
- radius_cvt_string — Converts raw data to string
- radius_demangle_mppe_key — Derives mppe-keys from mangled data
- radius_demangle — Demangles data
- radius_get_attr — Extracts an attribute
- radius_get_tagged_attr_data — Extracts the data from a tagged attribute
- radius_get_tagged_attr_tag — Extracts the tag from a tagged attribute
- radius_get_vendor_attr — Extracts a vendor specific attribute
- radius_put_addr — Attaches an IP address attribute
- radius_put_attr — Attaches a binary attribute
- radius_put_int — Attaches an integer attribute
- radius_put_string — Attaches a string attribute
- radius_put_vendor_addr — Attaches a vendor specific IP address attribute
- radius_put_vendor_attr — Attaches a vendor specific binary attribute
- radius_put_vendor_int — Attaches a vendor specific integer attribute
- radius_put_vendor_string — Attaches a vendor specific string attribute
- radius_request_authenticator — Returns the request authenticator
- radius_salt_encrypt_attr — Salt-encrypts a value
- radius_send_request — Sends the request and waits for a reply
- radius_server_secret — Returns the shared secret
- radius_strerror — Returns an error message