# -*- coding: utf-8 -*- import logging, mv_common import os, re config_file = "mv_config" def setupvnc_system(systemconfig,data_config): logging.info("____Start of vnc setup____") mv_common.pacinstall("tigervnc") vncdir=data_config.VNCHOME+"/.vnc" try: os.makedirs(vncdir) os.chown(vncdir,78,78) except: logging.info(" couldn't create vnc dir:%s" %vncdir) vncfile="%s/xstartup" %vncdir file_contents=''' #!/bin/bash xhost + localhost xhost + 127.0.0.1 vncconfig -iconic & if [ ! -e ~GNUstep ] then wmaker.inst cp -f /usr/share/wm_data/GNUstep/Defaults/WindowMaker ~/GNUstep/Defaults/ cp -f /usr/share/wm_data/GNUstep/Defaults/WMState.vnc ~/GNUstep/Defaults/WMState cp -f /usr/share/wm_data/GNUstep/Defaults/WMWindowAttributes ~/GNUstep/Defaults/ cp -f /usr/share/wm_data/GNUstep/Defaults/WMRootMenu ~/GNUstep/Defaults/ fi exec wmaker ''' try: logging.debug(" Writing %s",vncfile) f= open(vncfile,'w') f.write(file_contents) f.close() os.chmod(vncfile,0755) except: logging.debug(" Couldn't open %s",vncfile) logging.debug(" Aborting vnc...") try: vncuid = pwd.getpwnam('vncsvc')[2] vncgid = pwd.getpwnam('vncsvc')[3] except: logging.critical("* vncsvc not found") vncuid = '78' vncgid = '78' cmd="setfacl -m u:vncsvc:x %s" %data_config.MYTHHOME mv_common.runcmd(cmd) srcmyth="%s/.mythtv" %data_config.MYTHHOME destmyth="%s/.mythtv" %data_config.VNCHOME mv_common.link_file(srcmyth,destmyth) #mv_common.mkdir_mythhome(data_config.VNCHOME,vncuid,vncgid) #home_xml_file=data_config.VNCHOME + "/.mythtv/config.xml" #configxml_file="/usr/share/mythtv/config.xml" #mv_common.link_file(configxml_file,home_xml_file) logging.info(" Writing out password") vncpassfile="%s/passwd" %vncdir cmd="echo %s|vncpasswd -f > %s" %(systemconfig.get("vncpassword"),vncpassfile) mv_common.runcmd(cmd) cmd="chmod 700 %s" %vncpassfile mv_common.runcmd(cmd) cmd="chown vncsvc %s" %vncpassfile mv_common.runcmd(cmd) logging.info("__End of vnc \n") def start_xvnc(xvncpasswd): logging.info(" Checking if x11vnc needs to be started") if mv_common.check_service("frontend"): logging.info(" Frontend is running, starting x11vnc") line='''su mythtv -c "DISPLAY=localhost:0 x11vnc -rfbport 5902 --passwd %s 2>&1 > /dev/null &" \n''' %xvncpasswd #line='''su mythtv -c "DISPLAY=localhost:0 xscreensaver -no-splash \&" ''' try: fout = open("/tmp/cmd.sh", "w") fout.write(line) fout.close() os.chmod("/tmp/cmd.sh",0755) cmd="/tmp/cmd.sh" os.system(cmd) os.remove("/tmp/cmd.sh") except: logging.info(" Couldn't start x11vnc") def setupvnc(systemconfig,data_config): logging.info("____Start of vnc config ____") if mv_common.read_config(mv_common.module_config,"vnc") == False : logging.info("____Skipping of vnc, config disabled____") return #vncservice try: vnc=systemconfig.get("vncenable") except: vnc = "0" if vnc == "1": logging.info(" Installing vnc system\n") setupvnc_system(systemconfig,data_config) mv_common.add_service("vnc") else: mv_common.remove_service("vnc") #x11vnc try: xvnc=systemconfig.get("xvncenable") xvncpasswd=systemconfig.get("xvncpassword") except: xvnc = "0" xvncpassword="LinHES" if xvnc == "1": logging.info(" Installing x11vnc system\n") mv_common.pacinstall("x11vnc") start_xvnc(xvncpasswd) else: mv_common.pacinstall("x11vnc") logging.info("__End of vnc\n")