diff --git a/api/add-domain.php b/api/add-domain.php index 750f12f..77b85e7 100644 --- a/api/add-domain.php +++ b/api/add-domain.php @@ -35,15 +35,15 @@ if(!isset($_SESSION['type']) || $_SESSION['type'] != "admin") { if(isset($input->action) && $input->action == "addDomain") { $soaData = Array(); - $soaData[] = trim($input->primary); - $soaData[] = trim(mail_to_soa($input->mail)); + $soaData[] = strtolower(preg_replace('/\s+/', '', $input->primary)); + $soaData[] = strtolower(mail_to_soa(preg_replace('/\s+/', '', $input->mail))); $soaData[] = date("Ymd") . "00"; $soaData[] = $input->refresh; $soaData[] = $input->retry; $soaData[] = $input->expire; $soaData[] = $input->ttl; - $domainsName = trim($input->name); + $domainsName = strtolower(preg_replace('/\s+/', '', $input->name)); $soaContent = implode(" ", $soaData); diff --git a/api/domains.php b/api/domains.php index 26943be..f54e3e1 100644 --- a/api/domains.php +++ b/api/domains.php @@ -40,7 +40,7 @@ if(isset($input->action) && $input->action == "getDomains") { FROM domains D LEFT OUTER JOIN permissions P ON D.id = P.domain WHERE (P.user=:user1 OR :user2) AND - (D.name LIKE :name1 OR name2) AND + (D.name LIKE :name1 OR :name2) AND (D.type=:type1 OR :type2) "; @@ -74,6 +74,10 @@ if(isset($input->action) && $input->action == "getDomains") { $stmt->execute(); $result = $stmt->fetchColumn(); + if ($result == 0) { + $result = 1; + } + // Initialize the return value $retval = Array(); diff --git a/api/edit-master.php b/api/edit-master.php index ac1db4a..64b60b8 100644 --- a/api/edit-master.php +++ b/api/edit-master.php @@ -142,7 +142,7 @@ if(isset($input->action) && $input->action == "getSoa") { $retval = Array(); - $retval['primary'] = preg_replace('/\\.$/', "", $content[0]); + $retval['primary'] = $content[0]; $retval['email'] = soa_to_mail($content[1]); $retval['serial'] = $content[2]; $retval['refresh'] = $content[3]; @@ -184,8 +184,8 @@ if(isset($input->action) && $input->action == "saveSoa") { $content = explode(" ", $content); $serial = $content[2]; - $newsoa = trim($input->primary) . " "; - $newsoa .= trim(mail_to_soa($input->email)) . " "; + $newsoa = strtolower(preg_replace('/\s+/', '', $input->primary)) . " "; + $newsoa .= strtolower(mail_to_soa(preg_replace('/\s+/', '', $input->email))) . " "; $newsoa .= $serial . " "; $newsoa .= $input->refresh . " "; $newsoa .= $input->retry . " "; @@ -208,7 +208,7 @@ if(isset($input->action) && $input->action == "saveSoa") { //Action for saving Record if(isset($input->action) && $input->action == "saveRecord") { $domainId = $input->domain; - $recordName = trim($input->name); + $recordName = strtolower(preg_replace('/\s+/', '', $input->name)); $recordContent = trim($input->content); $stmt = $db->prepare("UPDATE records SET name=:name,type=:type,content=:content,ttl=:ttl,prio=:prio WHERE id=:id AND domain_id=:domain_id"); @@ -226,7 +226,7 @@ if(isset($input->action) && $input->action == "saveRecord") { //Action for adding Record if(isset($input->action) && $input->action == "addRecord") { $domainId = $input->domain; - $recordName = trim($input->name); + $recordName = strtolower(preg_replace('/\s+/', '', $input->name)); $recordContent = trim($input->content); $db->beginTransaction(); diff --git a/api/index.php b/api/index.php index 36dea56..d460dc0 100644 --- a/api/index.php +++ b/api/index.php @@ -21,9 +21,9 @@ require_once '../lib/database.php'; $input = json_decode(file_get_contents('php://input')); -$sql = $db->prepare("SELECT id,password,type FROM user WHERE name=:name LIMIT 1"); +$stmt = $db->prepare("SELECT id,password,type FROM user WHERE name=:name LIMIT 1"); $stmt->bindValue(':name', $input->user, PDO::PARAM_STR); -$sql->execute(); +$stmt->execute(); $stmt->bindColumn('id', $id); $stmt->bindColumn('password', $password); $stmt->bindColumn('type', $type); diff --git a/api/install.php b/api/install.php index 9d17d95..f6445d9 100644 --- a/api/install.php +++ b/api/install.php @@ -295,7 +295,7 @@ try { } catch (PDOException $e) { $retval['status'] = "error"; - $retval['message'] = $e; + $retval['message'] = serialize($e); } if (!isset($retval)) { $passwordHash = password_hash($input->userPassword, PASSWORD_DEFAULT); @@ -316,11 +316,17 @@ if (!isset($retval)) { $configFile[] = '$config[\'db_password\'] = \'' . addslashes($input->password) . "';"; $configFile[] = '$config[\'db_name\'] = \'' . addslashes($input->database) . "';"; $configFile[] = '$config[\'db_port\'] = ' . addslashes($input->port) . ";"; - $configFile[] = '$config[\'db_type\'] = ' . addslashes($input->type) . ";"; - - file_put_contents("../config/config-user.php", implode("\n", $configFile)); - - $retval['status'] = "success"; + $configFile[] = '$config[\'db_type\'] = \'' . addslashes($input->type) . "';"; + + try { + file_put_contents("../config/config-user.php", implode("\n", $configFile)); + $retval['status'] = "success"; + } + catch (Exception $e) { + $retval['status'] = "error"; + $retval['message'] = serialize($e); + } + } if(isset($retval)) { diff --git a/api/upgrade.php b/api/upgrade.php index 31b2be2..19d57fc 100644 --- a/api/upgrade.php +++ b/api/upgrade.php @@ -29,7 +29,7 @@ if(isset($input->action) && $input->action == "getVersions") { if(isset($input->action) && $input->action == "requestUpgrade") { $currentVersion = getVersion($db); - + $dbType = $config['db_type']; if($currentVersion < 1) { $sql["mysql"] = " CREATE TABLE IF NOT EXISTS remote ( @@ -54,8 +54,8 @@ if(isset($input->action) && $input->action == "requestUpgrade") { INSERT INTO options(name,value) VALUES ('schema_version', 1); "; - $sql["pgsql"] = ""; - $stmt = $db->query($sql[$config['db_type']]); + $sql["pgsql"] = "INSERT INTO options(name,value) VALUES ('schema_version', 1);"; + $stmt = $db->query($sql[$dbType]); while ($stmt->nextRowset()) {;} } if($currentVersion < 2) { @@ -79,13 +79,13 @@ if(isset($input->action) && $input->action == "requestUpgrade") { UPDATE options SET value=2 WHERE name='schema_version'; "; - $sql["pgsql"] = ""; - $stmt = $db->query($sql[$config['db_type']]); + $sql["pgsql"] = "UPDATE options SET value=2 WHERE name='schema_version';"; + $stmt = $db->query($sql[$dbType]); while ($stmt->nextRowset()) {;} } if($currentVersion < 3) { $sql["mysql"] = " - CREATE TABLE domainmetadata ( + CREATE TABLE IF NOT EXISTS domainmetadata ( id INT AUTO_INCREMENT, domain_id INT NOT NULL, kind VARCHAR(32), @@ -98,9 +98,10 @@ if(isset($input->action) && $input->action == "requestUpgrade") { UPDATE options SET value=3 WHERE name='schema_version'; "; - $sql["pgsql"] = ""; - $stmt = $db->query($sql[$config['db_type']]); + $sql["pgsql"] = "UPDATE options SET value=3 WHERE name='schema_version';"; + $stmt = $db->query($sql[$dbType]); while ($stmt->nextRowset()) {;} + } if($currentVersion < 4) { $sql["mysql"] = " @@ -147,8 +148,8 @@ if(isset($input->action) && $input->action == "requestUpgrade") { UPDATE options SET value=4 WHERE name='schema_version'; "; - $sql["pgsql"] = ""; - $stmt = $db->query($sql[$config['db_type']]); + $sql["pgsql"] = "UPDATE options SET value=4 WHERE name='schema_version';"; + $stmt = $db->query($sql[$dbType]); while ($stmt->nextRowset()) {;} } $retval['status'] = "success"; diff --git a/config/config-default.php b/config/config-default.php index 2617756..e4f0d57 100644 --- a/config/config-default.php +++ b/config/config-default.php @@ -24,12 +24,6 @@ $config['db_password'] = ""; $config['db_port'] = 3306; $config['db_name'] = "pdnsmanager"; -//HTTP API Settings -$config['api_functionality'] = true; -$config['api_host'] = "localhost" -$config['api_port'] = 8080; -$config['api_key'] = ""; - //Remote update $config['nonce_lifetime'] = 15; diff --git a/domains.php b/domains.php index fd60f6a..a4e256c 100644 --- a/domains.php +++ b/domains.php @@ -73,6 +73,8 @@ limitations under the License. @@ -92,8 +94,9 @@ limitations under the License. '; - echo 'Add MASTER'; - echo 'Add NATIVE'; + echo 'Add NATIVE'; + echo 'Add MASTER'; + echo 'Add SLAVE'; echo ''; } ?> diff --git a/edit-master.php b/edit-master.php index 4107ee6..1780b02 100644 --- a/edit-master.php +++ b/edit-master.php @@ -70,7 +70,7 @@ limitations under the License.
- +
diff --git a/install.php b/install.php index 3b7ce3c..263b525 100644 --- a/install.php +++ b/install.php @@ -66,11 +66,10 @@ limitations under the License.

Database

- -
diff --git a/js/install.js b/js/install.js index ce440b7..3351d95 100644 --- a/js/install.js +++ b/js/install.js @@ -52,7 +52,7 @@ function checkSettings() { port: $('#dbPort').val(), userName: $('#adminName').val(), userPassword: $('#adminPassword').val(), - type: $('#dbType').val() + type: $('#dbType').val() }; $.post( diff --git a/lib/checkversion.php b/lib/checkversion.php index c96d5dd..5332d8b 100644 --- a/lib/checkversion.php +++ b/lib/checkversion.php @@ -30,13 +30,11 @@ function checkVersion($db) { function getVersion($db) { - try { - $stmt = $db->prepare("SELECT value FROM options WHERE name='schema_version' LIMIT 1"); - $stmt->execute(); - $version = $stmt->fetchColumn(); - } catch (Exception $e) { - return 0; + $stmt = $db->prepare("SELECT value FROM options WHERE name='schema_version' LIMIT 1"); + $stmt->execute(); + $version = $stmt->fetchColumn(); + if (!$version) { + $version = 0; } - return $version; } \ No newline at end of file diff --git a/lib/database.php b/lib/database.php index c741421..9019270 100644 --- a/lib/database.php +++ b/lib/database.php @@ -17,7 +17,7 @@ */ try { - $db = new PDO("$config['db_type']:dbname=$config['db_name'];host=$config['db_host'];port=$config['db_port']", $config['db_user'], $config['db_password']); + $db = new PDO($config['db_type'].":dbname=".$config['db_name'].";host=".$config['db_host'].";port=".strval($config['db_port']), $config['db_user'], $config['db_password']); } catch (PDOException $e) { die("Connection to database failed");