begin 254491    [proxies BOTP] mis-handling of non-existent welcome-file's    WAS.webcontainer
491252
public boolean isAvailable (String resource){
	    
	    Container c = _webapp.getModuleContainer();
	    if(c != null){
	       Entry entry = c.getEntry(resource); 
	       if(entry != null){
	           return true;
	       }
	       return isAvailableInDocumentRoot(resource,WCCustomProperties.SERVE_WELCOME_FILE_FROM_EDR);
	    }
	    
	    String tempFileString = _webapp.getRealPath(resource);
	    boolean available = false;
	    if (tempFileString != null) { 
	        File caseFile = new Java2SecurityFile(tempFileString);
		available = caseFile.exists();
		if (available && com.ibm.ws.util.FileSystem.isCaseInsensitive) {
			try{
				available = com.ibm.ws.util.FileSystem.uriCaseCheck(caseFile, resource);
			}catch (IOException io){
				available = false;
			}
		}
        }
		
	    if (!available)
	    	available = isAvailableInDocumentRoot(resource,WCCustomProperties.SERVE_WELCOME_FILE_FROM_EDR);			
		
        return available;
	}
1120014
def main():
    '''
    
    '''
    import argparse
    from kazoo.client import KazooClient

    parser = argparse.ArgumentParser(
            description="Crawler config file pusher to Zookeeper")
    parser.add_argument('-f', '--file', action='store', required=True,
                        help="The yaml file to use")
    parser.add_argument('-i', '--id', action='store', default="all",
                        help="The crawler id to use in zookeeper")
    parser.add_argument('-p', '--path', action='store',
                        default="/scrapy-cluster/crawler/",
                        help="The zookeeper path to use")
    parser.add_argument('-w', '--wipe', action='store_const', const=True,
                        help="Remove the current config")
    parser.add_argument('-z', '--zoo-keeper', action='store', required=True,
                        help="The Zookeeper connection <host>:<port>")
    args = vars(parser.parse_args())

    filename = args['file']
    id = args['id']
    wipe = args['wipe']
    zoo = args['zoo_keeper']
    path = args['path']

    zk = KazooClient(hosts=zoo)
    zk.start()

    # ensure path exists
    zk.ensure_path(path)

    bytes = open(filename, 'rb').read()

    if zk.exists(path):
        # push the conf file
        if not zk.exists(path + id) and not wipe:
            print("creaing conf node")
            zk.create(path + id, bytes)
        elif not wipe:
            print("updating conf file")
            zk.set(path + id, bytes)

        if wipe:
            zk.set(path + id, None)

    zk.stop()
1226594
def real_main(start_url=None,
              ignore_prefixes=None,
              upload_build_id=None,
              upload_release_name=None):
    """"""
    coordinator = workers.get_coordinator()
    fetch_worker.register(coordinator)
    coordinator.start()

    item = SiteDiff(
        start_url=start_url,
        ignore_prefixes=ignore_prefixes,
        upload_build_id=upload_build_id,
        upload_release_name=upload_release_name,
        heartbeat=workers.PrintWorkflow)
    item.root = True

    coordinator.input_queue.put(item)
    coordinator.wait_one()
    coordinator.stop()
    coordinator.join()
632212
function startBrowserSync() {
    if (args.nosync || browserSync.active) {
        return;
    }

    helper.log('Starting BrowserSync on port ' + port);

    var serverRoot = config.baseDirs;

    gulp.watch([].concat(config.src), ['watch-all']);


    var options = {
        //proxy: 'localhost:' + port,
        port: 8010,
        ws: true,
        server: {
            baseDir: serverRoot
        },
        reloadDelay: config.browserReloadDelay
    };

    browserSync.init(options);

}
1237090
function proxyError (err) {
    reverseProxy.destroy();

    process.nextTick(function () {
      //
      // Destroy the incoming socket in the next tick, in case the error handler
      // wants to write to it.
      //
      socket.destroy();
    });

    self.emit('webSocketProxyError', req, socket, head);
  }
1133194
function concatPubPath(env, fileName) {

        "use strict";

        var hostPrefixMap = {
            'daily': 'h5.waptest',
            'prepub': 'h5.wapa',
            'wapp': 'wapp.m', //未定义
            'online': 'h5.m'
        };

        return 'http://' + [hostPrefixMap[env] + '.tao'+''+'bao.com', awpConfig.oWebappDir, fileName].join('/');

    }
