Fixed a few code bugs. Added text to strip whitespace from records (i.e.
name, master, email)
This commit is contained in:
lamclennan 2017-01-07 23:59:03 +10:00
parent 5d5f8c4af7
commit 47f3f9939e
13 changed files with 52 additions and 47 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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();

View file

@ -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);

View file

@ -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)) {

View file

@ -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";

View file

@ -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;

View file

@ -73,6 +73,8 @@ limitations under the License.
<select class="form-control no-shadow" id="searchType">
<option value="none">No filter...</option>
<option value="MASTER">MASTER</option>
<option value="NATIVE">NATIVE</option>
<option value="SLAVE">SLAVE</option>
</select>
</div>
</form>
@ -92,8 +94,9 @@ limitations under the License.
<?php
if($_SESSION['type'] == "admin") {
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 margin-left-20" href="add-domain.php#NATIVE">Add NATIVE</a>';
echo '<a class="btn btn-primary" 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>';
}
?>

View file

@ -70,7 +70,7 @@ limitations under the License.
</div>
<div class="form-group">
<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>
<button disabled type="submit" class="btn btn-primary" tabindex="7">Save</button>
</div>

View file

@ -66,11 +66,10 @@ limitations under the License.
<h3>Database</h3>
<div class="form-group">
<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="pgsql">PgSQL</option>
</select>
<input type="text" class="form-control" id="dbHost" placeholder="Host" autocomplete="off">
</div>
<div class="form-group">
<label for="dbHost" class="control-label">Host</label>

View file

@ -52,7 +52,7 @@ function checkSettings() {
port: $('#dbPort').val(),
userName: $('#adminName').val(),
userPassword: $('#adminPassword').val(),
type: $('#dbType').val()
type: $('#dbType').val()
};
$.post(

View file

@ -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;
}

View file

@ -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");