remove some console logs in the javascript
prometheus now listening on separate port fixed powershell command for setting up authorized keys.
This commit is contained in:
parent
85841bcb0f
commit
b4b962d859
@ -97,7 +97,6 @@ func main() {
|
||||
notifications := NewStateNotifier()
|
||||
admin := converge.NewAdmin(notifications)
|
||||
websessions := converge.NewWebSessions(notifications.webNotificationChannel)
|
||||
setupPrometheus(notifications.prometheusNotificationChannel)
|
||||
|
||||
// For agents connecting
|
||||
registrationService := websocketutil.WebSocketService{
|
||||
@ -166,6 +165,13 @@ func main() {
|
||||
|
||||
http.HandleFunc("/", catchAllHandler(contextpath))
|
||||
|
||||
// monitoring
|
||||
mux := http.NewServeMux()
|
||||
setupPrometheus(mux, notifications.prometheusNotificationChannel)
|
||||
go func() {
|
||||
log.Fatal(http.ListenAndServe(":8001", mux))
|
||||
}()
|
||||
|
||||
// Start HTTP server
|
||||
fmt.Println("Rendez-vous server listening on :8000")
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
|
@ -86,14 +86,14 @@ func clientActive(client models.Client) {
|
||||
clientInfo.With(clientLabels(client)).Set(1)
|
||||
}
|
||||
|
||||
func setupPrometheus(notifications chan *models.State) {
|
||||
func setupPrometheus(mux *http.ServeMux, notifications chan *models.State) {
|
||||
go func() {
|
||||
for {
|
||||
state := <-notifications
|
||||
updateMetrics(state)
|
||||
}
|
||||
}()
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
mux.Handle("/metrics", promhttp.Handler())
|
||||
}
|
||||
|
||||
func updateMetrics(state *models.State) {
|
||||
|
@ -32,9 +32,10 @@ func generateCLIExammple(w http.ResponseWriter, r *http.Request) {
|
||||
access := getConvergeAccess(r)
|
||||
|
||||
downloadCommand := r.FormValue("download-command")
|
||||
|
||||
certificateValidation := r.FormValue("certificate-validation") != ""
|
||||
sshPublicKeys := strings.Split(keysString, "\n")
|
||||
usageInputs := templates.NewUsageInputs(id, sshPublicKeys, remoteShells, localShells, downloadCommand)
|
||||
usageInputs := templates.NewUsageInputs(id, sshPublicKeys, remoteShells, localShells, downloadCommand,
|
||||
certificateValidation)
|
||||
matched, _ := regexp.MatchString("^[a-zA-Z0-9-_]+$", id)
|
||||
if !matched {
|
||||
usageInputs.ErrorMessages = append(usageInputs.ErrorMessages, "ID may consist only of alphanumeric characters, '-', and '_'")
|
||||
|
@ -4,7 +4,6 @@ metadata:
|
||||
labels:
|
||||
app: converge
|
||||
name: converge
|
||||
namespace: wamblee-org
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
@ -22,5 +21,7 @@ spec:
|
||||
name: converge
|
||||
ports:
|
||||
- containerPort: 8000
|
||||
|
||||
name: http
|
||||
- containerPort: 8001
|
||||
name: prometheus
|
||||
|
||||
|
@ -9,5 +9,8 @@ spec:
|
||||
- port: 8000
|
||||
protocol: TCP
|
||||
targetPort: 8000
|
||||
- port: 8001
|
||||
protocol: TCP
|
||||
targetPort: prometheus
|
||||
selector:
|
||||
app: converge
|
||||
|
@ -49,7 +49,6 @@ templ BasePage(tab int) {
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
}
|
||||
if (!window.originalWebSocket) {
|
||||
console.log("timezone override for websockets")
|
||||
window.originalWebSocket = htmx.createWebSocket
|
||||
htmx.createWebSocket = function(url) {
|
||||
url = new URL(url, window.location.href).href
|
||||
@ -62,7 +61,7 @@ templ BasePage(tab int) {
|
||||
document.body.addEventListener(
|
||||
"htmx:configRequest",
|
||||
function(evt) {
|
||||
console.log("Adding timezone to htmx request headers and making URL absolute");
|
||||
//console.log("Adding timezone to htmx request headers and making URL absolute");
|
||||
evt.detail.headers["X-Timezone"] = getTimezone();
|
||||
}
|
||||
);
|
||||
|
@ -19,23 +19,23 @@ templ AgentUsage(access models.ConvergeAccess, usageInputs UsageInputs) {
|
||||
|
||||
if usageInputs.RemoteShells[BASH] {
|
||||
<code-sample id="run-agent-bash">@templ.Raw(addSshKeys(BASH, usageInputs.SshKeys)) <br/>
|
||||
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent http{access.Secure}://{access.BaseUrl}/downloads/agent<br/>
|
||||
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent {GetDownloadSecureOption(usageInputs)} http{access.Secure}://{access.BaseUrl}/downloads/agent<br/>
|
||||
chmod 755 agent <br/>
|
||||
./agent --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl}<br/>
|
||||
./agent {GetAgentSecureOption(usageInputs)} --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl}<br/>
|
||||
rm -f agent <br/>
|
||||
</code-sample>
|
||||
}
|
||||
if usageInputs.RemoteShells[CMD] {
|
||||
<code-sample id="run-agent-cmd">@templ.Raw(addSshKeys(CMD, usageInputs.SshKeys)) <br/>
|
||||
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent.exe http{access.Secure}://{access.BaseUrl}/downloads/agent.exe <br/>
|
||||
.\agent --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl} <br/>
|
||||
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent.exe {GetDownloadSecureOption(usageInputs)} http{access.Secure}://{access.BaseUrl}/downloads/agent.exe <br/>
|
||||
.\agent {GetAgentSecureOption(usageInputs)} --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl} <br/>
|
||||
del agent.exe <br/>
|
||||
</code-sample>
|
||||
}
|
||||
if usageInputs.RemoteShells[POWERSHELL] {
|
||||
<code-sample id="run-agent-powershell">@templ.Raw(addSshKeys(POWERSHELL, usageInputs.SshKeys)) <br/>
|
||||
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent.exe http{access.Secure}://{access.BaseUrl}/downloads/agent.exe <br/>
|
||||
.\agent --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl} <br/>
|
||||
{DOWNLOAD_COMMAND[usageInputs.DownloadCommand]} agent.exe {GetDownloadSecureOption(usageInputs)} http{access.Secure}://{access.BaseUrl}/downloads/agent.exe <br/>
|
||||
.\agent {GetAgentSecureOption(usageInputs)} --id {usageInputs.Id} ws{access.Secure}://{access.BaseUrl} <br/>
|
||||
del agent.exe <br/>
|
||||
</code-sample>
|
||||
}
|
||||
@ -190,6 +190,12 @@ templ Usage(access models.ConvergeAccess) {
|
||||
<input id="download-command-1" name="download-command" type="radio" value={WGET}> <label for="download-command-1">wget</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="minimal-width"><label for="certificate-validation">certificate validation</label></td>
|
||||
<td>
|
||||
<input checked id="certificate-validation-0" name="certificate-validation" type="checkbox" checked> <label for="certificate-validation-0"></label>
|
||||
</td>
|
||||
</tr>
|
||||
<!--tr>
|
||||
<td class="minimal-width"><label for="local-shell">local environment</label></td>
|
||||
<td>
|
||||
@ -250,7 +256,7 @@ templ Usage(access models.ConvergeAccess) {
|
||||
}
|
||||
|
||||
function loadFormFromCookie() {
|
||||
console.log("Load form from cookie")
|
||||
//console.log("Load form from cookie")
|
||||
const form = document.getElementById('inputs');
|
||||
if (!form) {
|
||||
return
|
||||
@ -264,20 +270,17 @@ templ Usage(access models.ConvergeAccess) {
|
||||
if (element.type === 'checkbox') {
|
||||
newvalue = value === "true"
|
||||
if (element.checked != newvalue) {
|
||||
console.log("Setting " + element.id + " checked " + newvalue)
|
||||
element.checked = newvalue
|
||||
updated = true
|
||||
}
|
||||
} else if (element.type === 'radio') {
|
||||
newvalue = element.value === value
|
||||
if (element.checked != newvalue) {
|
||||
console.log("Setting " + element.id + " selected " + newvalue)
|
||||
element.checked = newvalue;
|
||||
updated = true
|
||||
}
|
||||
} else {
|
||||
if (element.value != value) {
|
||||
console.log("Setting " + element.id + " " + element.value + " -> " + value)
|
||||
element.value = value;
|
||||
updated = true
|
||||
}
|
||||
@ -286,7 +289,6 @@ templ Usage(access models.ConvergeAccess) {
|
||||
}
|
||||
}
|
||||
if (updated) {
|
||||
console.log("Sending htmx event to trigger form")
|
||||
htmx.trigger(form, 'formdataloaded')
|
||||
}
|
||||
}
|
||||
@ -295,12 +297,12 @@ templ Usage(access models.ConvergeAccess) {
|
||||
document.getElementById('inputs').addEventListener('change', saveFormToCookie);
|
||||
|
||||
document.body.addEventListener('htmx:load', function(event) {
|
||||
console.log("htmx:load")
|
||||
//console.log("htmx:load")
|
||||
loadFormFromCookie();
|
||||
});
|
||||
|
||||
document.body.addEventListener('htmx:afterSettle', function(event) {
|
||||
console.log("htmx:afterSettle")
|
||||
//console.log("htmx:afterSettle")
|
||||
loadFormFromCookie();
|
||||
});
|
||||
|
||||
|
@ -9,19 +9,22 @@ type UsageInputs struct {
|
||||
SshKeys []string
|
||||
ErrorMessages []string
|
||||
|
||||
RemoteShells map[string]bool
|
||||
LocalShells map[string]bool
|
||||
DownloadCommand string
|
||||
RemoteShells map[string]bool
|
||||
LocalShells map[string]bool
|
||||
DownloadCommand string
|
||||
CertificateValidation bool
|
||||
}
|
||||
|
||||
func NewUsageInputs(id string, sshPublicKeys []string, remoteShells []string, localShells []string,
|
||||
downloadCommand string) UsageInputs {
|
||||
downloadCommand string,
|
||||
certificateValidation bool) UsageInputs {
|
||||
inputs := UsageInputs{
|
||||
Id: id,
|
||||
SshKeys: sshPublicKeys,
|
||||
RemoteShells: make(map[string]bool),
|
||||
LocalShells: make(map[string]bool),
|
||||
DownloadCommand: downloadCommand,
|
||||
Id: id,
|
||||
SshKeys: sshPublicKeys,
|
||||
RemoteShells: make(map[string]bool),
|
||||
LocalShells: make(map[string]bool),
|
||||
DownloadCommand: downloadCommand,
|
||||
CertificateValidation: certificateValidation,
|
||||
}
|
||||
for _, remoteShell := range remoteShells {
|
||||
inputs.RemoteShells[remoteShell] = true
|
||||
@ -33,6 +36,7 @@ func NewUsageInputs(id string, sshPublicKeys []string, remoteShells []string, lo
|
||||
}
|
||||
|
||||
func addSshKeys(shell string, keys []string) string {
|
||||
|
||||
quote := `"`
|
||||
if shell == CMD {
|
||||
quote = ""
|
||||
@ -43,8 +47,12 @@ func addSshKeys(shell string, keys []string) string {
|
||||
if index == 0 {
|
||||
operator = ">"
|
||||
}
|
||||
res += fmt.Sprintf(" echo %s%s%s %s .authorized_keys<br/>", quote, key, quote,
|
||||
operator)
|
||||
if shell == POWERSHELL {
|
||||
res += fmt.Sprintf(`"%s" | Out-File -FilePath ".authorized_keys" -Encoding ASCII<br/>`, key)
|
||||
} else {
|
||||
res += fmt.Sprintf(" echo %s%s%s %s .authorized_keys<br/>", quote, key, quote,
|
||||
operator)
|
||||
}
|
||||
}
|
||||
return res + " "
|
||||
}
|
||||
@ -55,3 +63,24 @@ func formControlTextClass(message string) string {
|
||||
}
|
||||
return "form-control is-invalid"
|
||||
}
|
||||
|
||||
func GetDownloadSecureOption(inputs UsageInputs) string {
|
||||
switch inputs.DownloadCommand {
|
||||
case CURL:
|
||||
if !inputs.CertificateValidation {
|
||||
return "-k"
|
||||
}
|
||||
case WGET:
|
||||
if !inputs.CertificateValidation {
|
||||
return "--no-check-certificate"
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func GetAgentSecureOption(inputs UsageInputs) string {
|
||||
if inputs.CertificateValidation {
|
||||
return ""
|
||||
}
|
||||
return "--insecure"
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ class CopyToClipboardComponent extends HTMLElement {
|
||||
if (fromElement) {
|
||||
navigator.clipboard.writeText(fromElement.innerText)
|
||||
.then(() => {
|
||||
console.log('Content copied to clipboard');
|
||||
this.render(CopyToClipboardComponent.ACTIVE)
|
||||
setTimeout((target) => {
|
||||
this.render(CopyToClipboardComponent.IN_ACTIVE)
|
||||
@ -67,7 +66,6 @@ class CodeSampleComponent extends HTMLElement {
|
||||
let id = this.getAttribute("id");
|
||||
let html = "<div class='small ps-5'><copy-to-clipboard from='" + id + "'></copy-to-clipboard></div>";
|
||||
html += "<p class='font-monospace small ps-5' id='" +id + "' >" + this.innerHTML + "</p>";
|
||||
console.log("html=" + html);
|
||||
this.innerHTML = html;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user