Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions kasmvnc/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you bump the version in README.md by 1 minor version? Thanks.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ tags: [helper, vnc, desktop]

# KasmVNC

Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and create an app to access it via the dashboard.
Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and
create an app to access it via the dashboard.

```tf
module "kasmvnc" {
Expand All @@ -18,7 +19,12 @@ module "kasmvnc" {
version = "1.0.23"
agent_id = coder_agent.example.id
desktop_environment = "xfce"
subdomain = true
}
```

> **Note:** This module only works on workspaces with a pre-installed desktop environment. As an example base image you can use `codercom/enterprise-desktop` image.
> **Note:** This module only works on workspaces with a one of the following
> desktop environments pre-installed: `xfce`, `kde`, `gnome`, `lxde`, `lxqt`.

> The `codercom/enterprise-desktop` base image contains `xfce` and can be used
> as an example image.
41 changes: 10 additions & 31 deletions kasmvnc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,30 @@ terraform {
}
}

variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}

variable "port" {
type = number
description = "The port to run KasmVNC on."
default = 6800
}

variable "kasm_version" {
type = string
description = "Version of KasmVNC to install."
default = "1.3.2"
}

variable "desktop_environment" {
type = string
description = "Specifies the desktop environment of the workspace. This should be pre-installed on the workspace."
validation {
condition = contains(["xfce", "kde", "gnome", "lxde", "lxqt"], var.desktop_environment)
error_message = "Invalid desktop environment. Please specify a valid desktop environment."
}
locals {
template_data = object({
PORT = var.port,
DESKTOP_ENVIRONMENT = var.desktop_environment,
KASM_VERSION = var.kasm_version
SUBDOMAIN = tostring(var.subdomain)
})
}

resource "coder_script" "kasm_vnc" {
agent_id = var.agent_id
display_name = "KasmVNC"
icon = "/icon/kasmvnc.svg"
script = templatefile("${path.module}/run.sh", {
PORT : var.port,
DESKTOP_ENVIRONMENT : var.desktop_environment,
KASM_VERSION : var.kasm_version
})
run_on_start = true
script = templatefile("${path.module}/run.sh.tftpl", locals.template_data)
}

resource "coder_app" "kasm_vnc" {
agent_id = var.agent_id
slug = "kasm-vnc"
display_name = "kasmVNC"
display_name = "KasmVNC"
url = "http://localhost:${var.port}"
icon = "/icon/kasmvnc.svg"
subdomain = true
subdomain = var.subdomain
share = "owner"
healthcheck {
url = "http://localhost:${var.port}/app"
Expand Down
73 changes: 73 additions & 0 deletions kasmvnc/path_vnc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<title>Path-Sharing Bounce Page</title>
<style type="text/css">
:root {
color-scheme: light dark;
--dark: #121212;
--header-bg: rgba(127,127,127,0.2);
--light: white;
--rule-color: light-dark(rgba(0,0,0,0.8), rgba(255,255,255,0.8));
background-color: light-dark(var(--light), var(--dark));
color: light-dark(var(--dark), var(--light));
}
body, h1, p {
box-sizing: border-box;
margin:0; padding:0;
}
body{
font-family:Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
h1{
width: 100%;
padding: 1rem;
letter-spacing: -1.5pt;
padding-bottom:10px;
border-bottom: 1px solid var(--rule-color);
background-color: var(--header-bg);
}
p {
padding: 1rem; letter-spacing: -0.5pt;}
a.indent { display:inline-block; padding-top:0.5rem; padding-left: 2rem; font-size:0.8rem }
</style>
<meta charset="UTF-8" />
</head>
<body>
<h1>Path-Sharing Bounce Page</h1>
<p>
This application is being served via path sharing.
If you are not redirected, <span id="help">check the
Javascript console in your browser's developer tools
for more information.</span>
</p>
</body>
<script language="javascript">
// This page exists to satisfy the querystring driven client API
// specified here - https://raw.githubusercontent.com/kasmtech/noVNC/bce2d6a7048025c6e6c05df9d98b206c23f6dbab/docs/EMBEDDING.md
// tl;dr:
// * `host` - The WebSocket host to connect to.
// This is just the hostname component of the original URL
// * `port` - The WebSocket port to connect to.
// It doesn't look like we need to set this unless it's different
// than the incoming http request.
// * `encrypt` - If TLS should be used for the WebSocket connection.
// we base this on whether or not the protocol is `https`, seems
// reasonable for now.
// * `path` - The WebSocket path to use.
// This apparently doesn't tolerate a leading `/` so we use a
// function to tidy that up.
function trimFirstCharIf(str, char) {
return str.charAt(0) === char ? str.slice(1) : str;
}
const newloc = new URL(window.location);
const h = document.getElementById("help")
newloc.pathname+="vnc.html"
newloc.searchParams.append("path", trimFirstCharIf(newloc.pathname,"/")+"/websockify");
newloc.searchParams.append("encrypted", newloc.protocol==="https:"? true : false);
console.log(newloc);
h.innerHTML = `click <a id="link" href="${newloc.toString()}">here</a> to go to the application.
<br/><br/>The rewritten URL is:<br/><a id="link" class="indent" href="${newloc.toString()}">${newloc.toString()}</a>`
window.location = newloc.href;
</script>
</html>
Loading
Loading