Bugs
Fixed a few code bugs. Added text to strip whitespace from records (i.e. name, master, email)
This commit is contained in:
parent
5d5f8c4af7
commit
47f3f9939e
|
@ -35,15 +35,15 @@ if(!isset($_SESSION['type']) || $_SESSION['type'] != "admin") {
|
||||||
|
|
||||||
if(isset($input->action) && $input->action == "addDomain") {
|
if(isset($input->action) && $input->action == "addDomain") {
|
||||||
$soaData = Array();
|
$soaData = Array();
|
||||||
$soaData[] = trim($input->primary);
|
$soaData[] = strtolower(preg_replace('/\s+/', '', $input->primary));
|
||||||
$soaData[] = trim(mail_to_soa($input->mail));
|
$soaData[] = strtolower(mail_to_soa(preg_replace('/\s+/', '', $input->mail)));
|
||||||
$soaData[] = date("Ymd") . "00";
|
$soaData[] = date("Ymd") . "00";
|
||||||
$soaData[] = $input->refresh;
|
$soaData[] = $input->refresh;
|
||||||
$soaData[] = $input->retry;
|
$soaData[] = $input->retry;
|
||||||
$soaData[] = $input->expire;
|
$soaData[] = $input->expire;
|
||||||
$soaData[] = $input->ttl;
|
$soaData[] = $input->ttl;
|
||||||
|
|
||||||
$domainsName = trim($input->name);
|
$domainsName = strtolower(preg_replace('/\s+/', '', $input->name));
|
||||||
|
|
||||||
$soaContent = implode(" ", $soaData);
|
$soaContent = implode(" ", $soaData);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ if(isset($input->action) && $input->action == "getDomains") {
|
||||||
FROM domains D
|
FROM domains D
|
||||||
LEFT OUTER JOIN permissions P ON D.id = P.domain
|
LEFT OUTER JOIN permissions P ON D.id = P.domain
|
||||||
WHERE (P.user=:user1 OR :user2) AND
|
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)
|
(D.type=:type1 OR :type2)
|
||||||
";
|
";
|
||||||
|
|
||||||
|
@ -74,6 +74,10 @@ if(isset($input->action) && $input->action == "getDomains") {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$result = $stmt->fetchColumn();
|
$result = $stmt->fetchColumn();
|
||||||
|
|
||||||
|
if ($result == 0) {
|
||||||
|
$result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the return value
|
// Initialize the return value
|
||||||
$retval = Array();
|
$retval = Array();
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ if(isset($input->action) && $input->action == "getSoa") {
|
||||||
|
|
||||||
$retval = Array();
|
$retval = Array();
|
||||||
|
|
||||||
$retval['primary'] = preg_replace('/\\.$/', "", $content[0]);
|
$retval['primary'] = $content[0];
|
||||||
$retval['email'] = soa_to_mail($content[1]);
|
$retval['email'] = soa_to_mail($content[1]);
|
||||||
$retval['serial'] = $content[2];
|
$retval['serial'] = $content[2];
|
||||||
$retval['refresh'] = $content[3];
|
$retval['refresh'] = $content[3];
|
||||||
|
@ -184,8 +184,8 @@ if(isset($input->action) && $input->action == "saveSoa") {
|
||||||
$content = explode(" ", $content);
|
$content = explode(" ", $content);
|
||||||
$serial = $content[2];
|
$serial = $content[2];
|
||||||
|
|
||||||
$newsoa = trim($input->primary) . " ";
|
$newsoa = strtolower(preg_replace('/\s+/', '', $input->primary)) . " ";
|
||||||
$newsoa .= trim(mail_to_soa($input->email)) . " ";
|
$newsoa .= strtolower(mail_to_soa(preg_replace('/\s+/', '', $input->email))) . " ";
|
||||||
$newsoa .= $serial . " ";
|
$newsoa .= $serial . " ";
|
||||||
$newsoa .= $input->refresh . " ";
|
$newsoa .= $input->refresh . " ";
|
||||||
$newsoa .= $input->retry . " ";
|
$newsoa .= $input->retry . " ";
|
||||||
|
@ -208,7 +208,7 @@ if(isset($input->action) && $input->action == "saveSoa") {
|
||||||
//Action for saving Record
|
//Action for saving Record
|
||||||
if(isset($input->action) && $input->action == "saveRecord") {
|
if(isset($input->action) && $input->action == "saveRecord") {
|
||||||
$domainId = $input->domain;
|
$domainId = $input->domain;
|
||||||
$recordName = trim($input->name);
|
$recordName = strtolower(preg_replace('/\s+/', '', $input->name));
|
||||||
$recordContent = trim($input->content);
|
$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");
|
$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
|
//Action for adding Record
|
||||||
if(isset($input->action) && $input->action == "addRecord") {
|
if(isset($input->action) && $input->action == "addRecord") {
|
||||||
$domainId = $input->domain;
|
$domainId = $input->domain;
|
||||||
$recordName = trim($input->name);
|
$recordName = strtolower(preg_replace('/\s+/', '', $input->name));
|
||||||
$recordContent = trim($input->content);
|
$recordContent = trim($input->content);
|
||||||
|
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
|
|
|
@ -21,9 +21,9 @@ require_once '../lib/database.php';
|
||||||
|
|
||||||
$input = json_decode(file_get_contents('php://input'));
|
$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);
|
$stmt->bindValue(':name', $input->user, PDO::PARAM_STR);
|
||||||
$sql->execute();
|
$stmt->execute();
|
||||||
$stmt->bindColumn('id', $id);
|
$stmt->bindColumn('id', $id);
|
||||||
$stmt->bindColumn('password', $password);
|
$stmt->bindColumn('password', $password);
|
||||||
$stmt->bindColumn('type', $type);
|
$stmt->bindColumn('type', $type);
|
||||||
|
|
|
@ -295,7 +295,7 @@ try {
|
||||||
}
|
}
|
||||||
catch (PDOException $e) {
|
catch (PDOException $e) {
|
||||||
$retval['status'] = "error";
|
$retval['status'] = "error";
|
||||||
$retval['message'] = $e;
|
$retval['message'] = serialize($e);
|
||||||
}
|
}
|
||||||
if (!isset($retval)) {
|
if (!isset($retval)) {
|
||||||
$passwordHash = password_hash($input->userPassword, PASSWORD_DEFAULT);
|
$passwordHash = password_hash($input->userPassword, PASSWORD_DEFAULT);
|
||||||
|
@ -316,11 +316,17 @@ if (!isset($retval)) {
|
||||||
$configFile[] = '$config[\'db_password\'] = \'' . addslashes($input->password) . "';";
|
$configFile[] = '$config[\'db_password\'] = \'' . addslashes($input->password) . "';";
|
||||||
$configFile[] = '$config[\'db_name\'] = \'' . addslashes($input->database) . "';";
|
$configFile[] = '$config[\'db_name\'] = \'' . addslashes($input->database) . "';";
|
||||||
$configFile[] = '$config[\'db_port\'] = ' . addslashes($input->port) . ";";
|
$configFile[] = '$config[\'db_port\'] = ' . addslashes($input->port) . ";";
|
||||||
$configFile[] = '$config[\'db_type\'] = ' . addslashes($input->type) . ";";
|
$configFile[] = '$config[\'db_type\'] = \'' . addslashes($input->type) . "';";
|
||||||
|
|
||||||
file_put_contents("../config/config-user.php", implode("\n", $configFile));
|
try {
|
||||||
|
file_put_contents("../config/config-user.php", implode("\n", $configFile));
|
||||||
$retval['status'] = "success";
|
$retval['status'] = "success";
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$retval['status'] = "error";
|
||||||
|
$retval['message'] = serialize($e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($retval)) {
|
if(isset($retval)) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ if(isset($input->action) && $input->action == "getVersions") {
|
||||||
|
|
||||||
if(isset($input->action) && $input->action == "requestUpgrade") {
|
if(isset($input->action) && $input->action == "requestUpgrade") {
|
||||||
$currentVersion = getVersion($db);
|
$currentVersion = getVersion($db);
|
||||||
|
$dbType = $config['db_type'];
|
||||||
if($currentVersion < 1) {
|
if($currentVersion < 1) {
|
||||||
$sql["mysql"] = "
|
$sql["mysql"] = "
|
||||||
CREATE TABLE IF NOT EXISTS remote (
|
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);
|
INSERT INTO options(name,value) VALUES ('schema_version', 1);
|
||||||
";
|
";
|
||||||
$sql["pgsql"] = "";
|
$sql["pgsql"] = "INSERT INTO options(name,value) VALUES ('schema_version', 1);";
|
||||||
$stmt = $db->query($sql[$config['db_type']]);
|
$stmt = $db->query($sql[$dbType]);
|
||||||
while ($stmt->nextRowset()) {;}
|
while ($stmt->nextRowset()) {;}
|
||||||
}
|
}
|
||||||
if($currentVersion < 2) {
|
if($currentVersion < 2) {
|
||||||
|
@ -79,13 +79,13 @@ if(isset($input->action) && $input->action == "requestUpgrade") {
|
||||||
|
|
||||||
UPDATE options SET value=2 WHERE name='schema_version';
|
UPDATE options SET value=2 WHERE name='schema_version';
|
||||||
";
|
";
|
||||||
$sql["pgsql"] = "";
|
$sql["pgsql"] = "UPDATE options SET value=2 WHERE name='schema_version';";
|
||||||
$stmt = $db->query($sql[$config['db_type']]);
|
$stmt = $db->query($sql[$dbType]);
|
||||||
while ($stmt->nextRowset()) {;}
|
while ($stmt->nextRowset()) {;}
|
||||||
}
|
}
|
||||||
if($currentVersion < 3) {
|
if($currentVersion < 3) {
|
||||||
$sql["mysql"] = "
|
$sql["mysql"] = "
|
||||||
CREATE TABLE domainmetadata (
|
CREATE TABLE IF NOT EXISTS domainmetadata (
|
||||||
id INT AUTO_INCREMENT,
|
id INT AUTO_INCREMENT,
|
||||||
domain_id INT NOT NULL,
|
domain_id INT NOT NULL,
|
||||||
kind VARCHAR(32),
|
kind VARCHAR(32),
|
||||||
|
@ -98,9 +98,10 @@ if(isset($input->action) && $input->action == "requestUpgrade") {
|
||||||
|
|
||||||
UPDATE options SET value=3 WHERE name='schema_version';
|
UPDATE options SET value=3 WHERE name='schema_version';
|
||||||
";
|
";
|
||||||
$sql["pgsql"] = "";
|
$sql["pgsql"] = "UPDATE options SET value=3 WHERE name='schema_version';";
|
||||||
$stmt = $db->query($sql[$config['db_type']]);
|
$stmt = $db->query($sql[$dbType]);
|
||||||
while ($stmt->nextRowset()) {;}
|
while ($stmt->nextRowset()) {;}
|
||||||
|
|
||||||
}
|
}
|
||||||
if($currentVersion < 4) {
|
if($currentVersion < 4) {
|
||||||
$sql["mysql"] = "
|
$sql["mysql"] = "
|
||||||
|
@ -147,8 +148,8 @@ if(isset($input->action) && $input->action == "requestUpgrade") {
|
||||||
|
|
||||||
UPDATE options SET value=4 WHERE name='schema_version';
|
UPDATE options SET value=4 WHERE name='schema_version';
|
||||||
";
|
";
|
||||||
$sql["pgsql"] = "";
|
$sql["pgsql"] = "UPDATE options SET value=4 WHERE name='schema_version';";
|
||||||
$stmt = $db->query($sql[$config['db_type']]);
|
$stmt = $db->query($sql[$dbType]);
|
||||||
while ($stmt->nextRowset()) {;}
|
while ($stmt->nextRowset()) {;}
|
||||||
}
|
}
|
||||||
$retval['status'] = "success";
|
$retval['status'] = "success";
|
||||||
|
|
|
@ -24,12 +24,6 @@ $config['db_password'] = "";
|
||||||
$config['db_port'] = 3306;
|
$config['db_port'] = 3306;
|
||||||
$config['db_name'] = "pdnsmanager";
|
$config['db_name'] = "pdnsmanager";
|
||||||
|
|
||||||
//HTTP API Settings
|
|
||||||
$config['api_functionality'] = true;
|
|
||||||
$config['api_host'] = "localhost"
|
|
||||||
$config['api_port'] = 8080;
|
|
||||||
$config['api_key'] = "";
|
|
||||||
|
|
||||||
//Remote update
|
//Remote update
|
||||||
$config['nonce_lifetime'] = 15;
|
$config['nonce_lifetime'] = 15;
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,8 @@ limitations under the License.
|
||||||
<select class="form-control no-shadow" id="searchType">
|
<select class="form-control no-shadow" id="searchType">
|
||||||
<option value="none">No filter...</option>
|
<option value="none">No filter...</option>
|
||||||
<option value="MASTER">MASTER</option>
|
<option value="MASTER">MASTER</option>
|
||||||
|
<option value="NATIVE">NATIVE</option>
|
||||||
|
<option value="SLAVE">SLAVE</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -92,8 +94,9 @@ limitations under the License.
|
||||||
<?php
|
<?php
|
||||||
if($_SESSION['type'] == "admin") {
|
if($_SESSION['type'] == "admin") {
|
||||||
echo '<div class="row text-center">';
|
echo '<div class="row text-center">';
|
||||||
echo '<a class="btn btn-success" href="add-domain.php#MASTER">Add MASTER</a>';
|
echo '<a class="btn btn-primary" href="add-domain.php#NATIVE">Add NATIVE</a>';
|
||||||
echo '<a class="btn btn-primary margin-left-20" href="add-domain.php#NATIVE">Add NATIVE</a>';
|
echo '<a class="btn btn-success margin-left-20" href="add-domain.php#MASTER">Add MASTER</a>';
|
||||||
|
echo '<a class="btn btn-success margin-left-20" href="add-domain.php#SLAVE">Add SLAVE</a>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -70,7 +70,7 @@ limitations under the License.
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="soa-mail" class="control-label">Email</label>
|
<label for="soa-mail" class="control-label">Email</label>
|
||||||
<input type="text" class="form-control" id="soa-mail" placeholder="Email" autocomplete="off" data-regex="^.+@[^.]+(\.[^.]+)*$" tabindex="2">
|
<input type="email" class="form-control" id="soa-mail" placeholder="Email" autocomplete="off" tabindex="2">
|
||||||
</div>
|
</div>
|
||||||
<button disabled type="submit" class="btn btn-primary" tabindex="7">Save</button>
|
<button disabled type="submit" class="btn btn-primary" tabindex="7">Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -66,11 +66,10 @@ limitations under the License.
|
||||||
<h3>Database</h3>
|
<h3>Database</h3>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dbType" class="control-label">Type</label>
|
<label for="dbType" class="control-label">Type</label>
|
||||||
<select class="form-control" name=dbType">
|
<select class="form-control" id="dbType">
|
||||||
<option value="mysql" selected>MySQL</option>
|
<option value="mysql" selected>MySQL</option>
|
||||||
<option value="pgsql">PgSQL</option>
|
<option value="pgsql">PgSQL</option>
|
||||||
</select>
|
</select>
|
||||||
<input type="text" class="form-control" id="dbHost" placeholder="Host" autocomplete="off">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="dbHost" class="control-label">Host</label>
|
<label for="dbHost" class="control-label">Host</label>
|
||||||
|
|
|
@ -52,7 +52,7 @@ function checkSettings() {
|
||||||
port: $('#dbPort').val(),
|
port: $('#dbPort').val(),
|
||||||
userName: $('#adminName').val(),
|
userName: $('#adminName').val(),
|
||||||
userPassword: $('#adminPassword').val(),
|
userPassword: $('#adminPassword').val(),
|
||||||
type: $('#dbType').val()
|
type: $('#dbType').val()
|
||||||
};
|
};
|
||||||
|
|
||||||
$.post(
|
$.post(
|
||||||
|
|
|
@ -30,13 +30,11 @@ function checkVersion($db) {
|
||||||
|
|
||||||
function getVersion($db) {
|
function getVersion($db) {
|
||||||
|
|
||||||
try {
|
$stmt = $db->prepare("SELECT value FROM options WHERE name='schema_version' LIMIT 1");
|
||||||
$stmt = $db->prepare("SELECT value FROM options WHERE name='schema_version' LIMIT 1");
|
$stmt->execute();
|
||||||
$stmt->execute();
|
$version = $stmt->fetchColumn();
|
||||||
$version = $stmt->fetchColumn();
|
if (!$version) {
|
||||||
} catch (Exception $e) {
|
$version = 0;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $version;
|
return $version;
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
try {
|
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) {
|
catch (PDOException $e) {
|
||||||
die("Connection to database failed");
|
die("Connection to database failed");
|
||||||
|
|
Loading…
Reference in a new issue