npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cwg-http-proxy-tools

v5.1.5

Published

a simple tool to proxy http(s) requests to your server, proxy agent support http, socks4 socks4a and socks5 protocol, data transmission based on websocket protocol.

Downloads

118

Readme

用法见test/test1.js

本文档仅对基本参数进行说明。

以代码形式使用本模块,首先需要引用本模块导出的方法和变量:

const {
  argv,
  setlog,
  bind_server,
  bind_client,
  bind_upstream,
  bind_manager,
  startSimpleServer,
  plimit,
}=require('cwg-http-proxy-tools')

argv

把控制台参数转换成js对象,如 --xx=111 --y 则转换之后的argv等于{xx: 111, y: true}

setlog(enable)

是否输出日志信息,enable为1时输出全部日志,为0时仅输出必要的日志信息。
如果不调用该方法,默认输出全部日志

bind_server(port, pwd, pubkeyExpires, onrefleshKeyHash, fakeServer, withoutUps, upsTargets, helomsg, cpwd)

开启一个本地server,参数依次为本地端口号 port,管理密码 pwd,pubkeyExpires 公钥有效时间,公钥刷新时回调函数 onrefleshKeyHash,非ws协议连接时伪装的服务器函数 fakeServer,启动server时不要自带上传源 withoutUps
  • pwd如果不需要则填数字0,然后改server就不可以被manager端进行远程管理
  • pubkeyExpires单位毫秒,例如3天过期,则这个值等于 3 * 24 * 3600e3
  • onrefleshKeyHash入参只有一个buffer类型的hash,长度为32位,只会在公钥发生变化时被调用
  • fakeServer,入参为(req, res),如果该参数不需要,则填入数字0,非ws协议访问时返回hello world,否则以fakeServer处理结果为准
  • withoutUps默认为1,如果不需要则必须把该参数设置为0
  • upsTargets指定需要连接的远程server,如果连接成功,则本server会请求作为远程server的一个upstream,在对方manager列表里展示为 数字<*U>

注意此处不要构成循环引用,否则遇到不可访问的目标时,会导致等待最大超时后才连接失败

  • helomsg为client连接服务端成功之后,服务端发送的连接成功提示消息
  • cwpd为client,upstream连接时的密码,如果不填则任何client和upstream都可以直接连接server并使用server的流量

bind_client(port, targets, noupstream, whiteblack, upstreamprivate)

开启本地client,支持http/https/socks4/socks4a/socks5连接协议,监听端口 port,连接目标可选列表 targets,不需要自带上传源 noupstream
  • targets是一个数组,数组内部为元素

    • 结构可以有两种:

      1. ['ws://xxx', hash32=>{}, cpwd]
      2. ['ws://cpwdbase64@xxx', hash32=>{}]

      targets是一个多层数组,ws://xxx表示目标地址,可以带端口号

      hash32=>{}是目标server的公钥hash,如果不填这个回调函数,则不会校验目标机器公钥是否匹配,有被中间人攻击的风险

      cpwd为服务器连接密码,如果服务器没有设置密码,则此项可以不填。cpwd也可以转换成base64字符串拼在ws字符串里面

  • 如果client带了一个upstream,则whiteblack为自带upstream的过滤规则,如果有该参数,则上传源收到转发流量命令,会按照该参数指定的规则判断是否允许连接目标机,使用示例:--whiteblack="1:(.|^)jd.com:(\d+)$",表示该上传源只允许访问jd.com域名,其他域名的目标均禁止访问。1:表示白名单模式,0:则表示黑名单模式,只允许一条规则,且必须指定是白名单还是黑名单模式,冒号后面跟的是具体规则的正则表达式,比如目标地址是 https://www.baidu.com/s/222,则实际进行判断的的字符串为 www.baidu.com:443 。upstreamprivate不填则默认自带的upstream会与server共享流量

bind_upstream(noshell, targets, whiteblack)

开启一个upstream,是否不需要shell noshell,targets同上,whiteblack为目标过滤规则,同上

bind_manager(pwd, targets)

pwd为目标server的管理密码,targets同上

startSimpleServer(port, pwd, expires, helomsg, cpwd, upsTargets)

快速开启一个简易服务器

开启后,访问该服务器 /keyhash.hex 可以获取到当前的服务端公钥的hash

plimit(memoryLimitSize, func)

限制运行服务的内存大小,超过内存大小则会重启。

目前代码内存泄漏问题存在,但暂时不好排查,如果是服务器上运行的程序建议都使用这个方法包裹,避免内存爆炸导致服务器宕机。

使用方式:plimit(512, _=>{ ...主程序代码... }),表示运行时最大使用内存大小为512MB,超过则该进程会自动重启,切断当前所有进行中的连接