1<?php
2
3namespace dokuwiki\plugin\captcha;
4
5/**
6 * A simple mechanism to count login failures for IP addresses
7 */
8class IpCounter
9{
10    protected $ip;
11    protected $store;
12
13    /**
14     * Initialize the counter
15     */
16    public function __construct()
17    {
18        $this->ip = clientIP(true);
19        $this->store = getCacheName($this->ip, '.captchaip');
20    }
21
22    /**
23     * Increases the counter by adding a byte
24     *
25     * @return void
26     */
27    public function increment()
28    {
29        io_saveFile($this->store, '1', true);
30    }
31
32    /**
33     * Return the current counter
34     *
35     * @return int
36     */
37    public function get()
38    {
39        return (int)@filesize($this->store);
40    }
41
42    /**
43     * Reset the counter to zero
44     *
45     * @return void
46     */
47    public function reset()
48    {
49        @unlink($this->store);
50    }
51}
52