forked from wopost/Bind-Web
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
387 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
$TTL 1D | ||
@ IN SOA @ rname.invalid. ( | ||
20180836; serial | ||
1H ; refresh | ||
1H ; retry | ||
1W ; expire | ||
3H ) ; minimum | ||
@ NS dns.cdd.group. | ||
@ NS dns2.cdd.group. | ||
dns A 192.168.10.20 | ||
dns2 A 192.168.10.2 | ||
;k8s-system | ||
heapster-grafana A 192.168.10.1 | ||
scope A 192.168.10.1 | ||
traefik A 192.168.10.1 | ||
heapster-grafana A 192.168.10.1 | ||
dashboard A 192.168.10.1 | ||
harbor A 192.168.10.20 | ||
monitor A 192.168.10.1 | ||
kibana A 192.168.10.1 | ||
elasticsearch A 192.168.10.1 | ||
jenkins A 192.168.10.1 | ||
prometheus A 192.168.10.1 | ||
cdh A 192.168.10.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
$TTL 1D | ||
@ IN SOA @ rname.invalid. ( | ||
20180837; serial | ||
1H ; refresh | ||
1H ; retry | ||
1W ; expire | ||
3H ) ; minimum | ||
@ NS dns.cdd.group. | ||
@ NS dns2.cdd.group. | ||
dns A 192.168.10.20 | ||
dns2 A 192.168.10.2 | ||
;k8s-system | ||
heapster-grafana A 192.168.10.1 | ||
scope A 192.168.10.1 | ||
traefik A 192.168.10.1 | ||
heapster-grafana A 192.168.10.1 | ||
dashboard A 192.168.10.1 | ||
harbor A 192.168.10.20 | ||
monitor A 192.168.10.1 | ||
kibana A 192.168.10.1 | ||
elasticsearch A 192.168.10.1 | ||
jenkins A 192.168.10.1 | ||
prometheus A 192.168.10.1 | ||
cdh A 192.168.10.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
db_host = '127.0.0.1' | ||
db_name = 'named' | ||
db_user = 'root' | ||
db_port = 5353 | ||
db_passwd = '123456' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
-- MySQL dump 10.13 Distrib 5.1.73, for redhat-linux-gnu (x86_64) | ||
-- | ||
-- Host: localhost Database: named | ||
-- ------------------------------------------------------ | ||
-- Server version 5.6.16-log | ||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8 */; | ||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; | ||
/*!40103 SET TIME_ZONE='+00:00' */; | ||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; | ||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; | ||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; | ||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; | ||
|
||
-- | ||
-- Table structure for table `dns_records` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `dns_records`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `dns_records` ( | ||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
`zone` varchar(255) NOT NULL, | ||
`host` varchar(255) NOT NULL DEFAULT '@', | ||
`type` enum('A','MX','CNAME','NS','SOA','PTR','TXT','AAAA','SVR','URL') NOT NULL, | ||
`data` varchar(255) DEFAULT NULL, | ||
`ttl` int(11) NOT NULL DEFAULT '3600', | ||
`mx_priority` int(11) DEFAULT NULL, | ||
`view` enum('any','Telecom','Unicom','CMCC','ours') NOT NULL DEFAULT 'any', | ||
`priority` tinyint(3) unsigned NOT NULL DEFAULT '255', | ||
`refresh` int(11) NOT NULL DEFAULT '28800', | ||
`retry` int(11) NOT NULL DEFAULT '14400', | ||
`expire` int(11) NOT NULL DEFAULT '86400', | ||
`minimum` int(11) NOT NULL DEFAULT '86400', | ||
`serial` bigint(20) NOT NULL DEFAULT '2015050917', | ||
`resp_person` varchar(64) NOT NULL DEFAULT 'ddns.net', | ||
`primary_ns` varchar(64) NOT NULL DEFAULT 'ns.ddns.net.', | ||
PRIMARY KEY (`id`), | ||
KEY `type` (`type`), | ||
KEY `host` (`host`), | ||
KEY `zone` (`zone`) | ||
) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `dns_records` | ||
-- | ||
|
||
LOCK TABLES `dns_records` WRITE; | ||
/*!40000 ALTER TABLE `dns_records` DISABLE KEYS */; | ||
INSERT INTO `dns_records` VALUES (21,'test.info','w','CNAME','www',60,NULL,'any',255,28800,14400,86400,86400,2015050917,'ddns.net','ns.ddns.net.'),(18,'test.info','www','A','2.2.2.2',60,NULL,'any',255,28800,14400,86400,86400,2015050917,'ddns.net','ns.ddns.net.'),(22,'test.info','www','A','1.1.1.1',60,NULL,'any',255,28800,14400,86400,86400,2015050917,'ddns.net','ns.ddns.net.'); | ||
/*!40000 ALTER TABLE `dns_records` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
|
||
-- | ||
-- Table structure for table `user` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `user`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `user` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`username` varchar(255) DEFAULT NULL, | ||
`name_cn` varchar(255) DEFAULT NULL, | ||
`password` varchar(255) DEFAULT NULL, | ||
`mobile` varchar(255) DEFAULT NULL, | ||
`email` varchar(255) DEFAULT NULL, | ||
`role` int(255) DEFAULT NULL, | ||
`status` int(255) DEFAULT NULL, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `username` (`username`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=89 DEFAULT CHARSET=utf8; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `user` | ||
-- | ||
|
||
LOCK TABLES `user` WRITE; | ||
/*!40000 ALTER TABLE `user` DISABLE KEYS */; | ||
INSERT INTO `user` VALUES (87,'laowang','老王','12fe31d801a521149d338101fe938649','13725578011','[email protected]',0,0),(88,'eagle','老鹰','12fe31d801a521149d338101fe938649','13725571111','[email protected]',0,0); | ||
/*!40000 ALTER TABLE `user` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; | ||
|
||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; | ||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; | ||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; | ||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; | ||
|
||
-- Dump completed on 2017-10-16 17:29:47 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
# -*-coding:utf-8 -*- | ||
from app import app | ||
import sys | ||
|
||
reload(sys) | ||
|
||
|
||
sys.setdefaultencoding('utf-8') | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0',debug=False) | ||
#app.run(host='0.0.0.0',port='5354') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
nohup python /etc/named/Bind-Web-master/run.py >> /etc/named/Bind-Web-master/bind-system.log 2>&1 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
#!/usr/bin/env python | ||
#_*_ coding:utf-8 _*_ | ||
__author__ = 'Eagle' | ||
import MySQLdb as mysql | ||
import config | ||
import commands | ||
import os | ||
import re | ||
import shutil | ||
import time | ||
|
||
connect_db = mysql.connect( | ||
user = config.db_user, | ||
passwd = config.db_passwd, | ||
db = config.db_name , | ||
host = config.db_host, | ||
port = config.db_port, | ||
charset= "utf8" ) | ||
cur = connect_db.cursor() | ||
|
||
#每次更新id加1&reload服务 | ||
def reload_service(): | ||
bak_time = time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime()) | ||
#域名文件的备份 | ||
if os.path.exists('/etc/named/Bind-Web-master/backup'): | ||
shutil.copyfile("cdd.group.zone", "backup/cdd.group.zone_%s" % bak_time) | ||
else: | ||
os.mkdir('backup') | ||
shutil.copyfile("cdd.group.zone", "backup/cdd.group.zone_%s" % bak_time) | ||
|
||
(status, output) = commands.getstatusoutput('grep serial cdd.group.zone') | ||
s , b = output.split(';') | ||
pre_value = int(s)+1 | ||
value = " " + str(pre_value) + "; " + "serial" | ||
os.system("sed -i '3s/.*serial/%s/g' cdd.group.zone" % value) | ||
os.system("systemctl reload named.service") | ||
|
||
# 获得注册信息,并写入数据库 | ||
def insert_sql(table_name,field,data): | ||
sql = "INSERT INTO %s (%s) VALUES (%s);" % (table_name, ','.join(field), ','.join(['"%s"' % data[x] for x in field])) | ||
print sql | ||
ip = str(data['data']) | ||
zone = data['zone'] | ||
host = data['host'] | ||
typees = data['type'] | ||
#从库查看要添加的二级域名 | ||
check_host = 'select host from dns_records where host="%s";' % host | ||
cur.execute(check_host) | ||
select_host = cur.fetchone() | ||
#要是存在直接报错 | ||
if select_host: | ||
res = int(0) | ||
else: | ||
#不存在就添加 | ||
res = cur.execute(sql) | ||
connect_db.commit() | ||
with open('cdd.group.zone','a+') as f: | ||
f.write("%s %s %s\n" % (host,typees,ip)) | ||
#写入成功更改id和reload服务 | ||
reload_service() | ||
res = int(1) | ||
if res: | ||
result = {'code':0,'msg':'insert ok'} | ||
else: | ||
result = {'code':1,'msg':'insert fail'} | ||
return result | ||
|
||
# 获得数据列表 | ||
def list(table_name,field): | ||
sql = "select * from %s ;" % table_name | ||
cur.execute(sql) | ||
res = cur.fetchall() | ||
if res: | ||
user = [dict((k,row[i]) for i,k in enumerate(field))for row in res] | ||
result = {'code':0,'msg':user} | ||
else: | ||
result = {'code':1,'errmsg':'data is null'} | ||
|
||
return result | ||
# 获取一条数据 | ||
def getone(table,data,field): | ||
if data.has_key('username'): | ||
sql = 'select * from %s where username="%s";' % (table,data['username']) | ||
else: | ||
sql = 'select %s from %s where id="%s";' % (','.join(field),table,data['id']) | ||
print sql | ||
cur.execute(sql) | ||
res = cur.fetchone() | ||
if res: | ||
user = {k:res[i] for i,k in enumerate(field)} | ||
result = {'code':0,'msg':user} | ||
else: | ||
result ={'code':1, 'msg':"data is null"} | ||
return result | ||
|
||
# 数据更新 | ||
def _update(table,field,data): | ||
conditions = ["%s='%s'" % (k,data[k]) for k in data] | ||
sql = "update %s set %s where id=%s ;" %(table,','.join(conditions),data['id']) | ||
check_hosts = 'select host from dns_records where id="%s";' % data['id'] | ||
cur.execute(check_hosts) | ||
old_host = str(cur.fetchone()).split("'")[1] | ||
|
||
ip = str(data['data']) | ||
zone = data['zone'] | ||
host = data['host'] | ||
typees = data['type'] | ||
print sql | ||
#从库查看该二级域名 | ||
check_host = 'select host from dns_records where host="%s";' % host | ||
cur.execute(check_host) | ||
select_host = cur.fetchone() | ||
|
||
#判断更新的ip地址是否合法,合法跳过这if,不合法测直接return error | ||
if not re.match('^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[1-9])$','%s' % ip): | ||
result = {'code':2,'errmsg':'check ip fail'} | ||
return result | ||
|
||
#要是存在并且这次的域名和原有的域名同样就认为改ip | ||
if host == old_host: | ||
os.system("sed -i 's/^%s [ \t].*/%s %s %s /g' cdd.group.zone" % (old_host,host,typees,ip)) | ||
res = cur.execute(sql) | ||
elif select_host: | ||
#这次的域名和原有的域名不同并且更新的域名存在就报错 | ||
res = int(0) | ||
else: | ||
#要是原域名和这次的不同并且库里不存在就变更原记录 | ||
os.system("sed -i 's/^%s [ \t].*/%s %s %s /g' cdd.group.zone" % (old_host,host,typees,ip)) | ||
res = cur.execute(sql) | ||
if res : | ||
#成功更改完服务reload操作 | ||
reload_service() | ||
connect_db.commit() | ||
result = {'code':0,'msg':'update ok'} | ||
else: | ||
result = {'code':1,'errmsg':'Update fail'} | ||
return result | ||
|
||
|
||
# 数据删除 | ||
def _delete(table_name,data): | ||
tag=False | ||
|
||
check_hosts = 'select host from dns_records where id="%s";' % data['id'] | ||
cur.execute(check_hosts) | ||
host = str(cur.fetchone()).split("'")[1] | ||
print host | ||
try: | ||
#直接配置文件里删除后reload | ||
os.system("sed -i '/^%s [ \t].*/d' cdd.group.zone" % host) | ||
reload_service() | ||
#从库表里删除记录值 | ||
sql = 'DELETE FROM %s where id="%s" ;' % (table_name,data['id']) | ||
if cur.execute(sql): | ||
connect_db.commit() | ||
tag=True | ||
except Exception, e: | ||
print 'Error %s' % (sql) | ||
return tag | ||
|
||
# 用户是否存在监测 | ||
def check(table,field,where): | ||
if isinstance(where, dict) and where: | ||
conditions = [] | ||
for k,v in where.items(): | ||
conditions.append("%s='%s'" % (k, v)) | ||
sql = "select %s from %s where %s ;" % (','.join(field),table,' AND '.join(conditions)) | ||
print sql | ||
try: | ||
if cur.execute(sql): | ||
res = cur.fetchone() | ||
print res | ||
user = {k:res[i] for i,k in enumerate(field)} | ||
print user | ||
result = {'code':0,'msg':user} | ||
else: | ||
result ={'code':1, 'msg':"data is null"} | ||
except Exception, e: | ||
result ={'code':1, 'msg':"SQL Error "} | ||
|
||
return result | ||
|
||
# 用户数据更新 | ||
def _updates(table,field,data): | ||
conditions = ["%s='%s'" % (k,data[k]) for k in data] | ||
sql = "update %s set %s where id=%s ;" %(table,','.join(conditions),data['id']) | ||
print sql | ||
res = cur.execute(sql) | ||
if res : | ||
connect_db.commit() | ||
result = {'code':0,'msg':'update ok'} | ||
else: | ||
result = {'code':1,'errmsg':'Update fail'} | ||
return result | ||
|
||
|
||
# 用户数据删除 | ||
def _deletes(table_name,data): | ||
tag=False | ||
try: | ||
sql = 'DELETE FROM %s where id="%s" ;' % (table_name,data['id']) | ||
if cur.execute(sql): | ||
connect_db.commit() | ||
tag=True | ||
except Exception, e: | ||
print 'Error %s' % (sql) | ||
return tag | ||
|
||
# 获得用户注册信息,并写入数据库 | ||
def insert_sqls(table_name,field,data): | ||
sql = "INSERT INTO %s (%s) VALUES (%s);" % (table_name, ','.join(field), ','.join(['"%s"' % data[x] for x in field])) | ||
print sql | ||
res = cur.execute(sql) | ||
connect_db.commit() | ||
if res: | ||
result = {'code':0,'msg':'insert ok'} | ||
else: | ||
result = {'code':1,'msg':'insert fail'} | ||
return result |