summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/mv_vnc.py
blob: 36e263c815086bd501079374070febf4b229ad00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- 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
xhost + si:localuser:root
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 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")
        mv_common.pacremove("tigervnc")
    #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")
        mv_common.add_service("xvnc")
    else:
        mv_common.remove_service("xvnc")
        mv_common.pacremove("x11vnc")


    logging.info("__End of vnc\n")