Working to update finding reverse proxies
This commit is contained in:
parent
769b44c494
commit
19e106fb58
|
|
@ -6,11 +6,16 @@
|
|||
<p>{{ caddyConfig }}</p>
|
||||
|
||||
<ButtonTest />
|
||||
|
||||
<br />
|
||||
|
||||
<button type="button" class="btn btn-secondary" @click="filterCaddyConfig(fetch_data)">Filter Caddy Config</button>
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import ButtonTest from '../views/ButtonTest.vue';
|
||||
|
||||
export default {
|
||||
|
|
@ -21,7 +26,9 @@ import ButtonTest from '../views/ButtonTest.vue';
|
|||
return {
|
||||
caddyConfig: null,
|
||||
isLoading: false,
|
||||
error: null
|
||||
error: null,
|
||||
reverse_proxy_routes: null
|
||||
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -48,27 +55,156 @@ import ButtonTest from '../views/ButtonTest.vue';
|
|||
console.error(error);
|
||||
}
|
||||
|
||||
},
|
||||
filterCaddyConfig() {
|
||||
const apps = this.caddyConfig.apps;
|
||||
const routes = apps.http.servers.srv0.routes;
|
||||
|
||||
//let reverse_proxy_array = [];
|
||||
|
||||
/*
|
||||
fetch('http://localhost:2019/config/', {
|
||||
mode: 'cors',
|
||||
method: 'GET'
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
fetch_data = data;
|
||||
this.myData = data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
this.error = error;
|
||||
}
|
||||
);
|
||||
for (let key in routes) {
|
||||
|
||||
}
|
||||
*/
|
||||
//console.log(routes);
|
||||
//console.log("Filtering Caddy Config");
|
||||
//findRps(routes);
|
||||
let rp_dict = findRPRecursively(routes);
|
||||
console.log(rp_dict);
|
||||
}
|
||||
|
||||
},
|
||||
mounted() {
|
||||
this.fetchCaddyConfig();
|
||||
}
|
||||
}
|
||||
|
||||
function findRps(routes) {
|
||||
console.log ("Searching for reverse_proxy");
|
||||
// We're interested in routes and handlers. We specifically want subroutes and reverse_proxy handler
|
||||
|
||||
// routes are lists of handles
|
||||
// handles are lists of routes
|
||||
// subroute handler will have a routes list of more handles
|
||||
|
||||
let rpDictionary = {};
|
||||
|
||||
for(let r_key in routes) {
|
||||
// In each route, we'll look at the first layer of handles
|
||||
// Actually, we need to find subroute, since subroute is what holds the reverse_proxy!
|
||||
|
||||
// Then in each route, search for the match list to get the hosts (only if first layer reverse_proxy is found)
|
||||
//let rp_found = false;
|
||||
// Loop over handle list
|
||||
var caddy_rp = null;
|
||||
var caddy_hn = null;
|
||||
|
||||
for(let h_key in routes[r_key].handle){
|
||||
// Check if the route.handle.handler == "subroute"
|
||||
let rp_found = false;
|
||||
if( routes[r_key].handle[h_key].handler === "subroute" ) {
|
||||
console.log(routes[r_key].handle[h_key]);
|
||||
for(let r2_key in routes[r_key].handle[h_key].routes) {
|
||||
for(let h2_key in routes[r_key].handle[h_key].routes[r_key].handler){
|
||||
if ( routes[r_key].handle[h_key].routes[r_key].handle[h2_key].handler === "reverse_proxy") {
|
||||
//let x = routes[r_key].handle[h_key].routes[r2_key].handle[h2_key].upstreams[0].dial;
|
||||
caddy_rp = routes[r_key].handle[h_key].routes[r2_key].handle[h2_key].upstreams[0].dial;
|
||||
//console.log("reverse proxy found. Address is: " + x);
|
||||
rp_found = true;
|
||||
}
|
||||
if(rp_found === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(rp_found === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
caddy_hn = routes[r_key].match[0].host[0];
|
||||
rpDictionary[caddy_hn] = caddy_rp;
|
||||
console.log(`Hostname ${caddy_hn} will be proxied to ${caddy_rp}`);
|
||||
//if(rp_found === true){
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
//console.log("rp hostname is " + routes[r_key].match[0].host[0]);
|
||||
|
||||
//if (rp_found === true) {
|
||||
// break;
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
// We need to find the handle in all of these (most likely the base route at this point in time)
|
||||
|
||||
// Search through the K-V pairs. Look for the 'Handle' key. This is a list
|
||||
// Search this List for handler 'subroute'
|
||||
// If it exists, look at the routes list it contains
|
||||
// Search handle list
|
||||
}
|
||||
|
||||
// Look to expand and use recursion by searching routes and handles. Can have two separate functions
|
||||
|
||||
function findRPRecursively(routes) {
|
||||
console.log("Searching recursively!");
|
||||
console.log(routes);
|
||||
let rpDictionary = {};
|
||||
for (let r_key in routes) {
|
||||
for (let h_key in routes[r_key].handle){
|
||||
|
||||
let handle = routes[r_key].handle[h_key];
|
||||
|
||||
if (handle.handler === "subroute"){
|
||||
console.log("Found subroute!");
|
||||
findRPRecursively(routes[r_key].handle[h_key].routes)
|
||||
}
|
||||
if (handle.handler === 'reverse_proxy'){
|
||||
console.log("Found reverse proxy!");
|
||||
console.log(routes)
|
||||
let host = routes[r_key].match.host;
|
||||
rpDictionary[host] = handle.upstreams[0].dial;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rpDictionary
|
||||
}
|
||||
|
||||
|
||||
// So what we should do: break apart the routes into handlers and matches. First search the handlers to see if you find subroute or rp.
|
||||
// Then match the array of those upstreams with the match value
|
||||
function findReverseProxies(routes) {
|
||||
|
||||
let rpArray = [];
|
||||
|
||||
for(r_key in routes) {
|
||||
for (let h_key in routes[r_key].handles) {
|
||||
if (routes[r_key].handles[h_key].handler === 'reverse_proxy') {
|
||||
for (let u_key in routes[r_key].handles[h_key].upstreams) {
|
||||
rpArray.push(routes[r_key].handles[h_key].upstreams[u_key].dial);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rpArray;
|
||||
}
|
||||
|
||||
function searchBaseRoutes(baseRoutes) {
|
||||
let handles = routes.handle;
|
||||
let matches = routes.match;
|
||||
|
||||
for (let h_key in handles) {
|
||||
console.log(h_key);
|
||||
if (handles[h_key] === 'subroute') {
|
||||
let rp_servers = findReverseProxies(handles[h_key].routes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue