Bitrix API

HostRestriction

Class HostRestriction

Tags
since
14.0.6
example

tests/security/hosts/basic.php

Table of Contents

Constants

ACTION_REDIRECT  = 'redirect'
ACTION_STOP  = 'stop'

Methods

__construct()  : mixed
getAction()  : string
getActionOptions()  : array<string|int, mixed>
getActive()  : bool
getHosts()  : string
getLogging()  : bool
getProperties()  : array<string|int, mixed>
getValidationRegExp()  : string
Return regular expressions (based on hosts) for checking.
isValidHost()  : bool
Checking host by host restriction policy
onPageStart()  : void
Handler for system event "OnPageStart", does nothing in CLI mode because it does not make sense
process()  : $this
The main method that checks the current host, logging and starting action
save()  : $this
Save all properties, enable automatic checking and clear cache if needed
setAction()  : $this
Set action performed while checking
setActive()  : $this
Activate or deactivate automatic checking
setHosts()  : $this
Set allowed hosts
setLogging()  : $this
Activate or deactivate logging on unallowed host requested
setProperties()  : $this
Set various properties for host checking, now support: - hosts: a string with allowed hosts (wild card supported, e.g.: *.example.com) {@see setHosts} - action: a string with action for unallowed host {@see validActions} - action_options: array with some options for action {@see setAction} - logging: bool, set true if need logging unallowed host {@see setLogging} - active: bool, set true if automatic checking on every request needed

Constants

Methods

getActionOptions()

public getActionOptions() : array<string|int, mixed>
Return values
array<string|int, mixed>

getProperties()

public getProperties() : array<string|int, mixed>
Return values
array<string|int, mixed>

getValidationRegExp()

Return regular expressions (based on hosts) for checking.

public getValidationRegExp() : string

Note: regular expression is cached for performance improvement and auto cleared after saving save

Return values
string

isValidHost()

Checking host by host restriction policy

public isValidHost(string $host) : bool
Parameters
$host : string

Host for checking.

Tags
throws
ArgumentTypeException
Return values
bool

Return true for valid (allowed) host.

onPageStart()

Handler for system event "OnPageStart", does nothing in CLI mode because it does not make sense

public static onPageStart() : void

process()

The main method that checks the current host, logging and starting action

public process([string $host = null ]) : $this
Parameters
$host : string = null

Requested host for checking.

Return values
$this

save()

Save all properties, enable automatic checking and clear cache if needed

public save() : $this
Return values
$this

setAction()

Set action performed while checking

public setAction(string $action[, array<string|int, mixed> $options = array() ]) : $this
Parameters
$action : string

Some action, now supported: redirect and stop.

$options : array<string|int, mixed> = array()

Some options for action, so far supported only host for redirect in redirect action.

Tags
throws
LogicException
throws
ArgumentTypeException
throws
ArgumentNullException
throws
ArgumentOutOfRangeException
Return values
$this

setActive()

Activate or deactivate automatic checking

public setActive([bool $isActive = false ]) : $this
Parameters
$isActive : bool = false

Set true for enable checking on every request.

Tags
throws
ArgumentTypeException
Return values
$this

setHosts()

Set allowed hosts

public setHosts(string $hosts[, bool $ignoreChecking = false ]) : $this
Parameters
$hosts : string

Allowed hosts (wild card supported, e.g.: *.example.com).

$ignoreChecking : bool = false

Set false for disable host validating before set.

Tags
throws
ArgumentTypeException
throws
LogicException
Return values
$this

setLogging()

Activate or deactivate logging on unallowed host requested

public setLogging([bool $isLogNeeded = true ]) : $this
Parameters
$isLogNeeded : bool = true

Set true if need logging unallowed host.

Tags
throws
ArgumentTypeException
Return values
$this

setProperties()

Set various properties for host checking, now support: - hosts: a string with allowed hosts (wild card supported, e.g.: *.example.com) {@see setHosts} - action: a string with action for unallowed host {@see validActions} - action_options: array with some options for action {@see setAction} - logging: bool, set true if need logging unallowed host {@see setLogging} - active: bool, set true if automatic checking on every request needed

public setProperties(array<string|int, mixed> $properties) : $this
Parameters
$properties : array<string|int, mixed>

See above.

Tags
throws
ArgumentOutOfRangeException
throws
ArgumentTypeException
throws
ArgumentNullException
throws
LogicException
Return values
$this

        
On this page

Search results