559319
def main(args=None):
    
    logger = cfg.configureLogger()
    for root, dirs, files in os.walk(cfg.dataDir):
        for dir in dirs:
            newDir = os.path.join(root, dir)
            try:
                os.removedirs(newDir)
                logger.info("Deleted empty dir " + str(newDir))
            except:
                pass

    if cfg.useTwisted:
        import logging
        logger = logging.getLogger('analyser.twisted')
        from twisted.internet import reactor
        from twisted.web.resource import Resource
        from twisted.web import static, server
        from twisted.web.wsgi import WSGIResource
        from twisted.application import service
        from twisted.internet import endpoints

        class ReactApp:
            """
            Handles the react app (excluding the static dir).
            """

            def __init__(self, path):
                # TODO allow this to load when in debug mode even if the files don't exist
                self.publicFiles = {f: static.File(os.path.join(path, f)) for f in os.listdir(path) if
                                    os.path.exists(os.path.join(path, f))}
                self.indexHtml = ReactIndex(os.path.join(path, 'index.html'))

            def getFile(self, path):
                """
                overrides getChild so it always just serves index.html unless the file does actually exist (i.e. is an
                icon or something like that)
                """
                return self.publicFiles.get(path.decode('utf-8'), self.indexHtml)

        class ReactIndex(static.File):
            """
            a twisted File which overrides getChild so it always just serves index.html (NB: this is a bit of a hack, 
            there is probably a more correct way to do this but...)
            """

            def getChild(self, path, request):
                return self

        class FlaskAppWrapper(Resource):
            """
            wraps the flask app as a WSGI resource while allow the react index.html (and its associated static content)
            to be served as the default page.
            """

            def __init__(self):
                super().__init__()
                self.wsgi = WSGIResource(reactor, reactor.getThreadPool(), app)
                import sys
                if getattr(sys, 'frozen', False):
                    # pyinstaller lets you copy files to arbitrary locations under the _MEIPASS root dir
                    uiRoot = sys._MEIPASS
                else:
                    # release script moves the ui under the analyser package because setuptools doesn't seem to include
                    # files from outside the package
                    uiRoot = os.path.dirname(__file__)
                logger.info('Serving ui from ' + str(uiRoot))
                self.react = ReactApp(os.path.join(uiRoot, 'ui'))
                self.static = static.File(os.path.join(uiRoot, 'ui', 'static'))

            def getChild(self, path, request):
                """
                Overrides getChild to allow the request to be routed to the wsgi app (i.e. flask for the rest api 
                calls),
                the static dir (i.e. for the packaged css/js etc), the various concrete files (i.e. the public 
                dir from react-app) or to index.html (i.e. the react app) for everything else.
                :param path: 
                :param request: 
                :return: 
                """
                if path == b'api':
                    request.prepath.pop()
                    request.postpath.insert(0, path)
                    return self.wsgi
                elif path == b'static':
                    return self.static
                else:
                    return self.react.getFile(path)

            def render(self, request):
                return self.wsgi.render(request)

        application = service.Application('analyser')
        site = server.Site(FlaskAppWrapper())
        endpoint = endpoints.TCP4ServerEndpoint(reactor, cfg.getPort(), interface='0.0.0.0')
        endpoint.listen(site)
        reactor.run()
    else:
        # get config from a flask standard place not our config yml
        app.run(debug=cfg.runInDebug(), host='0.0.0.0', port=cfg.getPort())
