Ejemplo n.º 1
0
    def make_file(self, binary=None):
        import tempfile

        currentTime = str(time.time())
        contentLength = self._environ.get("CONTENT_LENGTH", 0)
        # old style tempfile prefix and dest directory.
        prefix = "tmp_upload_%s_%s_" % (currentTime, contentLength)
        destDir = tempdirMap[""]
        # flush MSIE backslash debris, if any.
        basename = re.sub(r".*\\", "", self.filename or "")

        if self.name.startswith("__progress__.__"):
            try:
                instructions = self.name.split("__.__")
                destDir, tempName = instructions[1:3]
                destDir = tempdirMap[destDir]
            except Exception, info:
                OSUtils.log(
                    Logging.LOG_NOTICE,
                    "Error setting up destination directory and progress tag"
                    " for field %s (%s): %s" % (self.name, self.filename or "", str(info)),
                )
                self.tempfileerror = str(info)
            else:
                # new style tempfile prefix.
                prefix = "%s_%s_%s_" % (tempName, contentLength, basename)
Ejemplo n.º 2
0
 def defaultAction(self):
     try:
         transaction = self.transaction()
         response = transaction.response()
     except Exception, info:
         OSUtils.logException()
         return
Ejemplo n.º 3
0
 def defaultActionContent(self):
     pField = self.fields.get('p')
     if pField in self.dispatchList:
         getattr(self, pField)()
     else:
         OSUtils.log(Logging.LOG_NOTICE, 'Request error in gfx: %s' % pField)
         raise KeyError, 'Request error in gfx: %s' % pField
Ejemplo n.º 4
0
    def _respond(self, transaction):

        mgmt = self.session().value('mgmt')
        assert 'monitor' != mgmt.remoteUser.lower(), \
               'Monitor may not view or download logs.'
        # check permissions
        assert Nodes.permission(mgmt,
            '/logging/syslog/action/file/\/var\/log\/messages') != 'deny', \
            ('%s may not view or download logs.' % mgmt.remoteUser)

        request = transaction.request()
        response = transaction.response()
        fields = request.fields()
        logtype = fields.get('logtype', 'user')
        mime = fields.get('mime', '') or self.ContentType
        logfilename = '/var/log/%smessages' % self.LOGTYPE_PREFIX[logtype]
        try:
            bytesize = os.stat(logfilename)[stat.ST_SIZE]
            seekto = max(0, bytesize - 500)
            response.setHeader('Content-type', mime)
            response.commit()
            if mime.endswith('html'):
                response.write('<html>\n')
                response.write('<head>\n')
                response.write('<title>Continuous Log</title>\n')
                response.write('</head>\n')
                response.write('<body>\n')
                response.write('<pre>\n')
            response.flush(True)

            logfile = file(logfilename)
            logfile.seek(seekto) # Seek to almost EOF
            # Print out the last few lines of the log,
            # stripping out any partial line artifact of our seek()
            txt = cgi.escape(logfile.read() or '')
            txt = txt[txt.find('\n') + 1:]
            writingDots = 0
            # Write to log after seek so we should read it in the first
            # iteration of reading logfile.
            while hasattr(request, '_transaction') and \
                  2 < AppServerModule.globalAppServer._running:
                if txt:
                    if writingDots:
                        response.write('\n')
                        writingDots = 0
                    response.write(txt)
                else:
                    writingDots += 1
                    if 0 == writingDots % 80:
                        response.write('\n')
                    response.write('. ')
                    time.sleep(3)
                response.flush() # I don't trust auto flush
                txt = cgi.escape(logfile.read() or '')
        except ConnectionAbortedError:
            pass
        except:
            OSUtils.logException()
Ejemplo n.º 5
0
    def __init__(self):
        XHTMLPage.__init__(self)

        self.javascriptFiles = ['/yui3.js',
                                '/rollup.js']

        self.stylesheets = ['/yui3.css',
                            '/rollup.css',
                            '/styles-ie6.css',
                            '/styles-ie7.css',
                            '/rollup-product.css']
        self.css = '''
        #licenseMessage {
            width: 500px;
        }
        '''
        self.titleText = '%s Login' % OSUtils.hostname()
Ejemplo n.º 6
0
 def __init__(self):
     try:
         super(gfx, self).__init__()
     except Exception, info:
         OSUtils.logException()
         return
Ejemplo n.º 7
0
import sys
import traceback
import xml.dom

import Capability
import FormUtils
import Nodes
import OSUtils
import Logging
from GfxContent import GfxContent
from WebKit.Application import EndResponse
try:
    from support_report_gfx import gfx_Report
