Skip to content

Commit 5c878f8

Browse files
committed
Update
1 parent e51e43f commit 5c878f8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/JSONDB/JSONDB.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,17 @@ protected static function &getInstance()
273273

274274
/**
275275
* Creates a new server.
276-
* @param string $path The server's path
276+
* @param string $name The server's path
277277
* @param string $username The server's username
278278
* @param string $password The server's user password
279279
* @param bool $connect If JSONDB connects directly to the server after creation
280280
* @return JSONDB
281281
* @throws Exception
282282
*/
283-
public function createServer($path, $username, $password, $connect = FALSE)
283+
public function createServer($name, $username, $password, $connect = FALSE)
284284
{
285285
$this->benchmark->mark('jsondb_(createServer)_start');
286+
$path = dirname(dirname(__DIR__)) . '/servers/' . $name;
286287
if (isset($path, $username, $password)) {
287288
if (file_exists($path) || is_dir($path)) {
288289
$this->benchmark->mark('jsondb_(createServer)_end');
@@ -297,16 +298,23 @@ public function createServer($path, $username, $password, $connect = FALSE)
297298
chmod($path, 0777);
298299

299300
$htaccess = fopen($path . '/.htaccess', 'a+');
300-
foreach(array('AuthType Basic', 'AuthName "JSONDB Server Access"', 'AuthUserFile "' . realpath(dirname(__DIR__) . '/config/.htpasswd') . '"', 'Require user ' . $username) as $line) {
301+
foreach(array('<IfModule mod_rewrite.c>',
302+
'RewriteEngine On',
303+
'RewriteRule ^index\.php$ - [L]',
304+
'RewriteRule . - [f]',
305+
'</IfModule>') as $line) {
301306
fwrite($htaccess, $line . "\n");
302307
}
303308
fclose($htaccess);
304309

310+
$indexphp = fopen($path . '/index.php', 'a+');
311+
fwrite($indexphp, 'Direct Access Denied.');
312+
fclose($indexphp);
305313

306-
$this->config->addUser(realpath($path), $username, $password);
314+
$this->config->addUser($name, $username, $password);
307315

308316
if ($connect) {
309-
$this->connect($path, $username, $password);
317+
$this->connect($name, $username, $password);
310318
}
311319
}
312320
$this->benchmark->mark('jsondb_(createServer)_end');
@@ -371,14 +379,15 @@ public function connect($server, $username, $password, $database = NULL)
371379

372380
if (!array_key_exists($server, $config)) {
373381
$this->benchmark->mark('jsondb_(connect)_end');
374-
throw new Exception("JSONDB Error: There is no registered server with the path \"{$server}\".");
382+
throw new Exception("JSONDB Error: There is no registered server with the name \"{$server}\".");
375383
}
376384

377385
if ($config[$server]['username'] !== Util::crypt($username) || $config[$server]['password'] !== Util::crypt($password)) {
378386
$this->benchmark->mark('jsondb_(connect)_end');
379387
throw new Exception("JSONDB Error: User's authentication failed for user \"{$username}\" on server \"{$server}\". Access denied.");
380388
}
381389

390+
$this->server = realpath(dirname(dirname(__DIR__)) . '/servers/' . $server);
382391
$this->database = $database;
383392
$this->username = $username;
384393
$this->password = $password;

0 commit comments

Comments
 (0)