Skip to content

Commit

Permalink
Update VNC passwd create & parse commands for Debian Bookworm compati…
Browse files Browse the repository at this point in the history
…bility (junhaoliao#29)
  • Loading branch information
li-ruihao authored Jul 22, 2024
1 parent 5c7ce90 commit eb4b780
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 13 additions & 10 deletions application/features/VNC.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

import logging
import os
import re
import threading

from .Connection import Connection
from .mywebsockify import MyProxyRequestHandler, MySSLProxyServer
from .vncpasswd import decrypt_passwd, obfuscate_password
from ..resources.xstartup import XSTARTUP_STR
from .vncpasswd import decrypt_passwd
from ..utils import find_free_port

logger = logging.getLogger(__name__)


def websocket_proxy_thread(local_websocket_port, local_vnc_port):
if os.environ.get('SSL_CERT_PATH') is None:
Expand Down Expand Up @@ -65,8 +67,8 @@ def connect(self, *args, **kwargs):
return super().connect(*args, **kwargs)

def get_vnc_password(self):
_, _, stdout, _ = self.exec_command_blocking('xxd -p ~/.vnc/passwd')
hexdump = stdout.readline()
_, _, stdout, _ = self.exec_command_blocking("hexdump --format '16/1 \"%02x\"' ~/.vnc/passwd")
hexdump = stdout.readline().rstrip()
if hexdump == '':
return False, ''
else:
Expand Down Expand Up @@ -96,8 +98,6 @@ def remove_vnc_settings(self):
return True, ''

def reset_vnc_password(self, password):
hexed_passwd = obfuscate_password(password).hex()

reset_cmd_lst = [
# killall -q: don't complain if no process found
# -w: wait until the processes to die then continue to the next cmd
Expand All @@ -108,16 +108,19 @@ def reset_vnc_password(self, password):
"rm -rf ~/.vnc",
"mkdir ~/.vnc",

f"printf '{XSTARTUP_STR}' > ~/.vnc/xstartup",
"cp /etc/vnc/xstartup ~/.vnc >& /dev/null",
"chmod 700 ~/.vnc/xstartup",
# FIXME: re-enable xstartup config
# f"printf '{XSTARTUP_STR}' > ~/.vnc/xstartup",
# "cp /etc/vnc/xstartup ~/.vnc >& /dev/null",
# "chmod 700 ~/.vnc/xstartup",

"echo '%s'| xxd -r -p > ~/.vnc/passwd" % hexed_passwd,
"echo '%s'| vncpasswd -f > ~/.vnc/passwd" % password,
"chmod 600 ~/.vnc/passwd",
]
_, _, _, stderr = self.exec_command_blocking(';'.join(reset_cmd_lst))
error_lines = []
for line in stderr:
logger.error("reset_vnc_password::exec_command_blocking stderr line: %s", line)

if "Disk quota exceeded" in line:
return False, 'Disk quota exceeded'
else:
Expand Down
6 changes: 6 additions & 0 deletions application/routes/vnc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# IN THE SOFTWARE.

import json
import logging

from flask import request, abort, stream_with_context

Expand All @@ -27,6 +28,8 @@
from ..codes import ICtrlStep, ICtrlError, ConnectionType
from ..utils import int_to_bytes

logger = logging.getLogger(__name__)


@api.route('/vnc', methods=['POST'])
def start_vnc():
Expand Down Expand Up @@ -101,11 +104,14 @@ def change_vncpasswd():

vnc, reason = create_connection(session_id, ConnectionType.VNC)
if reason != '':
logger.error("create_connection() failed with status=", status)
abort(403, description=reason)

passwd = request.json.get('passwd')
status, reason = vnc.reset_vnc_password(passwd)

if not status:
logger.error("reset_vnc_password() failed with status=%s", reason)
abort(403, description=reason)

return 'success'
Expand Down

0 comments on commit eb4b780

Please sign in to comment.