Exemplo n.º 1
0
    def handleList(self, confInfo):
        args = self.callerArgs.data
        path = self.callerArgs.id
        names = []
        allowFolders = allowFiles = True

        if ALLOW_FOLDER_SELECTION in args:
            allowFolders = bp.parse_boolean(args[ALLOW_FOLDER_SELECTION][0])
        if ALLOW_FILE_SELECTION in args:
            allowFiles = bp.parse_boolean(args[ALLOW_FILE_SELECTION][0])

        if not path:
            if sys.platform.startswith('win'):
                import win32api
                names = [
                    drive for drive in win32api.GetLogicalDriveStrings().split(
                        '\000') if drive
                ]
                path = ''
            else:
                path = '/'
                try:
                    names = sorted(os.listdir(path))
                except Exception, e:
                    raise admin.ArgValidationException(e)
Exemplo n.º 2
0
    def handleCreate(self, confInfo):
        confInfo.addDeprecationMsg()
        location = self.callerArgs.id

        force = False
        if FORCE in self.callerArgs:
            force = bundle_paths.parse_boolean(self.callerArgs[FORCE][0])

        try:
            bundle, status = appbuilder.installApp(location, force)
        except splunk.RESTException as e:
            raise admin.InternalException(e.msg)

        upgraded = (status == bundle_paths.BundleInstaller.STATUS_UPGRADED)

        appName = bundle.name(raw=True) or ''
        confInfo[appName].append('name', appName)
        confInfo[appName].append('location', bundle.location() or '')
        confInfo[appName].append('status',
                                 'upgraded' if upgraded else 'installed')
        confInfo[appName].append('source_location', location)

        if not upgraded:
            reloader = 'apps/local/_reload'
        else:
            reloader = 'apps/local/%s/_reload' % urllib.quote(bundle.name())
        rest.simpleRequest(reloader, sessionKey=self.getSessionKey())
Exemplo n.º 3
0
    def handleCreate(self, confInfo):
        location = self.callerArgs.id

        force = False
        if FORCE in self.callerArgs:
            force = bundle_paths.parse_boolean(self.callerArgs[FORCE][0])

        try:
            bundle, status = appbuilder.installApp(location, force)
        except splunk.RESTException, e:
            raise admin.InternalException(e.msg)
Exemplo n.º 4
0
class RemoteAppsSetup(splunk.rest.BaseRestHandler):

    """
    Prepare remote applications management based on configuration settings.
    """

    def __init__(self, method, requestInfo, responseInfo, sessionKey):
        splunk.rest.BaseRestHandler.__init__(self,
                                            method,
                                            requestInfo,
                                            responseInfo,
                                            sessionKey)
        # Default values
        self._allowRemote = True
        self._login = LOGIN_URL
        self._base = DEFAULT_URL
        self._agent = None
        self._platformInfo = None
        try:
            platform_info = platform.platform()
            os_name = platform.system()
            arch = platform.machine()
            py_ver = urllib.URLopener().version
            with open(os.path.join(bundle_paths.etc(), "splunk.version")) as f:
                for i in f:
                    if i.startswith("VERSION"):
                        version = i.split("=")[1].strip().strip('"')
                    elif i.startswith("BUILD"):
                        build = i.split("=")[1].strip()
            self._agent = "Splunkd/%s (%s; version=%s; arch=%s; build=%s; %s)" % (version, os_name, platform_info, arch, build, py_ver)
            self._platformInfo = {'version': version, 'platform': os_name}
        except Exception, e:
            logger.exception(e)
        # Manual overrides in server.conf
        try:
            conf = bundle.getConf("server", self.sessionKey)
            s = conf["applicationsManagement"]
            if not s.isDisabled():
                if s.has_key("allowInternetAccess"):
                    self._allowRemote = bundle_paths.parse_boolean(s["allowInternetAccess"])
                if s.has_key("loginUrl"):
                    self._login = s["loginUrl"]
                if s.has_key("url"):
                    self._base = s["url"]
                if s.has_key("useragent"):
                    self._agent = s["useragent"]
        except:
            pass
        logger.debug("applicationsManagement.allowInternetAccess = %s" % str(self._allowRemote))
        logger.debug("applicationsManagement.loginUrl = %s" % self._login)
        logger.debug("applicationsManagement.url = %s" % self._base)
        logger.debug("applicationsManagement.useragent = %s" % self._agent)