except Exception, info:
    OSUtils.logException()
    class gfx_Report: pass


# This servlet replies to requests of the form:
#    /sh/gfx?p=NAME
#
# And the response is XML.
#
# ("p" originally meant "page", but now it's a general purpose selector thing)
#
# XXX/robin How do we catch exceptions in instantiation of base classes?
class gfx(gfx_Report,
          GfxContent):

    # Each mixin class contributes their dispatches.
Ejemplo n.º 8
0
 def sendExportFile(self, filename):
     try:
         exfile = file(filename, 'rb')
     except IOError, info:
         OSUtils.logException()
         return
Ejemplo n.º 9
0
    def startStorageRedirectionService(self):

        hostname="";
        rc="";
        rmsg=""
        startVnc=0;

        vncPortFileName="/tmp/vncPortStorageRedirectionService";

        if(os.path.isfile(vncPortFileName)):

            fh=open(vncPortFileName,'rt');
            self.vncServerPort=fh.read();
            fh.close();
            self.vncServerPort=self.vncServerPort.strip();

            rc,hostname=OSUtils.ExecCmd("hostname",1);
            if(rc):
                raise OSCmdError("OS Command error");

            hostname=hostname.strip()

            rc,self.user=OSUtils.ExecCmd("whoami",1);
            if(rc):
                raise OSCmdError("OS Command error");

            self.user=self.user.strip()

            rc=OSUtils.isProcessRunning(hostname+":"+self.vncServerPort+"\s+\("+self.user+"\)");

            if (rc==0):
                self.logger.info("VNC session already running for port:"+str(self.vncServerPort));
            else:
                startVnc=1;

        else:

            startVnc=1;

        if (startVnc):

            ### Start vnc session for CDROM javaws
            rc,rmsg=OSUtils.ExecCmd("vncserver",1);
            if(rc):
                raise OSCmdError("OS Command error");

            matchObj = re.search(hostname+":(\d+)", rmsg, re.M|re.I)
            if matchObj:
                    self.vncServerPort=matchObj.group(1)
                    self.vncServerPort=self.vncServerPort.rstrip();
                    self.logger.debug("VNC Server Port is "+self.vncServerPort);
                    fh=open(vncPortFileName,'wt');
                    fh.write(self.vncServerPort);
                    fh.close();
            else:
                    self.logger.error("Unable to determine vnc port");
                    raise OSCmdError("Unable to determine vnc port");

        os.environ["DISPLAY"]=":"+self.vncServerPort+".0";
        cmd_str="xhost","+";
        rc,rmsg=OSUtils.ExecCmd(cmd_str,1);
        if(rc):
            raise OSCmdError("OS Command error");

        #/usr/java/jre1.6.0_45/bin/javaws -Xnoself.splash jnlpgenerator-cli
        cmd_str="nohup "+self.javaBinDir+"/javaws"+" -Xnoself.splash "+self.storageRedirBinDir+"/jnlpgenerator-cli &";

        self.logger.debug(cmd_str);
        os.system(cmd_str);
        time.sleep(30);                

        rc=self.isStorageRedirectionServiceRunning();
        if(rc):
                raise OSCmdError("Failed to start storage redirection service");
Ejemplo n.º 10
0
            self.mgmt.action('/stats/actions/export', *params)

            # hack ported from the old web ui that waits up to 30 seconds for the file to
            # finish being exported.
            if tField == 'false':
                i = 0
                while i < 30:
                    if os.path.exists(filename) == True:
                        break
                    time.sleep(1)
                    i += 1

                # Put together a nice filename for the user in this format:
                # hostname-date-time-report.csv
                browserFilename = '%s-%s-%s.csv' % \
                                  (OSUtils.hostname(), time.strftime('%Y%m%d-%H%M%S'), rField)

                response.setHeader('Content-Type', 'application/octet-stream')
                response.setHeader('Content-Disposition', 'attachment; filename=%s' % browserFilename)
                response.setHeader('Content-Length', os.stat(filename).st_size)
                self.sendExportFile(filename)
                os.unlink(filename)
            else:
                # This servlet doesn't inherit from PagePresentation, so we
                # can't use the handy setActionMessage() function to set an
                # action message.  Alas, we'll have to set the session value
                # and URL parameter manually.
                msg = cgi.escape('Report data emailed to %s.' % eField)
                msgid = str(self.request().requestID())
                self.session().setValue('msg_' + msgid, ([], [msg]))
                response.sendRedirect('/mgmt/gui?p=reportExports&_msg=%s' % msgid)