def render_content(self, ctx, data): mq = WebUtils.system('getent passwd | grep Computer') def gotResult(proc): comps = [] for i in proc.split('\n'): if i.strip('\n'): name = i.split(':')[0].strip('$') comps.append([ name, tags.a(href=url.root.child("Computers").child( "Delete").child(name), onclick="return confirm('%s');" % self.text.compConfirm)[tags.img( src="/images/ex.png")] ]) return comps res = wait(mq) yield res mq = res.getResult() getComputers = gotResult(mq) Utils.log.msg('%s opened Tools/Computers' % (self.avatarId.username)) yield ctx.tag[ tags.h3[tags.img(src='/images/srvman.png'), self.text.compHeading], tags.h3[self.text.compHeadingList], PageHelpers. dataTable([self.text.compName, ''], getComputers, sortable=True), tags.h3[self.text.compHeadingAdd], tags.directive('form addComputer'), ]
def system(e): from twisted.internet import utils #def procResult(e): # return e mq = utils.getProcessOutput('/bin/sh', ['-c', e], errortoo=1) #.addCallbacks(procResult, procResult) res = wait(mq) yield res yield res.getResult()
def system(e): from twisted.internet import utils #def procResult(e): # return e path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/tcs/tums" env = {'PATH': path, 'path': path, 'DEBIAN_FRONTEND': "noninteractive"} mq = utils.getProcessOutput('/bin/sh', ['-c', str(e)], env=env, errortoo=1) res = wait(mq) yield res yield res.getResult()
def systemCalls(self): # EMAIL if os.path.exists('/etc/debian_version'): debianMode = True else: debianMode = False proclist = [ "dhcpd", "squid", "apache2", "openvpn.vpn", "samba", "courier-imapd", "sshd" ] namelist = { "dhcpd": u"DHCP Server", "dhcp3-server": u"DHCP Server", "squid": u"Web Proxy", "squid3": u"Web Proxy", "apache2": u"Web Server", "openvpn.vpn": u"VPN Server", "openvpn": u"VPN Server", "samba": u"File Server", "courier-imapd": u"IMAP Mail Server", "courier-imap": u"IMAP Mail Server", "sshd": u"Secure Shell" } if Settings.Mailer == "exim": mq = utils.getProcessOutput(Settings.BaseDir + '/syscripts/mailQueue.sh', [], errortoo=1) res = wait(mq) yield res mq = res.getResult() mq = unicode(mq.strip('\n')).split() proclist.append('exim') namelist['exim'] = "Mail Server" namelist['exim4'] = "Mail Server" else: mq = utils.getProcessOutput(Settings.BaseDir + '/syscripts/postQueue.sh', [], errortoo=1) res = wait(mq) yield res mq = res.getResult() if not "is empty" in mq: post = mq.strip('\n').split() mq = [unicode(post[4]), u"%s %s" % (post[1], post[2])] else: mq = [u"0", u"0"] proclist.append('postfix') namelist['postfix'] = u"Mail Server" # PROCESS LISTS procstatus = [] for proc in proclist: if debianMode: # Remap package names for Debian if proc == "openvpn.vpn": checkproc = "openvpn" proc = "openvpn" elif proc == "courier-imapd": checkproc = "couriertcpd" proc = "courier-imap" elif proc == "samba": checkproc = "smbd" elif proc == "dhcpd": checkproc = "dhcpd" proc = "dhcp3-server" elif proc == "exim": proc = "exim4" checkproc = "exim" elif proc == "squid": proc = "squid3" checkproc = "squid" else: checkproc = proc stat = self.processCall( Settings.BaseDir + '/syscripts/debInitStat.sh', [checkproc]) else: stat = self.processCall( Settings.BaseDir + '/syscripts/initStat.sh', [proc]) res = wait(stat) yield res stat = res.getResult() if "started" in stat: procstatus.append( (u'/images/green.gif', unicode(namelist[proc]), (u'Running. Click to stop this service', url.root.child('Proc').child(proc).child('stop'), u'Running'))) elif "stop" in stat: procstatus.append( (u'/images/red.gif', unicode(namelist[proc]), (u'Not running. Click to start this service', url.root.child('Proc').child(proc).child('start'), u'Stopped'))) else: procstatus.append( (u'/images/horange.gif', unicode(namelist[proc]), (u'Can\'t tell the status. Click to force a restart', url.root.child('Proc').child(proc).child('restart'), u'Unknown'))) # DISK UTILL d = self.processCall(Settings.BaseDir + '/syscripts/diskUtil.sh') res = wait(d) yield res d = unicode(res.getResult()) filesystem = [] for i in d.split('\n'): f = unicode(i.strip('\n')).split() filesystem.append(f) d = self.processCall(Settings.BaseDir + '/syscripts/raidStat.sh') res = wait(d) yield res d = unicode(res.getResult()) raids = {} if not "No such file" in d: # Don't try if the raid doesn't exist... thisRaid = "" for i in d.split('\n'): l = i.strip().strip('\n') if l: line = l.split() if "md" in line[0]: thisRaid = line[0] raids[thisRaid] = [line[2], line[3], line[4:]] else: raids[thisRaid].append(line[3]) raidstat = [] for i in raids.keys(): thisRaid = [ unicode(i), unicode(raids[i][1]), u"%s %s" % (raids[i][0], raids[i][3]) ] smart = [] for i in raids[i][2]: s = self.processCall( Settings.BaseDir + '/syscripts/smartStat.sh', [i[:3]]) res = wait(s) yield res s = res.getResult() smart.append(u"%s: %s" % (i, s.strip('\n').replace( '=== START OF READ SMART DATA SECTION ===', ''))) thisRaid.append(smart) raidstat.append(thisRaid) # SAMBA SESSIONS s = self.processCall('/usr/bin/net', ['status', 'shares', 'parseable']) res = wait(s) yield res s = res.getResult() shares = {} for i in s.split('\n'): if i: l = unicode(i).split('\\') if not shares.get(l[3], None): shares[l[3]] = [] shares[l[3]].append(l[0]) del s s = self.processCall('/usr/bin/net', ['status', 'sessions', 'parseable']) res = wait(s) yield res s = res.getResult() sessions = [] for i in s.split('\n'): if i: l = i.split('\\') if shares.get(l[1], None): shareopen = [u'%s' % k for k in shares[l[1]]] else: shareopen = [u""] sessions.append([ unicode(l[1]), unicode(l[2]), u"%s (%s)" % (l[3], l[4]), shareopen ]) del s uptime = self.processCall('/usr/bin/uptime') res = wait(uptime) yield res s = res.getResult() uptime = s.strip('\n').split(',') time = unicode(uptime[0].split()[0]) up = unicode(' '.join(uptime[0].split()[2:4])) users = unicode(uptime[2].split()[0]) yield mq, procstatus, filesystem, raidstat, shares, sessions, time, up, users
def system(e): from twisted.internet import utils mq = utils.getProcessOutput('/bin/sh', ['-c', e], errortoo=1) res = wait(mq) yield res yield res.getResult()
def form_vpnForm(self, data): """ OpenVPN (TCS VPN) form""" form = formal.Form() form.addField('openvpn', formal.Boolean(), label = self.text.vpnLabelOpenvpn, description=self.text.vpnDescripOpenvpn) form.addField('iprange1', formal.String(required=True), label = self.text.vpnRangeStart) form.addField('iprange2', formal.String(required=True), label = self.text.vpnRangeTo) form.addField('mtu', formal.String(), label = self.text.vpnMTU) form.addField('WINS', formal.String(), label = self.text.vpnWINSServer) form.addField('DNS', formal.String(), label = self.text.vpnDNSServer) form.addField('DOMAIN', formal.String(), label = self.text.vpnDomain) mq = utils.getProcessOutput('/bin/sh', ['-c', "route -n | grep -E \"(eth|tun|tap)\" | grep -v \"G\" | awk '{print $1 \" \" $3}'"], errortoo=1) res = wait(mq) yield res routes = res.getResult() nr = [] for ro in routes.split('\n'): if ro.strip('\n'): nr.append(ro.strip()) routes = nr del nr try: confFile = open('/etc/openvpn/vpn.conf', 'rt') except: confFile = [""] activeRoutes = [] conf = {'mtu': '1400'} if os.path.exists('/etc/debian_version'): rc = utils.getProcessOutput(Settings.BaseDir + '/syscripts/rcStatus.py', [], errortoo=1) else: rc = utils.getProcessOutput('/bin/rc-status', ['default'], errortoo=1) res = wait(rc) yield res rc = res.getResult() vpnstat = "" for i in rc.split('\n'): if vpnInit in i: vpnstat = i if "openvpn" in vpnstat: conf['openvpn'] = True for i in confFile: line = i.strip('\n') if "route" in line: # Activate a route and add it to the list if not there route = line.split('"')[1].split() tr = "%s %s" % (route[1], route[2]) activeRoutes.append(tr.strip()) if not tr in routes: routes.append(tr.strip()) if "server-bridge" in line: ips = line.split() conf['iprange1'] = ips[3] conf['iprange2'] = ips[4] if "dhcp-option" in line: sp = line.replace('"','').split() conf[sp[2]] = sp[3] conf['routes'] = activeRoutes print conf form.addField('routes', formal.Sequence(formal.String()), formal.widgetFactory(formal.CheckboxMultiChoice, [(i,i) for i in routes]), label = self.text.vpnRoutesPush) form.data = conf form.addAction(self.submitForm) yield form