Documentation

Filesystem extends AbstractData
in package

Filesystem

Model for filesystem data access, implemented as a singleton.

Table of Contents

Constants

HTACCESS_LINE  = 'Require all denied'
line in generated .htaccess files, to protect exposed directories from being browsable on apache web servers
PASTE_FILE_PATTERN  = DIRECTORY_SEPARATOR . '[a-f0-9][a-f0-9]' . DIRECTORY_SEPARATOR . '[a-f0-9][a-f0-9]' . DIRECTORY_SEPARATOR . '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]' . '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*'
glob() pattern of the two folder levels and the paste files under the configured path. Needs to return both files with and without .php suffix, so they can be hardened by _prependRename(), which is hooked into exists().
PROTECTION_LINE  = '<?php http_response_code(403); /*'
first line in paste or comment files, to protect their contents from browsing exposed data directories

Properties

$_last_cache  : array<string|int, mixed>
cache for the traffic limiter
$_path  : string
path in which to persist something

Methods

__construct()  : mixed
instantiates a new Filesystem data backend
create()  : bool
Create a paste.
createComment()  : bool
Create a comment in a paste.
delete()  : mixed
Delete a paste and its discussion.
exists()  : bool
Test if a paste exists.
existsComment()  : bool
Test if a comment exists.
getAllPastes()  : array<string|int, mixed>
Returns all paste ids
getValue()  : string
Load a value.
purge()  : mixed
Perform a purge of old pastes, at most the given batchsize is deleted.
purgeValues()  : void
Purge outdated entries.
read()  : array<string|int, mixed>|false
Read a paste.
readComments()  : array<string|int, mixed>
Read all comments of paste.
setValue()  : bool
Save a value.
_getExpiredPastes()  : array<string|int, mixed>
Returns up to batch size number of paste ids that have expired
getOpenSlot()  : int|string
Get next free slot for comment from postdate.
upgradePreV1Format()  : array<string|int, mixed>
Upgrade pre-version 1 pastes with attachment to version 1 format.
_dataid2discussionpath()  : string
Convert paste id to discussion storage path.
_dataid2path()  : string
Convert paste id to storage path.
_get()  : array<string|int, mixed>|false
get the data
_prependRename()  : void
rename a file, prepending the protection line at the beginning
_store()  : bool
store the data
_storeString()  : bool
store a string

Constants

HTACCESS_LINE

line in generated .htaccess files, to protect exposed directories from being browsable on apache web servers

public mixed HTACCESS_LINE = 'Require all denied'
Tags
const

string

PASTE_FILE_PATTERN

glob() pattern of the two folder levels and the paste files under the configured path. Needs to return both files with and without .php suffix, so they can be hardened by _prependRename(), which is hooked into exists().

public mixed PASTE_FILE_PATTERN = DIRECTORY_SEPARATOR . '[a-f0-9][a-f0-9]' . DIRECTORY_SEPARATOR . '[a-f0-9][a-f0-9]' . DIRECTORY_SEPARATOR . '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]' . '[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]*'

Note that wildcard patterns are not regular expressions, although they are a bit similar.

Tags
link
https://man7.org/linux/man-pages/man7/glob.7.html
const

string

PROTECTION_LINE

first line in paste or comment files, to protect their contents from browsing exposed data directories

public mixed PROTECTION_LINE = '<?php http_response_code(403); /*'
Tags
const

string

Properties

$_last_cache

cache for the traffic limiter

protected array<string|int, mixed> $_last_cache = array()
Tags
access

protected

$_path

path in which to persist something

private string $_path = 'data'
Tags
access

private

Methods

__construct()

instantiates a new Filesystem data backend

