public function __construct(HereAuth $main) { $this->main = $main; $this->path = $main->getConfig()->getNested("Database.JSON.DataFolder", "accounts"); if ($this->path[0] !== "/") { $this->path = $main->getDataFolder() . $this->path; } if (!is_dir($this->path)) { mkdir($this->path, 0777, true); } if (!is_dir($this->path)) { throw new \RuntimeException("Could not create data directory at {$this->path}"); } $this->path = realpath($this->path) . "/"; $this->indexEnabled = $main->getConfig()->getNested("Database.JSON.EnableLeadingIndex", false); if (is_file($hadb = $this->path . ".hadb")) { $data = json_decode(file_get_contents($hadb), true); } else { $data = ["#" => "This is a HereAuth JSON-based account database.", "created" => time(), "lastClosed" => time()]; } $data["lastOpened"] = time(); $data["version"] = $this->main->getDescription()->getVersion(); file_put_contents($hadb, json_encode($data, JSON_PRETTY_PRINT | JSON_BIGINT_AS_STRING | JSON_UNESCAPED_SLASHES)); $this->sql = new SQLite3($this->path . "reg.db"); $this->sql->exec("CREATE TABLE IF NOT EXISTS reg (ip TEXT, name TEXT PRIMARY KEY, time INTEGER)"); var_dump($this->sql->busyTimeout(1)); // outputs bool(true) }
public function __construct(HereAuth $main) { $dir = rtrim($main->getConfig()->getNested("AuditLogger.LogFolder", "audit"), "/") . "/"; if ($dir[0] !== "/" and strpos($dir, "://") === false) { $dir = $main->getDataFolder() . $dir; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } foreach ($entries = ["register", "login", "push", "bump", "invalid", "timeout", "factor"] as $entry) { $value = $main->getConfig()->getNested("AuditLogger.Log." . ucfirst($entry), ($isWin = Utils::getOS() === "win") ? "/NUL" : "/dev/null"); if ($value === "/NUL" and !$isWin or $value === "/dev/null" and $isWin) { $main->getLogger()->warning("Your OS is " . ($isWin ? "Windows" : "not Windows") . ", where {$value} is not a special file! HereAuth will attempt to create that file!"); } if ($value[0] !== "/") { $value = $dir . $value; } $this->{$entry} = $stream = $this->getStream($value); // fwrite($stream, date(self::DATE_FORMAT) . " Start logging $entry\n"); } }