Reduce code duplication

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-04-26 17:58:27 +02:00
parent cedc59ba78
commit 8b0ee8f4fa
4 changed files with 29 additions and 99 deletions

View File

@@ -8,6 +8,7 @@
$api = true;
header('Content-type: application/json');
require("scripts/pi-hole/php/database.php");
require("scripts/pi-hole/php/password.php");
require("scripts/pi-hole/php/auth.php");
check_cors();
@@ -62,37 +63,7 @@ else
// Needs package php5-sqlite, e.g.
// sudo apt-get install php5-sqlite
function SQLite3_connect($trytoreconnect)
{
global $DBFILE;
try
{
// connect to database
return new SQLite3($DBFILE, SQLITE3_OPEN_READONLY);
}
catch (Exception $exception)
{
// sqlite3 throws an exception when it is unable to connect, try to reconnect after 3 seconds
if($trytoreconnect)
{
sleep(3);
$db = SQLite3_connect(false);
}
}
}
if(strlen($DBFILE) > 0)
{
$db = SQLite3_connect(true);
}
else
{
die("No database available");
}
if(!$db)
{
die("Error connecting to database");
}
$db = SQLite3_connect($DBFILE);
if(isset($_GET["network"]) && $auth)
{