Exemplo n.º 1
0
Arquivo: Admin.php Projeto: klsf/kldns
 public function addDomain()
 {
     $domain = I("post.domain");
     if (I("post.action") == "add" && $domain) {
         $level = I("post.level/d");
         $dns = I("post.dns");
         $klsfDns = KlsfDns::getApi($dns);
         if (!($info = $klsfDns->getDomainInfo($domain))) {
             $error = $klsfDns->getErrorInfo();
             $this->assign("alert", sweetAlert("温馨提示", $error['msg'], "warning"));
         } else {
             $insert = array(':domain_id' => $info['domain_id'], ':dns' => $dns, ':name' => trim($info['name'], '.'), ':level' => $level);
             if ($this->pdo->execute("INSERT INTO `pre_domains` (`domain_id`, `dns`, `name`, `level`) VALUES (:domain_id, :dns, :name, :level)", $insert)) {
                 $this->assign("alert", sweetAlert("添加成功", "添加域名" . $info['name'] . "成功!", "success", U("domainList")));
                 return $this->fetch("common/sweetAlert");
             } else {
                 $this->assign("alert", sweetAlert("温馨提示", "保存数据库失败!", "warning"));
             }
         }
     }
     $this->assign("webTitle", "添加域名");
     return $this->fetch("addDomain");
 }
Exemplo n.º 2
0
Arquivo: Ajax.php Projeto: klsf/kldns
 /**
  * 删除记录
  * @param        $id
  * @param string $type
  */
 public function delRecord($id, $type = "user")
 {
     if ($type == "user") {
         //用户删除
         $this->isLogin();
         if (!($record = $this->pdo->find("select a.domain_id,b.dns from `pre_records`as a left join `pre_domains` as b on b.domain_id=a.domain_id WHERE a.`uid`=:uid and a.record_id=:id limit 1", array(":uid" => $this->userInfo['uid'], ":id" => $id)))) {
             $this->alert(sweetAlert("删除失败", "此记录不存在!", "warning"));
         }
     } else {
         //管理员删除
         $this->isAdmin();
         if (!($record = $this->pdo->find("select a.domain_id,b.dns from `pre_records`as a left join `pre_domains` as b on b.domain_id=a.domain_id WHERE a.record_id=:id limit 1", array(":id" => $id)))) {
             $this->alert(sweetAlert("删除失败", "此记录不存在!", "warning"));
         }
     }
     $domain_id = $record['domain_id'];
     $klsfDns = KlsfDns::getApi($record['dns']);
     if ($klsfDns->delRecord($domain_id, $id)) {
         if ($type == "user") {
             //用户删除
             $this->pdo->execute("delete from pre_records where record_id=:id and uid=:uid limit 1", array(":uid" => $this->userInfo['uid'], ":id" => $id));
         } else {
             //管理员删除
             $this->pdo->execute("delete from pre_records where record_id=:id limit 1", array(":id" => $id));
         }
         $this->remove('#Record_' . $id);
     } else {
         $info = $klsfDns->getErrorInfo();
         $this->alert(sweetAlert("删除失败", $info['msg'], "warning"));
     }
 }
Exemplo n.º 3
0
Arquivo: Panel.php Projeto: klsf/kldns
 public function index()
 {
     $action = I("post.action");
     if ($action == 'addrecord') {
         $this->assign("isAdd", true);
         $domain_id = I("post.domain_id");
         $name = trim(strtolower(I("post.name")));
         $type = I("post.type");
         $value = I("post.value");
         $code = I("post.code");
         if (strlen($code) != 4 || !isset($_COOKIE['verification']) || md5(strtolower($code)) !== $_COOKIE['verification']) {
             $this->assign("alert", sweetAlert("温馨提示", "验证码不正确", "warning"));
         } elseif (C("allowNum") == -1) {
             $this->assign("alert", sweetAlert("温馨提示", "站长已经关闭用户自助解析功能!", "warning"));
         } elseif (!$this->checkAllow($name)) {
             $this->assign("alert", sweetAlert("温馨提示", "对不起,前缀{$name}不允许用户解析!", "warning"));
         } elseif (C("allowNum") && $this->pdo->getCount("select record_id from pre_records where uid=:uid", array(":uid" => $this->userInfo['uid'])) >= C("allowNum")) {
             $this->assign("alert", sweetAlert("温馨提示", "你最大允许解析" . C("allowNum") . "条记录!", "warning"));
         } elseif (!($row = $this->pdo->find("select dns,name from pre_domains where domain_id=:id and level <= :level limit 1", array(":id" => $domain_id, ":level" => $this->userInfo['level'])))) {
             $this->assign("alert", sweetAlert("温馨提示", "所选择域名不存在!", "warning"));
         } else {
             setCookie('verification', null, -1, '/');
             //销毁验证码
             $klsfDns = KlsfDns::getApi($row['dns']);
             if ($ret = $klsfDns->addRecord($domain_id, $name, $type, $value, $row['name'])) {
                 $insert = array(':record_id' => $ret['record_id'], ':uid' => $this->userInfo['uid'], ':domain_id' => $domain_id, ':name' => $ret['name'], ':type' => $type, ':value' => $value);
                 if ($this->pdo->execute("INSERT INTO `pre_records` (`record_id`, `uid`, `domain_id`, `name`, `type`, `value`, `updatetime`) VALUES (:record_id, :uid, :domain_id, :name, :type, :value, NOW())", $insert)) {
                     $this->assign("isAdd", false);
                     $this->assign("alert", sweetAlert("添加成功", "添加记录成功!", "success"));
                 } else {
                     $this->assign("alert", sweetAlert("温馨提示", "解析成功,保存数据库失败!", "warning"));
                 }
             } else {
                 $info = $klsfDns->getErrorInfo();
                 $this->assign("alert", sweetAlert("温馨提示", $info['msg'], "warning"));
             }
         }
     }
     //获取记录列表
     $records = $this->pdo->selectAll("select a.*,b.name as domain,b.dns from pre_records as a left join pre_domains as b on b.domain_id=a.domain_id where a.uid=:uid", array(":uid" => $this->userInfo['uid']));
     //获取域名列表
     $domains = $this->pdo->selectAll("select * from pre_domains where `level` <= :level", array(":level" => $this->userInfo['level']));
     //遍历记录检查是否还存在,不存在则从数据库删除
     $newRecords = array();
     foreach ($records as $record) {
         $klsfDns = KlsfDns::getApi($record['dns']);
         if ($re = $klsfDns->getRecordInfo($record['domain_id'], $record['record_id'])) {
             $re['domain'] = $record['domain'];
             $newRecords[] = $re;
         } else {
             //不存在则删除记录
             $this->pdo->execute("delete from pre_records where record_id=:id limit 1", array(":id" => $record['record_id']));
         }
     }
     $this->assign("records", $newRecords);
     $this->assign("domains", $domains);
     $this->assign("webTitle", "控制面板");
     return $this->fetch();
 }