Skip to content

Commit

Permalink
Added user connection verification; Added filter to auto hide revoked…
Browse files Browse the repository at this point in the history
… certs; Some fixes
  • Loading branch information
pashcovich committed Nov 2, 2020
1 parent 6e9a553 commit a65bda0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .werffiles/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fi

cp -f /etc/openvpn/setup/openvpn.conf /etc/openvpn/openvpn.conf

[ -d /etc/openvpn/certs/pki ] && chmod 755 /etc/openvpn/certs/pki
[ -f /etc/openvpn/certs/pki/crl.pem ] && chmod 644 /etc/openvpn/certs/pki/crl.pem
[ -d $EASY_RSA_LOC/pki ] && chmod 755 $EASY_RSA_LOC/pki
[ -f $EASY_RSA_LOC/pki/crl.pem ] && chmod 644 $EASY_RSA_LOC/pki/crl.pem

mkdir -p /etc/openvpn/ccd

Expand Down
1 change: 1 addition & 0 deletions .werffiles/openvpn.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dh /etc/openvpn/easyrsa/pki/dh.pem
crl-verify /etc/openvpn/easyrsa/pki/crl.pem
tls-auth /etc/openvpn/easyrsa/pki/ta.key
key-direction 0
duplicate-cn
cipher AES-128-CBC
management 127.0.0.1 8989
keepalive 10 60
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
cap_add:
- NET_ADMIN
ports:
- 1194:1194
- 7777:1194
volumes:
- ./easyrsa:/etc/openvpn/easyrsa
- ./ccd:/etc/openvpn/ccd
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ new Vue({
showWhenStatus: 'Active'
}
],
filters: {
hide_revoked: true
},
u: {
newUserName: '',
// newUserPassword: 'nopass',
Expand All @@ -127,9 +130,6 @@ new Vue({
}
},
watch: {
// u: function () {
// this.u.columns = Object.keys(this.u.data[0]) //.reverse()
// }
},
mounted: function () {
this.u_get_data()
Expand Down Expand Up @@ -209,11 +209,22 @@ new Vue({
modalShowCcdDisplay: function () {
return this.u.modalShowCcdVisible ? {display: 'flex'} : {}
},
filteredRows: function() {
var _this = this;

if(_this.filters.hide_revoked) {
return _this.rows.filter(function(account) {
return account.AccountStatus === "Active";
});
} else {
return _this.rows;
}
}

},
methods: {
rowStyleClassFn: function(row) {
return row.ConnectionStatus == '' ? '' : 'active-row';
return row.ConnectionStatus == 'Connected' ? 'connected-user' : '' ;
},
rowActionFn: function(e) {
this.username = e.target.dataset.username;
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ body {
margin: 0.1rem;
}

.connected-user {
background-color: rgba(162, 245, 169, 0.5);
}

.new-user-btn {
margin-right: 2rem;
}
Expand Down
34 changes: 6 additions & 28 deletions frontend/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,20 @@
</head>
<body>
<div id="app">

<!-- <div class="dropdown-menu dropdown-custom" :style="uCtxStyle" v-show="u.ctxVisible">-->
<!-- <button class="dropdown-item" type="button" :data-name="name" :data-text="text" @click.left.stop="u_ctx_click" v-for="text, name in u.ctxMenuItems">{{text}}</button>-->
<!-- </div>-->

<!-- <table class="table table-bordered table-hover">-->
<!-- <thead class="thead-dark">-->
<!-- <tr>-->
<!-- <th scope="col">Name</th>-->
<!-- <th scope="col">Account status</th>-->
<!-- <th scope="col">Expiration date</th>-->
<!-- <th scope="col">Revocation date</th>-->
<!--&lt;!&ndash; <th scope="col">Connection status</th>&ndash;&gt;-->
<!-- </tr>-->
<!-- </thead>-->
<!-- <tbody>-->
<!-- <tr v-for="row in u.data" :data-name="row.Identity" v-bind:style="row.ConnectionStatus" @contextmenu.prevent="u_ctx_show">-->
<!-- <td>{{ row.Identity }}</td>-->
<!-- <td>{{ row.AccountStatus }}</td>-->
<!-- <td>{{ row.ExpirationDate }}</td>-->
<!-- <td>{{ row.RevocationDate }}</td>-->
<!--&lt;!&ndash; <td>{{ row.ConnectionStatus }}</td>&ndash;&gt;-->
<!-- </tr>-->
<!-- </tbody>-->
<!-- </table>-->
<vue-good-table
:columns="columns"
:rows="rows"
:rows="filteredRows"
:line-numbers="true"
:row-style-class="rowStyleClassFn"
:search-options="{ enabled: true}" >
<div slot="table-actions">
<button type="button" class="btn btn-sm btn-success el-square" v-on:click.stop="u.modalNewUserVisible=true">Add user</button>
<button type="button" class="btn btn-sm btn-secondary el-square" v-on:click.stop="filters.hide_revoked=!filters.hide_revoked" v-show="filters.hide_revoked">Show revoked</button>
<button type="button" class="btn btn-sm btn-secondary el-square" v-on:click.stop="filters.hide_revoked=!filters.hide_revoked" v-show="!filters.hide_revoked">Hide revoked</button>
</div>
<div slot="emptystate">
This will show up when there are no rows
<div slot="emptystate" class="d-flex justify-content-center">
<h4>No users have been created yet.</h4>
<button type="button" class="btn btn-sm btn-success el-square" v-on:click.stop="u.modalNewUserVisible=true">Add user</button>
</div>
<template slot="table-row" slot-scope="props">
<span v-if="props.column.field == 'actions'">
Expand Down
25 changes: 21 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,24 @@ func checkUserExist(username string) bool {

func usersList() []openvpnClient {
users := []openvpnClient{}
activeClients := mgmtGetActiveClients()

for _, line := range indexTxtParser(fRead(*indexTxtPath)) {
if line.Identity != "server" {
ovpnClient := openvpnClient{Identity: line.Identity, ExpirationDate: indexTxtDateToHumanReadable(line.ExpirationDate)}
switch {
case line.Flag == "V":
users = append(users, openvpnClient{Identity: line.Identity, ExpirationDate: indexTxtDateToHumanReadable(line.ExpirationDate), AccountStatus: "Active"})
ovpnClient.AccountStatus = "Active"
case line.Flag == "R":
users = append(users, openvpnClient{Identity: line.Identity, RevocationDate: indexTxtDateToHumanReadable(line.RevocationDate), ExpirationDate: indexTxtDateToHumanReadable(line.ExpirationDate), AccountStatus: "Revoked"})
ovpnClient.AccountStatus = "Revoked"
ovpnClient.RevocationDate = indexTxtDateToHumanReadable(line.RevocationDate)
case line.Flag == "E":
users = append(users, openvpnClient{Identity: line.Identity, RevocationDate: indexTxtDateToHumanReadable(line.RevocationDate), ExpirationDate: indexTxtDateToHumanReadable(line.ExpirationDate), AccountStatus: "Expired"})

ovpnClient.AccountStatus = "Expired"
}
if isUserConnected(line.Identity, activeClients) {
ovpnClient.ConnectionStatus = "Connected"
}
users = append(users, ovpnClient)
}
}
return users
Expand Down Expand Up @@ -520,6 +527,16 @@ func mgmtGetActiveClients() []clientStatus {
return activeClients
}

func isUserConnected(username string, connectedUsers []clientStatus) bool {
for _, connectedUser := range connectedUsers {
if connectedUser.CommonName == username {
return true
}
}
return false
}


func indexTxtDateToHumanReadable(datetime string) string {
layout := "060102150405Z"
t, err := time.Parse(layout, datetime)
Expand Down

0 comments on commit a65bda0

Please sign in to comment.