An open API service indexing awesome lists of open source software.

https://github.com/bitsensor/php

BitSensor Web Application Security
https://github.com/bitsensor/php

bitsensor php security

Last synced: about 1 month ago
JSON representation

BitSensor Web Application Security

Awesome Lists containing this project

README

          

![logo](https://dl2.pushbulletusercontent.com/3WwxLx0wKhfLB4sMWZ2QjLqFzwT5nwWD/Logo_BitSensorSmall_Light.png)

# BitSensor PHP Plugin

The BitSensor PHP plugin.

[BitSensor](https://bitsensor.io/)

[Documentation](https://plugins.bitsensor.io/php)

[Gitlab repo](https://git.bitsensor.io/plugins/php)

## Setup BitSensor

### Requirements
* `php >= 5.6.0`
* `composer`
* `uopz` [optional, for query tracing]

## Installation
```bash
composer require bitsensor/php
```

## Configuration

### Code
```php
| IP address manual override value. |
| ```setHostSrc()``` | hostSrc | ```Config::HOST_SERVER_NAME``` ("serverName"), ```Config::HOST_HOST_HEADER``` ("hostHeader"), ```Config::HOST_MANUAL``` ("manual") | ```Config::HOST_SERVER_NAME``` ("serverName") | Source of the hostname. |
| ```setHost()``` | host | host address override | | Hostname manual override value. |
| ```setLogLevel()``` | logLevel | ```Config::LOG_LEVEL_ALL``` ("all"), ```Config::LOG_LEVEL_NONE``` ("none") | ```Config::LOG_LEVEL_ALL``` ("all") | The logging level. |
| ```setOutputFlushing``` | outputFlushing | ```Config::OUTPUT_FLUSHING_ON``` ("on"), ```Config::OUTPUT_FLUSHING_OFF``` ("off") | ```Config::OUTPUT_FLUSHING_OFF``` ("off") | Output flushing. Turning this on allows the browser to render the page while BitSensor is still working in the background. |
| ```setUopzHook``` | uopzHook | ```Config::UOPZ_HOOK_ON``` ("on"), ```Config::UOPZ_HOOK_OFF``` ("off") | ```Config::UOPZ_HOOK_ON``` ("on") | Uopz Hooking. Turning this on enables BitSensor to hook into function calls. |
| ```setFastcgiFinishRequest``` | executeFastCgi | ```Config::EXECUTE_FASTCGI_FINISH_REQUEST_ON``` ("on"), ```Config::EXECUTE_FASTCGI_FINISH_REQUEST_OFF``` ("off") | ```Config::EXECUTE_FASTCGI_FINISH_REQUEST_OFF``` ("off")| Finish request to your FastCGI webserver, while processing BitSensor in a separate thread. |

### Connector Types

#### Api
| PHP | JSON | Value | Default | Description |
|-------------------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| ```setUser()``` | user | username | | Your BitSensor username. |
| ```setApiKey()``` | apikey | api key | | Your BitSensor API key. |
| ```setHost()``` | host | hostname | {user}.bitsensor.io | Hostname of the BitSensor endpoint. |
| ```setPort()``` | port | port | 8080 | Port of the BitSensor endpoint. |

#### File
| PHP | JSON | Value | Default | Description |
|---------------------|----------|------------------|---------------------------------------|--------------|
| ```setFilename()``` | filename | File to write to | /var/log/bitsensor-datapoints-php.log | Logfile that is appended to. Make sure that the Apache or Nginx user can write to this file. Set this using `touch /var/log/bitsensor-datapoints-php.log; chown www-data /var/log/bitsensor-datapoints-php.log; chmod 200 /var/log/bitsensor-datapoints-php.log` |

### Blocking Actions
#### Blockingpage
| PHP | JSON | Value | Default | Description |
|-------------------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| ```setUser()``` | user | username | | Your BitSensor username. |
| ```setHost()``` | host | hostname | {user}.bitsensor.io | Hostname of the BitSensor endpoint. |
| ```setPort()``` | port | port | 2080 | Port of the BitSensor endpoint. |

## Query tracing

To use PDO and MySQLi query tracing, the [uopz](https://github.com/krakjoe/uopz) pecl extension must be installed.

```bash
# You might have to install `pecl` and php-dev dependencies
sudo apt-get install php-pear php-dev

pecl install uopz

# You might have to add `extension=uopz.so` to your php.ini, if that does not happen automatically
echo 'extension=uopz.so' >> /etc/php/7.0/fpm/php.ini

# In case of php-fpm, reload the service
service php7.0-fpm reload

# Check successful installation, the output should be `1`
php -r 'echo extension_loaded("uopz");'
```

## Logging

### Monolog
```php
pushHandler(new PsrHandler(new PsrLogHandler()));
```

### Tags
If you are running many applications, it might be sensible to group them by a tag. You can create a tag using the following snippet:
```php