1168759
async function mkProxyOrMockFile({dirPath, exclude, targetDir, proxyFolderName,
    mockFolderName, time, interval, isProxy, libPath}) {
//@formatter:on
    
    const relativePath = dirPath.replace(targetDir, '') || '/';
    const childList = await loadChildList(dirPath, exclude);

    const taskList = childList.map(child => {
        return ((async function handleFile() {
            const stat = await Fs.stat(Path.join(dirPath, child));
            if (stat.isFile()) {
                const fileRelativePath = relativePath + child;
                const isWs = _.endsWith(child, '-ws.js');

                const factory = {
                    'proxy_api'() {
                        return Render(PROXY_TPL,
                            {note: Common.NOTE, proxyFolderName, fileRelativePath});
                    },
                    'mock_api'() {
                        return Render(MOCK_API_TPL,
                            {note: Common.NOTE, mockFolderName, fileRelativePath, time});
                    },
                    'proxy_ws'() {
                        return Render(PROXY_TPL,
                            {note: Common.NOTE, proxyFolderName, fileRelativePath});
                    },
                    'mock_ws'() {
                        return Render(MOCK_WS_TPL, {
                            note: Common.NOTE,
                            mockFolderName,
                            fileRelativePath,
                            interval
                        });
                    }
                }[`${isProxy ? 'proxy' : 'mock'}_${isWs ? 'ws' : 'api'}`]();

                await Fs.writeFile(Path.join(libPath, child), factory);
                return;
            }

            if (stat.isDirectory()) {
                await mkProxyOrMockFile({
                    dirPath: Path.join(dirPath, child), exclude, targetDir, proxyFolderName,
                    mockFolderName, time, interval, isProxy, libPath
                });
            }
        })());
    });

    await Promise.all(taskList);
}
228431
function proxyObjErrors (proxyObj) {
  if (!proxyObj) { return '`proxyObj` not defined'; }

  let errors   = '';
  let expected = ['req', 'req', 'reqOpts', 'options'];

  _.each(expected, function (expect, index) {
    if (!proxyObj[expect]) {
      errors += (index ? ', ' : '') + 'Missing property: `' + expect + '`';
    }
  });

  return errors ? 'Errors found in `proxyObj`: [' + errors + ']' : false;
}
609611
function (e, req, res, host) {
		LOG.error('proxy error for host: ' + host + '. remove from active proxy list:', 'SR.Proxy');
		LOG.error(e, 'SR.Proxy');
		
		// remove proxy info from list
		delete l_proxies[host];
		
		// notify for proxy failure
		UTIL.safeCall(onProxyFail, host);
		
		// send back to client about the proxy error
		res.writeHead(502, {
   			'Content-Type': 'text/plain'
		});
		res.end('PROXY_ERROR: cannot access proxy: ' + host);		
	}
1682
def main(overwrite):
    
    logger.debug("Checking existence of '%s'.", CONF_PATH)
    if not os.path.exists(CONF_PATH):
        logger.debug("Directory %s not found! Panicking..", CONF_PATH)
        raise UserWarning(
            "Can't find '%s' - it looks like ProFTPD is not installed!" % (
                CONF_PATH,
            )
        )

    # check existence of proftpd.conf
    logger.debug("Checking existence of configuration file '%s'.", CONF_FILE)
    if not os.path.exists(CONF_FILE):
        logger.debug("Configuration file not found, creating..")
        _write_conf_file()
    else:
        logger.debug("Found.")

        if not os.path.exists(CONF_FILE + "_"):
            logger.debug(
                "Backing up the configuration file '%s' -> '%s'.",
                CONF_FILE,
                CONF_FILE + "_"
            )
            shutil.copyfile(CONF_FILE, CONF_FILE + "_")
        else:
            logger.debug(
                "Backup already exists. '%s' will be overwritten.",
                CONF_FILE
            )
    if overwrite:
        logger.debug("--update switch not found, overwriting conf file")
        _write_conf_file()

    logger.debug("Checking existence of the '%s' file.", MODULES_FILE)
    if not os.path.exists(MODULES_FILE) and _is_deb_system():
        with open(MODULES_FILE, "w") as f:
            f.write(DEFAULT_MODULES_CONF)
            logger.debug("Modules file not found. Created '%s'.", MODULES_FILE)

    # create data directory, where the user informations will be stored
    logger.debug("Checking existence of user's directory '%s'.", DATA_PATH)
    if not os.path.exists(DATA_PATH):
        logger.debug("Directory '%s' not found, creating..", DATA_PATH)

        os.makedirs(DATA_PATH, 0777)

        logger.debug("Done. '%s' created.", DATA_PATH)

    # create user files if they doesn't exists
    logger.debug("Checking existence of passwd file '%s'.", LOGIN_FILE)
    if not os.path.exists(LOGIN_FILE):
        logger.debug("passwd file not found, creating..")

        open(LOGIN_FILE, "a").close()

        logger.debug("Done. '%s' created.")

    logger.debug("Setting permissions..")
    os.chown(LOGIN_FILE, get_ftp_uid(), -1)
    os.chmod(LOGIN_FILE, 0400)

    # load values from protpd conf file
    logger.debug("Switching and adding options..")
    data = ""
    with open(CONF_FILE) as f:
        data = f.read()

    # set path to passwd file
    logger.debug("\tAuthUserFile")
    data = add_or_update(
        data,
        "AuthUserFile",
        LOGIN_FILE
    )
    logger.debug("\tRequireValidShell")
    data = add_or_update(data, "RequireValidShell", "off")
    logger.debug("\tDefaultRoot")
    data = add_or_update(data, "DefaultRoot", "~")

    # http://www.proftpd.org/docs/modules/mod_log.html
    logger.debug("\tLogFormat")
    data = add_or_update(data, "LogFormat", 'paths "%f, %u, %m, %{%s}t"')
    logger.debug("\tExtendedLog")
    data = add_or_update(
        data,
        "ExtendedLog",
        LOG_FILE + " WRITE paths"
    )

    if not _is_deb_system():
        logger.debug("Detected non debian based linux. Aplying SUSE changes.")
        data = comment(data, "IdentLookups off")
        data = comment(data, "Include /etc/proftpd/modules.conf")
        data = add_or_update(data, "User", "ftp")

    # save changed file
    logger.debug("Saving into config file..")
    with open(CONF_FILE, "w") as f:
        f.write(data)
        logger.debug("Done.")

    logger.debug("Sending proftpd signal to reload configuration..")
    reload_configuration()
    logger.debug("Done.")
    logger.info("All set.")