public __construct(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>
Tags
access

public

create()

Create a paste.

public create(string $pasteid, array<string|int, mixed> $paste) : bool
Parameters
$pasteid : string
$paste : array<string|int, mixed>
Tags
access

public

Return values
bool

createComment()

Create a comment in a paste.

public createComment(string $pasteid, string $parentid, string $commentid, array<string|int, mixed> $comment) : bool
Parameters
$pasteid : string
$parentid : string
$commentid : string
$comment : array<string|int, mixed>
Tags
access

public

Return values
bool

delete()

Delete a paste and its discussion.

public delete(string $pasteid) : mixed
Parameters
$pasteid : string
Tags
access

public

exists()

Test if a paste exists.

public exists(string $pasteid) : bool
Parameters
$pasteid : string
Tags
access

public

Return values
bool

existsComment()

Test if a comment exists.

public existsComment(string $pasteid, string $parentid, string $commentid) : bool
Parameters
$pasteid : string
$parentid : string
$commentid : string
Tags
access

public

Return values
bool

getAllPastes()

Returns all paste ids

public getAllPastes() : array<string|int, mixed>
Tags
inheritDoc
Return values
array<string|int, mixed>

getValue()

Load a value.

public getValue(string $namespace[, string $key = '' ]) : string
Parameters
$namespace : string
$key : string = ''
Tags
access

public

Return values
string

purge()

Perform a purge of old pastes, at most the given batchsize is deleted.

public purge(int $batchsize) : mixed
Parameters
$batchsize : int
Tags
access

public

purgeValues()

Purge outdated entries.

public purgeValues(string $namespace, int $time) : void
Parameters
$namespace : string
$time : int
Tags
access

public

read()

Read a paste.

public read(string $pasteid) : array<string|int, mixed>|false
Parameters
$pasteid : string
Tags
access

public

Return values
array<string|int, mixed>|false

readComments()

Read all comments of paste.

public readComments(string $pasteid) : array<string|int, mixed>
Parameters
$pasteid : string
Tags
access

public

Return values
array<string|int, mixed>

setValue()

Save a value.

public setValue(string $value, string $namespace[, string $key = '' ]) : bool
Parameters
$value : string
$namespace : string
$key : string = ''
Tags
access

public

Return values
bool

_getExpiredPastes()

Returns up to batch size number of paste ids that have expired

protected _getExpiredPastes(int $batchsize) : array<string|int, mixed>
Parameters
$batchsize : int
Tags
access

private

Return values
array<string|int, mixed>

getOpenSlot()

Get next free slot for comment from postdate.

protected getOpenSlot(array<string|int, mixed> &$comments, int|string $postdate) : int|string
Parameters
$comments : array<string|int, mixed>
$postdate : int|string
Tags
access

protected

Return values
int|string

upgradePreV1Format()

Upgrade pre-version 1 pastes with attachment to version 1 format.

protected static upgradePreV1Format(array<string|int, mixed> $paste) : array<string|int, mixed>
Parameters
$paste : array<string|int, mixed>
Tags
access

protected

static
Return values
array<string|int, mixed>

_dataid2discussionpath()

Convert paste id to discussion storage path.

private _dataid2discussionpath(string $dataid) : string

eg. input 'e3570978f9e4aa90' --> output 'data/e3/57/e3570978f9e4aa90.discussion/'

Parameters
$dataid : string
Tags
access

private

Return values
string

_dataid2path()

Convert paste id to storage path.

private _dataid2path(string $dataid) : string

The idea is to creates subdirectories in order to limit the number of files per directory. (A high number of files in a single directory can slow things down.) eg. "f468483c313401e8" will be stored in "data/f4/68/f468483c313401e8" High-trafic websites may want to deepen the directory structure (like Squid does).

eg. input 'e3570978f9e4aa90' --> output 'data/e3/57/'

Parameters
$dataid : string
Tags
access

private

Return values
string

_get()

get the data

private _get(string $filename) : array<string|int, mixed>|false
Parameters
$filename : string
Tags
access

public

Return values
array<string|int, mixed>|false

$data

_prependRename()

rename a file, prepending the protection line at the beginning

private _prependRename(string $srcFile, string $destFile) : void
Parameters
$srcFile : string
$destFile : string
Tags
access

public

_store()

store the data

private _store(string $filename, array<string|int, mixed> $data) : bool
Parameters
$filename : string
$data : array<string|int, mixed>
Tags
access

public

Return values
bool

_storeString()

store a string

private _storeString(string $filename, string $data) : bool
Parameters
$filename : string
$data : string
Tags
access

public

Return values
bool

        
On this page

Search results