Exemplo n.º 5
0
    def handleList(self, confInfo):
        args = self.callerArgs.data
        path = self.callerArgs.id
        names = []
        allowFolders = allowFiles = True

        if ALLOW_FOLDER_SELECTION in args:
            allowFolders = bp.parse_boolean(args[ALLOW_FOLDER_SELECTION][0])
        if ALLOW_FILE_SELECTION in args:
            allowFiles = bp.parse_boolean(args[ALLOW_FILE_SELECTION][0])
            
        if not path:
            if sys.platform.startswith('win'):
                import win32api
                names = [drive for drive in win32api.GetLogicalDriveStrings().split('\000') if drive]
                path = ''
            else:
                path = '/'
                try:
                    names = sorted(os.listdir(path))
                except Exception, e:
                    raise admin.ArgValidationException(e)
Exemplo n.º 6
0
 def __init__(self, method, requestInfo, responseInfo, sessionKey):
     splunk.rest.BaseRestHandler.__init__(self, method, requestInfo,
                                          responseInfo, sessionKey)
     # Default values
     self._allowRemote = True
     self._login = LOGIN_URL
     self._base = DEFAULT_URL
     self._agent = None
     self._platformInfo = None
     self._supportInProductInstall = True
     self._sslpol = bundle_paths.SSLPolicy()
     try:
         platform_info = platform.platform()
         os_name = platform.system()
         arch = platform.machine()
         py_ver = URLopener().version
         with open(os.path.join(bundle_paths.etc(), "splunk.version")) as f:
             for i in f:
                 if i.startswith("VERSION"):
                     version = i.split("=")[1].strip().strip('"')
                 elif i.startswith("BUILD"):
                     build = i.split("=")[1].strip()
         self._agent = "Splunkd/%s (%s; version=%s; arch=%s; build=%s; %s)" % (
             version, os_name, platform_info, arch, build, py_ver)
         self._platformInfo = {'version': version, 'platform': os_name}
     except Exception as e:
         logger.exception(e)
     # Manual overrides in server.conf
     try:
         conf = bundle.getConf("server", self.sessionKey)
         s = conf["applicationsManagement"]
         if not s.isDisabled():
             if "allowInternetAccess" in s:
                 self._allowRemote = bundle_paths.parse_boolean(
                     s["allowInternetAccess"])
             if "loginUrl" in s:
                 self._login = s["loginUrl"]
             if "url" in s:
                 self._base = s["url"]
             if "useragent" in s:
                 self._agent = s["useragent"]
             if "caCertFile" in s:
                 self._sslpol._cafile = bundle_paths.expandvars(
                     s["caCertFile"])
             if "sslCommonNameList" in s:
                 self._sslpol._sslCommonNameList = bundle_paths.expandvars(
                     s["sslCommonNameList"])
             if "cipherSuite" in s:
                 self._sslpol._cipherSuite = bundle_paths.expandvars(
                     s["cipherSuite"])
         s = conf["shclustering"]
         if not s.isDisabled():
             self._supportInProductInstall = False
     except Exception as e:
         logger.exception(e)
     logger.debug("applicationsManagement.allowInternetAccess = %s" %
                  str(self._allowRemote))
     logger.debug("applicationsManagement.loginUrl = %s" % self._login)
     logger.debug("applicationsManagement.url = %s" % self._base)
     logger.debug("applicationsManagement.useragent = %s" % self._agent)
     logger.debug("applicationsManagement.supportInProductInstall = %s" %
                  str(self._supportInProductInstall))
     if self._sslpol._cafile is None:
         logger.debug("applicationsManagement.caCertFile = %s" %
                      str(self._sslpol._cafile))
     if self._sslpol._sslCommonNameList is None:
         logger.debug("applicationsManagement.sslCommonNameList = %s" %
                      str(self._sslpol._sslCommonNameList))
     if self._sslpol._cipherSuite is None:
         logger.debug("applicationsManagement.cipherSuite = %s" %
                      str(self._sslpol._cipherSuite))