Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyuga Pro #28

Merged
merged 24 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
请求日志记录
  • Loading branch information
ac0d3r committed May 4, 2023
commit 7d638a1ac4e056760490d0c5ee38dbd02fe1214f
2 changes: 2 additions & 0 deletions frontend/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare module '@vue/runtime-core' {
ElAvatar: typeof import('element-plus/es')['ElAvatar']
ElButton: typeof import('element-plus/es')['ElButton']
ElCard: typeof import('element-plus/es')['ElCard']
ElCol: typeof import('element-plus/es')['ElCol']
ElContainer: typeof import('element-plus/es')['ElContainer']
ElDescriptions: typeof import('element-plus/es')['ElDescriptions']
ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem']
Expand All @@ -29,6 +30,7 @@ declare module '@vue/runtime-core' {
ElMenu: typeof import('element-plus/es')['ElMenu']
ElMenuItem: typeof import('element-plus/es')['ElMenuItem']
ElPopconfirm: typeof import('element-plus/es')['ElPopconfirm']
ElRow: typeof import('element-plus/es')['ElRow']
ElSpace: typeof import('element-plus/es')['ElSpace']
ElSubMenu: typeof import('element-plus/es')['ElSubMenu']
ElSwitch: typeof import('element-plus/es')['ElSwitch']
Expand Down
87 changes: 72 additions & 15 deletions frontend/src/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,53 @@ const confirm = () => {
};
// records
const records: Ref<any[]> = ref([]);
const ws = new WebSocket(`ws://${window.location.host}/api/v2/user/record`)
ws.onmessage = (msg: any) => {
records.value.push(JSON.parse(msg.data));
}
const typeTag = (type: number) => {
if (type == 0) {
return '';
} else if (type == 1) {
return 'success';
} else if (type == 2) {
return 'warning';
} else if (type == 3) {
return 'danger';
}
return 'info';
}
const strTag = (type: number) => {
if (type == 0) {
return 'dns';
} else if (type == 1) {
return 'http';
} else if (type == 2) {
return 'ldap';
} else if (type == 3) {
return 'rmi';
}
return 'unknown';
}
const parseDetail = (detail: any): any => {
if (detail !== null && detail.raw !== null) {
let lines = [];
for (let line of detail.raw.split('\r\n')) {
if (line !== '')
lines.push(line);
}
return lines;
}
return null;
}
const parseTime = (time: number): string => {
const date = new Date(time * 1000);
return date.toLocaleString();
}
</script>

<template>
<div style="text-align: center; ">
<div style="text-align: center;">
<el-space direction="vertical">
<el-card shadow="always" style="width: 500px;">
<template #header>
Expand All @@ -60,8 +103,7 @@ const records: Ref<any[]> = ref([]);
</el-icon>
Profile
</el-text>
<!-- <el-button :icon="Tools" text @click="store.state.logged ? opened = true : opened = false" /> -->
<el-button :icon="Tools" text @click="opened = true" />
<el-button :icon="Tools" text @click="store.state.logged ? opened = true : opened = false" />
</div>
</template>
<el-descriptions v-if="store.state.logged" :column="1" size="small" direction="horizontal">
Expand Down Expand Up @@ -121,15 +163,28 @@ const records: Ref<any[]> = ref([]);
</el-empty>
<el-table v-else :data="records" height="550" stripe table-layout="fixed" max-height="550"
style="width: 1000px;">
<el-table-column prop="type" label="Type" />
<el-table-column prop="type" label="Type">
<template #default="scope">
<el-tag :type="typeTag(scope.row.type)" disable-transitions>{{ strTag(scope.row.type)
}}</el-tag>
</template>
</el-table-column>
<el-table-column prop="name" label="Name" />
<el-table-column prop="remote_addr" label="RemoteAddr" />
<el-table-column prop="created_at" label="CreatedAt" />
<el-table-column prop="created_at" label="CreatedAt">
<template #default="scope">
{{ parseTime(scope.row.created_at) }}
</template>
</el-table-column>
<el-table-column type="expand">
<template #default="props">
<div m="4">
<h3>Detail</h3>
<p m="t-0 b-2">{{ props.row.detail }}</p>
<h4>Detail</h4>
<el-row>
<el-col v-for="line in parseDetail(props.row.detail)" :span="16">
<el-text size="small">{{ line }}</el-text>
</el-col>
</el-row>
</div>
</template>
</el-table-column>
Expand All @@ -138,15 +193,17 @@ const records: Ref<any[]> = ref([]);
</div>

<!-- settting -->
<el-drawer v-model="opened" title="Settings" direction="rtl">
<el-drawer v-model="opened" title="Settings" direction="rtl" size="small">
<el-form>
<el-popconfirm width="300" title="Are you sure to reset the API token?" confirm-button-text="Yes"
cancel-button-text="No" :icon="InfoFilled" icon-color="#626AEF" @confirm="reset">
<template #reference>
<el-button type="primary" :icon="Refresh">Reset Token</el-button>
</template>
</el-popconfirm>
<el-divider />
<el-form-item label="Token">
<el-popconfirm width="300" title="Are you sure to reset the API token?" confirm-button-text="Yes"
cancel-button-text="No" :icon="InfoFilled" icon-color="#626AEF" @confirm="reset">
<template #reference>
<el-button type="primary" :icon="Refresh">Reset</el-button>
</template>
</el-popconfirm>
</el-form-item>
<el-divider content-position="left">Notify Setting</el-divider>
<el-form-item label="Enable">
<el-switch v-model="store.state.user.notify.enable"
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949" />
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const fail = (msg: string) => {
});
};

const host = window.location.hostname;
const apihost: string = function () {
return `${window.location.protocol}//${window.location.host}`;
}();
Expand Down Expand Up @@ -116,7 +115,6 @@ function resetToken(succcallback: Function) {


export {
host,
isLogin,
githubOauth,
logout,
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ func ReturnUnauthorized(c *gin.Context, code errCode, err ...error) {
var cookieExpireTime = 3600 * 24 * 7

func setCookie(c *gin.Context, key, value string) {
c.SetCookie(key, value, cookieExpireTime, "/", "", true, false)
c.SetCookie(key, value, cookieExpireTime, "/", "", false, false)
}
13 changes: 12 additions & 1 deletion internal/handler/restful_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,18 @@ func (w *restfulHandler) record(c *gin.Context) {
close(c)
}
}()

// get user all records
records, err := w.recorder.Get(sid)
if err != nil {
logrus.Warnf("[restful] get user records err: %s", err.Error())
return
}
for _, r := range records {
if err = ws.WriteJSON(r); err != nil {
logrus.Infof("[restful][stream] push record err: %s", err.Error())
}
}
// subscribe user record event
s := w.eventbus.Subscribe(sid)
defer w.eventbus.Unsubscribe(s)
for {
Expand Down
4 changes: 2 additions & 2 deletions internal/oob/oob.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ type RecordType uint

func (o RecordType) String() string {
switch o {
case TypeHTTP:
return "http"
case TypeDNS:
return "dns"
case TypeHTTP:
return "http"
case TypeLDAP:
return "ldap"
case TypeRMI:
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Run(ctx context.Context,

u, err := db.GetUserBySid(r.Sid)
if err == nil && u != nil && u.Notify.Enable {
logrus.Infof("[server][notify] msg: %s-%s", r.Type.String(), r.Name)
logrus.Infof("[server][notify] msg: '%s', '%s'", r.Type.String(), r.Name)

if u.Notify.Bark.Key != "" {
notifier.WithBark(u.Notify.Bark.Key, u.Notify.Bark.Server, r.Type.String(), r.Name)
Expand Down