Skip to content

Commit

Permalink
Update ui & dns
Browse files Browse the repository at this point in the history
  • Loading branch information
ac0d3r committed Dec 18, 2021
1 parent 7bfec59 commit 9638404
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 164 deletions.
13 changes: 12 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"sass-loader": "^8.0.2",
"vue": "^2.6.10",
"vue-axios": "^3.3.7",
"vue-clipboard2": "^0.3.3"
"vue-clipboard2": "^0.3.3",
"vue-cookies": "^1.7.4"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.1",
Expand Down
89 changes: 53 additions & 36 deletions frontend/src/components/DnsLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,25 @@
cancel-text="No"
@confirm="handleCreateUser"
>
<a-tooltip title="reset domain name">
<a-icon size="small" type="redo" />
</a-tooltip>
<a-button size="small" type="primary" shape="circle" icon="redo" />
</a-popconfirm>
<a-tooltip title="set dns rebinding">
<a-icon
size="small"
type="setting"
@click="
() => {
Shows.DnsRebindSetting = true;
User.OldIPs = User.IPs;
}
"
/>
</a-tooltip>

<a-icon
size="small"
type="setting"
@click="
() => {
Shows.DnsRebindSetting = true;
User.OldIPs = User.IPs;
}
"
/>
<a-popconfirm
title="Wipe all records data?"
ok-text="Yes"
cancel-text="No"
@confirm="handleWipeData"
>
<a-tooltip title="wipe data">
<a-icon size="small" type="close" />
</a-tooltip>
<a-button size="small" type="danger" shape="circle" icon="close" />
</a-popconfirm>
</template>
</a-card>
Expand All @@ -70,6 +63,7 @@
<a-select
v-model="CurrentQueryMode"
style="width: 120px; margin-right: 4px"
@change="handleSelectQueryModeChange"
>
<a-select-option
v-for="(mode, index) in QueryModes"
Expand Down Expand Up @@ -130,7 +124,16 @@
"
>
<div v-if="User.ID">
Host: <a-tag>r.{{ User.ID }}</a-tag>
Host: <a-tag>r.{{ User.ID }}</a-tag
><a-icon
v-if="User.ID !== ''"
type="copy"
@click="
() => {
copy('r.' + User.ID);
}
"
/>
</div>
<br />
<div>
Expand All @@ -156,7 +159,7 @@
:style="{ width: '78px' }"
:value="Inputs.DnsRebinding"
@change="handleTagInputChange"
@blur="handleTagInputConfirm"
@blur="handleTagInputBlur"
@keyup.enter="handleTagInputConfirm"
/>
<a-tag
Expand All @@ -182,7 +185,7 @@ import {
GetLogRecords,
WipeRecodsData,
} from "../utils/apis";
import { getCookie, equar } from "../utils/cookie";
import { equar, validateIPaddress } from "../utils/util";
const formatTimestamp = (created) => {
const parsed = parseInt(created, 10);
Expand Down Expand Up @@ -267,13 +270,22 @@ export default {
handleTagInputChange(e) {
this.Inputs.DnsRebinding = e.target.value;
},
handleTagInputBlur() {
this.Shows.AddDns = false;
this.Inputs.DnsRebinding = "";
},
handleTagInputConfirm() {
const dns = this.Inputs.DnsRebinding;
let ips = this.User.IPs;
if (dns && ips.indexOf(dns) === -1) {
ips = [...ips, dns];
if (!validateIPaddress(this.Inputs.DnsRebinding)) {
this.$message.error("You have entered an invalid IP address!");
} else {
const dns = this.Inputs.DnsRebinding;
let ips = this.User.IPs;
if (dns && ips.indexOf(dns) === -1) {
ips = [...ips, dns];
}
this.User.IPs = ips;
}
this.User.IPs = ips;
this.Shows.AddDns = false;
this.Inputs.DnsRebinding = "";
},
Expand All @@ -293,6 +305,9 @@ export default {
handleWipeData() {
this.wipeRecodsData();
},
handleSelectQueryModeChange() {
this.getLogRecords();
},
formatHttpRaw(raw) {
return raw.length > 80 ? `${raw.substring(0, 80)}...` : raw;
},
Expand All @@ -313,8 +328,8 @@ export default {
const succ = (data) => {
this.User.ID = data.id;
this.User.Token = data.token;
document.cookie = `identity=${data.id}`;
document.cookie = `token=${data.token}`;
this.$cookies.set("identity", data.id, -1, "/");
this.$cookies.set("token", data.token, -1, "/");
this.$message.success("user created successfully");
this.getUserDnsRebindingHosts();
};
Expand All @@ -323,8 +338,8 @@ export default {
deleteUser(needCreate) {
const succ = () => {
this.User = { ID: "", Token: "", IPs: [], OldIPs: [] };
document.cookie = "identity=";
document.cookie = "token=";
this.$cookies.remove("identity");
this.$cookies.remove("token");
this.$message.success("user deleted successfully");
needCreate ? this.createUser() : {};
};
Expand All @@ -338,8 +353,8 @@ export default {
this.fail(msg);
if (code === 200) {
this.User = { ID: "", Token: "", IPs: [], OldIPs: [] };
document.cookie = "identity=";
document.cookie = "token=";
this.$cookies.remove("identity");
this.$cookies.remove("token");
}
};
GetUserDnsRebindingHosts(succ, fail);
Expand Down Expand Up @@ -376,10 +391,12 @@ export default {
WipeRecodsData(succ, this.fail);
},
initUser() {
this.User.ID = getCookie("identity");
this.User.Token = getCookie("token");
if (this.User.ID !== "" && this.User.Token !== "")
this.User.ID = this.$cookies.get("identity");
this.User.Token = this.$cookies.get("token");
if (this.User.ID !== "" && this.User.Token !== "") {
this.getUserDnsRebindingHosts();
this.getLogRecords();
}
},
},
created() {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import axios from 'axios'
import VueAxios from 'vue-axios'
import App from './App.vue'
import VueClipboard from 'vue-clipboard2'
import VueCookies from 'vue-cookies'

import 'ant-design-vue/dist/antd.css';

VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);
Vue.use(VueCookies);
Vue.use(Antd, VueAxios, axios);

Vue.config.productionTip = false
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/utils/apis.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { apihost } from "./conf";
import { getCookie } from "./cookie";
import VueCookies from 'vue-cookies'


function SetTokenHeader(obj) {
obj.Authorization = "Bearer " + getCookie("token")
const token = VueCookies.get("token");
obj.Authorization = "Bearer " + token
return obj
}

Expand Down
30 changes: 0 additions & 30 deletions frontend/src/utils/cookie.js

This file was deleted.

21 changes: 21 additions & 0 deletions frontend/src/utils/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function equar(a, b) {
if (a.length !== b.length) {
return false
} else {
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false
}
}
return true;
}
}

function validateIPaddress(ipaddress) {
if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress)) {
return (true)
}
return (false)
}

export { equar, validateIPaddress };
46 changes: 27 additions & 19 deletions hyuga/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,28 @@ import (
)

var (
C = Config{}
DefaultIP net.IP
DebugMode bool
RedisDsn string
RecordExpiration time.Duration
MainDomain string
DefaultIP net.IP
NSDomain []string
)

type Config struct {
DebugMode bool `yaml:"debug"`
Redis string `yaml:"redis"`
Domain domainSetting `yaml:"domain"`
RecordExpirationHour int `yaml:"record_expiration_hours"`
RecordExpiration time.Duration
}

type domainSetting struct {
Main string `yaml:"main"`
NS []string `yaml:"ns"`
IP string `yaml:"ip"`
DebugMode bool `yaml:"debug"`
Redis string `yaml:"redis"`
Domain struct {
Main string `yaml:"main"`
NS []string `yaml:"ns"`
IP string `yaml:"ip"`
} `yaml:"domain"`
RecordExpirationHour int `yaml:"record_expiration_hours"`
}

func SetFromYaml(c string) error {
var conf Config

f, err := os.Open(c)
if err != nil {
return err
Expand All @@ -41,15 +44,20 @@ func SetFromYaml(c string) error {
return err
}

if err = yaml.Unmarshal(buf, &C); err != nil {
if err = yaml.Unmarshal(buf, &conf); err != nil {
return err
}

C.Domain.Main = strings.Trim(C.Domain.Main, ".")
for i := range C.Domain.NS {
C.Domain.NS[i] = dns.Fqdn(C.Domain.NS[i])
DebugMode = conf.DebugMode
RedisDsn = conf.Redis
RecordExpiration = time.Duration(time.Duration(conf.RecordExpirationHour) * time.Hour)

MainDomain = strings.Trim(conf.Domain.Main, ".")
NSDomain = make([]string, len(conf.Domain.NS))
for i := range conf.Domain.NS {
NSDomain[i] = dns.Fqdn(conf.Domain.NS[i])
}
DefaultIP = net.ParseIP(C.Domain.IP)
C.RecordExpiration = time.Duration(time.Duration(C.RecordExpirationHour) * time.Hour)
DefaultIP = net.ParseIP(conf.Domain.IP)

return nil
}
9 changes: 6 additions & 3 deletions hyuga/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ func TestSetFromFile(t *testing.T) {
if err != nil {
t.Fatal(err)
}

t.Logf("%+v \n", C)

t.Log(DebugMode)
t.Log(RedisDsn)
t.Log(RecordExpiration)
t.Log(MainDomain)
t.Log(DefaultIP)
t.Log(NSDomain)
t.Log(DefaultIP)
}
1 change: 1 addition & 0 deletions hyuga/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func Init(dsn string) error {
opt *redis.Options
err error
)
// compatible with docker link
if dsn == "redis:6379" {
opt = &redis.Options{Addr: dsn, Password: "", DB: 0}
} else {
Expand Down
Loading

0 comments on commit 9638404

Please sign in to comment.