Compare commits
10 Commits
852a89ee71
...
abe104b7a4
| Author | SHA1 | Date |
|---|---|---|
|
|
abe104b7a4 | |
|
|
dc25e591a7 | |
|
|
42294aa6d0 | |
|
|
c5121212ec | |
|
|
0a0b91c7a8 | |
|
|
fd4e6109f0 | |
|
|
b3b505c3e0 | |
|
|
46ce2f55d1 | |
|
|
19e106fb58 | |
|
|
769b44c494 |
36
index.html
36
index.html
|
|
@ -7,6 +7,42 @@
|
|||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">Navbar</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" aria-current="page" href="#">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">Link</a>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Dropdown
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item" href="#">Action</a></li>
|
||||
<li><a class="dropdown-item" href="#">Another action</a></li>
|
||||
<li><hr class="dropdown-divider"></li>
|
||||
<li><a class="dropdown-item" href="#">Something else here</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disabled" aria-disabled="true">Disabled</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="d-flex" role="search">
|
||||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"/>
|
||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<template>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
|
||||
}
|
||||
</script>
|
||||
|
|
@ -9,6 +9,11 @@ const router = createRouter({
|
|||
name: 'home',
|
||||
component: HomeView,
|
||||
},
|
||||
{
|
||||
path: '/rp/new',
|
||||
name: 'new-reverser-proxy',
|
||||
component: 'NewReverseProxyView.vue'
|
||||
}
|
||||
/*
|
||||
{
|
||||
path: '/config',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
|
||||
|
||||
<template>
|
||||
<button class="btn btn-primary">"Test Button"</button>
|
||||
</template>
|
||||
|
|
@ -1,51 +1,18 @@
|
|||
<template>
|
||||
|
||||
<div class="container">
|
||||
<button class="btn btn-primary" @click="fetchCaddyConfig">Get Config</button>
|
||||
<br/>
|
||||
|
||||
<p> {{ myData }}</p>
|
||||
|
||||
<ReverseProxies />
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
import ReverseProxies from '../views/ReverseProxies.vue';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
myData: null,
|
||||
isLoading: false,
|
||||
error: null
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async fetchCaddyConfig() {
|
||||
this.isLoading = true;
|
||||
this.error = null;
|
||||
|
||||
let fetch_data = null;
|
||||
|
||||
fetch('http://localhost:2019/config/', {
|
||||
mode: 'cors',
|
||||
method: 'GET'
|
||||
})
|
||||
//.then(response => console.log(response))
|
||||
.then(response => response.json())
|
||||
//then(responseJson => fetch_data = responseJson)
|
||||
//.then(data => console.log(data))
|
||||
.then(data => {
|
||||
fetch_data = data;
|
||||
this.myData = data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
this.error = error;
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
components: {
|
||||
ReverseProxies
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<template>
|
||||
<div class="container">
|
||||
<h1>New Reverse Proxy</h1>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
<template>
|
||||
<div class="container">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-for="(header, index) in headers" :key="index">{{ header }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, rowIndex) in tableData" :key="rowIndex">
|
||||
<td>{{ item.id }}</td>
|
||||
<td>{{ item.hostname }}</td>
|
||||
<td>{{ item.servers }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<router-link to="new-reverse-proxy">
|
||||
<button class="btn btn-primary">Insert Reverse Proxy</button>
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import ButtonTest from '../views/ButtonTest.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
ButtonTest
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
caddyConfig: null,
|
||||
isLoading: false,
|
||||
error: null,
|
||||
reverse_proxy_routes: null,
|
||||
headers: [
|
||||
'#',
|
||||
'hostname',
|
||||
'routes'
|
||||
],
|
||||
tableData: []
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async fetchCaddyConfig() {
|
||||
this.isLoading = true;
|
||||
this.error = null;
|
||||
|
||||
let fetch_data = null;
|
||||
|
||||
try {
|
||||
const response = await fetch('http://localhost:2019/config/', {
|
||||
mode: 'cors',
|
||||
method: 'GET'
|
||||
});
|
||||
|
||||
if(!response.ok) {
|
||||
throw new Error('Error in fetch request');
|
||||
}
|
||||
|
||||
fetch_data = await response.json();
|
||||
this.caddyConfig = fetch_data;
|
||||
|
||||
} catch (error) {
|
||||
this.error = "Could not fetch Caddy Config: " + error.message;
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
},
|
||||
async filterCaddyConfig() {
|
||||
const apps = this.caddyConfig.apps;
|
||||
const routes = apps.http.servers.srv0.routes;
|
||||
|
||||
this.reverse_proxy_routes = searchBaseRoutes(routes);
|
||||
|
||||
},
|
||||
async createTableData() {
|
||||
let count = 1;
|
||||
for (let rp_key in this.reverse_proxy_routes) {
|
||||
this.tableData.push(
|
||||
{ id: count, hostname: rp_key, servers: this.reverse_proxy_routes[rp_key] }
|
||||
)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchCaddyConfig();
|
||||
|
||||
await this.filterCaddyConfig();
|
||||
|
||||
await this.createTableData();
|
||||
//console.log(this.reverse_proxy_routes);
|
||||
}
|
||||
}
|
||||
|
||||
function findReverseProxies(routes) {
|
||||
let rpArray = [];
|
||||
|
||||
for(let r_key in routes) {
|
||||
for (let h_key in routes[r_key].handle) {
|
||||
if (routes[r_key].handle[h_key].handler === 'reverse_proxy') {
|
||||
|
||||
for (let u_key in routes[r_key].handle[h_key].upstreams) {
|
||||
rpArray.push(routes[r_key].handle[h_key].upstreams[u_key].dial);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rpArray;
|
||||
}
|
||||
|
||||
function searchBaseRoutes(baseRoutes) {
|
||||
|
||||
let rp_dict = {};
|
||||
|
||||
for (let r_key in baseRoutes) {
|
||||
|
||||
let handles = baseRoutes[r_key].handle;
|
||||
let matches = baseRoutes[r_key].match;
|
||||
|
||||
let rp_servers = [];
|
||||
|
||||
for (let h_key in handles) {
|
||||
if (handles[h_key].handler === 'subroute') {
|
||||
rp_servers = findReverseProxies(handles[h_key].routes);
|
||||
}
|
||||
}
|
||||
|
||||
rp_dict[ matches[0].host ] = rp_servers;
|
||||
}
|
||||
|
||||
return rp_dict;
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue