Added some trimming around some VARCHAR records

This commit is contained in:
lamclennan 2017-01-07 20:29:36 +10:00
parent 7972a197ee
commit 5d5f8c4af7
2 changed files with 21 additions and 14 deletions

View file

@ -35,32 +35,34 @@ if(!isset($_SESSION['type']) || $_SESSION['type'] != "admin") {
if(isset($input->action) && $input->action == "addDomain") {
$soaData = Array();
$soaData[] = $input->primary;
$soaData[] = mail_to_soa($input->mail);
$soaData[] = trim($input->primary);
$soaData[] = trim(mail_to_soa($input->mail));
$soaData[] = date("Ymd") . "00";
$soaData[] = $input->refresh;
$soaData[] = $input->retry;
$soaData[] = $input->expire;
$soaData[] = $input->ttl;
$domainsName = trim($input->name);
$soaContent = implode(" ", $soaData);
$db->beginTransaction();
$stmt = $db->prepare("INSERT INTO domains(name,type) VALUES (:name,:type)");
$stmt->bindValue(':name', $input->name, PDO::PARAM_STR);
$stmt->bindValue(':name', $domainsName, PDO::PARAM_STR);
$stmt->bindValue(':type', $input->type, PDO::PARAM_STR);
$stmt->execute();
$stmt = $db->prepare("SELECT MAX(id) FROM domains WHERE name=:name AND type=:type");
$stmt->bindValue(':name', $input->name, PDO::PARAM_STR);
$stmt->bindValue(':name', $domainsName, PDO::PARAM_STR);
$stmt->bindValue(':type', $input->type, PDO::PARAM_STR);
$stmt->execute();
$newDomainId = $stmt->fetchColumn();
$stmt = $db->prepare("INSERT INTO records(domain_id,name,type,content,ttl) VALUES (:domain_id,:name,'SOA',:content,:ttl)");
$stmt->bindValue(':domain_id', $newDomainId, PDO::PARAM_INT);
$stmt->bindValue(':name', $input->name, PDO::PARAM_STR);
$stmt->bindValue(':name', $domainsName, PDO::PARAM_STR);
$stmt->bindValue(':content', $soaContent, PDO::PARAM_STR);
$stmt->bindValue(':ttl', $input->ttl, PDO::PARAM_INT);
$stmt->execute();

View file

@ -184,8 +184,8 @@ if(isset($input->action) && $input->action == "saveSoa") {
$content = explode(" ", $content);
$serial = $content[2];
$newsoa = $input->primary . " ";
$newsoa .= mail_to_soa($input->email) . " ";
$newsoa = trim($input->primary) . " ";
$newsoa .= trim(mail_to_soa($input->email)) . " ";
$newsoa .= $serial . " ";
$newsoa .= $input->refresh . " ";
$newsoa .= $input->retry . " ";
@ -208,11 +208,13 @@ 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);
$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->bindValue(':name', $input->name, PDO::PARAM_STR);
$stmt->bindValue(':name', $recordName, PDO::PARAM_STR);
$stmt->bindValue(':type', $input->type, PDO::PARAM_STR);
$stmt->bindValue(':content', $input->content, PDO::PARAM_STR);
$stmt->bindValue(':content', $recordContent, PDO::PARAM_STR);
$stmt->bindValue(':ttl', $input->ttl, PDO::PARAM_INT);
$stmt->bindValue(':prio', $input->prio, PDO::PARAM_INT);
$stmt->bindValue(':id', $input->id, PDO::PARAM_INT);
@ -224,22 +226,25 @@ 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);
$recordContent = trim($input->content);
$db->beginTransaction();
$stmt = $db->prepare("INSERT INTO records (domain_id, name, type, content, prio, ttl) VALUES (:domain_id,:name,:type,:content,:prio,:ttl)");
$stmt->bindValue(':domain_id', $domainId, PDO::PARAM_INT);
$stmt->bindValue(':name', $input->name, PDO::PARAM_STR);
$stmt->bindValue(':name', $recordName, PDO::PARAM_STR);
$stmt->bindValue(':type', $input->type, PDO::PARAM_STR);
$stmt->bindValue(':content', $input->content, PDO::PARAM_STR);
$stmt->bindValue(':content', $recordContent, PDO::PARAM_STR);
$stmt->bindValue(':ttl', $input->ttl, PDO::PARAM_INT);
$stmt->bindValue(':prio', $input->prio, PDO::PARAM_INT);
$stmt->execute();
$stmt = $db->prepare("SELECT MAX(id) FROM records WHERE domain_id=:domain_id AND name=:name AND type=:type AND content=:content AND prio=:prio AND ttl=:ttl");
$stmt->bindValue(':domain_id', $domainId, PDO::PARAM_INT);
$stmt->bindValue(':name', $input->name, PDO::PARAM_STR);
$stmt->bindValue(':name', $recordName, PDO::PARAM_STR);
$stmt->bindValue(':type', $input->type, PDO::PARAM_STR);
$stmt->bindValue(':content', $input->content, PDO::PARAM_STR);
$stmt->bindValue(':content', $recordContent, PDO::PARAM_STR);
$stmt->bindValue(':ttl', $input->ttl, PDO::PARAM_INT);
$stmt->bindValue(':prio', $input->prio, PDO::PARAM_INT);
$stmt->execute();