31354
async function triageGoogleError(err, origin) {
    // console.log(err);
    const triaged = {
        err,
        origin,
        print: true,
    };

    if (err && err.code === 401) {
        triaged.message = `Your credentials appear to be invalid.\nRun 'gas auth -f' to re-authenticate.`;
        triaged.extraInfo = `Invalid Credentials`;
    } else if (err === `Error: invalid_grant`) {
        triaged.message = `Your credentials appear to be invalid.\nRun 'gas auth -f' to re-authenticate.`;
        triaged.extraInfo = `Invalid Grant`;
    } else if (err && err.code === 403) {
        triaged.message = err.message;
        triaged.extraInfo = `Not allowed`;
    } else if (err && err.code === 404) {
        triaged.message = err.message;
        triaged.extraInfo = `Not found`;
    } else if (err && err.code === `ENOTFOUND`) {
        triaged.message = `Can't seem to reach the Google servers.`;
        triaged.extraInfo = `No connection`;
    } else if (err && err.code === `ECONNRESET`) {
        triaged.message = `Unexpected closed connection.`;
        triaged.extraInfo = `Closed connection`;
    } else if (err && err.code === 400 && origin === 'pushToRemote') {
        const projectRoot = await findInProject('.', constants.META_DIR);
        if (projectRoot.found) {

            // Find syntax errors in all files
            const files = getAllFiles(projectRoot.folder, '.', []);
            const syntaxErrors = [];
            for (const file of files) {
                const extension = path.parse(file).ext;
                if (extension === '.js' || extension === '.gs') {
                    const src = fs.readFileSync(path.join(projectRoot.folder, file));
                    const syntaxErr = check(src, file);
                    if (syntaxErr) {
                        syntaxErrors.push(syntaxErr);
                    }
                }
            }

            // Create a message with a summary of found syntax errors
            if (syntaxErrors.length > 0) {
                let message = `The code you are trying to push appears to have 1 or more syntax error(s).`;
                for (const err of syntaxErrors) {
                    message += `-------------------------------------------------------------------------------------------------\n`;
                    message += `${err}\n`;
                }
                triaged.extraInfo = `${syntaxErrors}`;
            } else {
                triaged.message = `Google doesn't accept the code you are trying to push. Try doublechecking for project structure errors.`;
                triaged.extraInfo = `No syntax errors`;
            }
        } else {
            triaged.message = `Google doesn't accept the code you are trying to push. Try doublechecking for project structure errors.`;
            triaged.extraInfo = `No .gas folder found`;
        }
    } else if (err) {
        triaged.message = (`gas returned an error: ${err}`);
        triaged.extraInfo = `Not a known error`;
    } else {
        triaged.message = (`O-oh. Something seems to have gone wrong.`);
        triaged.extraInfo = `No error passed to the function`;
    }
    return triaged;
}
179061
function HttpServer(options) {
  options = options || {};

  if (options.root) {
    this.root = options.root;
  }
  else {
    try {
      fs.lstatSync('./public');
      this.root = './public';
    }
    catch (err) {
      this.root = './';
    }
  }

  this.headers = options.headers || {};

  this.cache = options.cache === undefined ? 3600 : options.cache; // in seconds.
  this.showDir = options.showDir !== 'false';
  this.autoIndex = options.autoIndex !== 'false';
  this.gzip = options.gzip === true;
  this.contentType = options.contentType || 'application/octet-stream';

  if (options.ext) {
    this.ext = options.ext === true
      ? 'html'
      : options.ext;
  }

  var before = options.before ? options.before.slice() : [];

  before.push(function (req, res) {
    if (options.logFn) {
      options.logFn(req, res);
    }

    res.emit('next');
  });

  if (options.cors) {
    this.headers['Access-Control-Allow-Origin'] = '*';
    this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
    if (options.corsHeaders) {
      options.corsHeaders.split(/\s*,\s*/)
          .forEach(function (h) { this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
    }
    before.push(corser.create(options.corsHeaders ? {
      requestHeaders: this.headers['Access-Control-Allow-Headers'].split(/\s*,\s*/)
    } : null));
  }

  if (options.robots) {
    before.push(function (req, res) {
      if (req.url === '/robots.txt') {
        res.setHeader('Content-Type', 'text/plain');
        var robots = options.robots === true
          ? 'User-agent: *\nDisallow: /'
          : options.robots.replace(/\\n/, '\n');

        return res.end(robots);
      }

      res.emit('next');
    });
  }

  before.push(ecstatic({
    root: this.root,
    cache: this.cache,
    showDir: this.showDir,
    autoIndex: this.autoIndex,
    defaultExt: this.ext,
    gzip: this.gzip,
    contentType: this.contentType,
//    handleError: typeof options.proxy !== 'string'
    handleError: (!options.fallback || typeof options.proxy === 'string')
  }));

  if (typeof options.proxy === 'string') {
    var proxy = httpProxy.createProxyServer({});
    before.push(function (req, res) {
      proxy.web(req, res, {
        target: options.proxy,
        changeOrigin: true
      });
    });
  }

  if (options.fallback) {
    before.push(function (req, res) {
      if (res.statusCode === 404) {
        res.redirect(options.fallback.address, 301);
      }
    });
  }

  var serverOptions = {
    before: before,
    headers: this.headers,
    onError: function (err, req, res) {
      if (options.logFn) {
        options.logFn(req, res, err);
      }

      res.end();
    }
  };

  if (options.https) {
    serverOptions.https = options.https;
  }

  this.server = union.createServer(serverOptions);
}
263641
public static void main(String[] args) throws IOException, InterruptedException {

        if (args.length < 4 || args.length > 5) {
            System.out.println(
                    "USAGE: HelloWorldServerTls host port certChainFilePath privateKeyFilePath " +
                    "[trustCertCollectionFilePath]\n  Note: You only need to supply trustCertCollectionFilePath if you want " +
                    "to enable Mutual TLS.");
            System.exit(0);
        }

        final HelloWorldServerTls server = new HelloWorldServerTls(args[0],
                Integer.parseInt(args[1]),
                args[2],
                args[3],
                args.length == 5 ? args[4] : null);
        server.start();
        server.blockUntilShutdown();
    }
701322
def is_usable(host, port, timeout=3):
    
    try:
        proxies = {
            'http': 'http://%s:%s' % (host, port),
            'https': 'https://%s:%s' % (host, port)
        }
        requests.get('http://www.baidu.com/', proxies=proxies, timeout=timeout)
    except HTTPError:
        print('failed: ', host, port)
        return False
    else:
        print('success: ', host, port)
        return True
1659
def _HandleHelp(self, request):
    """"""
    help_path = request.path.split("/", 2)[-1]
    if not help_path:
      raise werkzeug_exceptions.Forbidden("Error: Invalid help path.")

    # Proxy remote documentation.
    return self._RedirectToRemoteHelp(help_path)
495065
function startBrowserSync(serverRoot) {

    console.log('Starting BrowserSync on port ' + 8010 + ' for ' + serverRoot);

    var options = {
        //proxy: 'localhost:' + port,
        port: 8010,
        ws: true,
        server: {
            baseDir: serverRoot
        },
        reloadDelay: 2000
    };

    browserSync.init(options);

}