CentOS 一键安装shadowsocks客户端和privoxy

#!/bin/bash
if command -v pip >/dev/null 2>&1; then 
    :
else 
    yum install -y python-pip
fi
if command -v sslocal >/dev/null 2>&1; then 
    :   
else
    pip install shadowsocks
fi
sslocal -s xxx.xxx.xxx.xxx -p xx -k xx -m aes-256-cfb -d restart
if command -v privoxy >/dev/null 2>&1; then
    :
else
    yum install -y privoxy
fi
line1='forward-socks5 / localhost:1080 .'
line1new=`head -n 1 /etc/privoxy/config`
if [ "$line1" != "$line1new" ]; then
    sed -i '1iforward-socks5 / localhost:1080 .' /etc/privoxy/config
fi
service privoxy restart
export http_proxy=http://127.0.0.1:8118;export https_proxy=http://127.0.0.1:8118;

proxy-local.sh

全自动短地址hash映射(shortUrl)

/**
 * CREATE TABLE `shortUrl` (
 * `id` int(11) NOT NULL AUTO_INCREMENT,
 * `key` int(11) unsigned NOT NULL,
 * `suffix` int(11) unsigned NOT NULL,
 * `url` text NOT NULL,
 * `num` int(11) NOT NULL,
 * `timeout` int(11) NOT NULL,
 * `createTime` int(11) NOT NULL,
 * `uri` char(16) GENERATED ALWAYS AS (concat(lower(hex(`key`)),hex(`suffix`))) VIRTUAL NOT NULL,
 * PRIMARY KEY (`id`),
 * UNIQUE KEY `uniq` (`key`,`suffix`) USING BTREE
 * ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='short url redirect';
 */
class ShortUrl
{
    private $pdo;

    private $tableName;

    private $strict = false;

    /**
     *
     * @param \PDO $pdo
     * @param string $tableName
     */
    function __construct($pdo, $tableName)
    {
        $this->pdo = $pdo;
        $this->tableName = $tableName;
    }

    /**
     *
     * @param boolean $flag
     */
    function setStrict($flag)
    {
        $this->strict = $flag;
    }

    /**
     *
     * @return boolean
     */
    function getStrict()
    {
        return $this->strict;
    }

    /**
     *
     * @param string $url
     * @param number $timeout
     * @return string
     */
    function add($url, $timeout = 0)
    {
        $query = parse_url($url, PHP_URL_QUERY);
        if (! empty($query)) {
            parse_str($query, $query);
            if (! $this->strict) {
                ksort($query);
            }
            $query = http_build_query($query);
            $classUrl = '\Http\Url';
            if (function_exists('http_build_url')) {
                $parse = parse_url($url);
                $parse['query'] = $query;
                $url = http_build_query($parse);
            } elseif (class_exists($classUrl)) {
                $parse = new $classUrl($url);
                $parse->query = $query;
                $url = $parse->toString();
            } else {
                $url = preg_replace('/\?(.+)(#|$)/', '?' . $query, $url);
            }
        }
        $data = array();
        $key = crc32($url);
        $key = sprintf("%u", $key);
        $sql = 'select uri from ' . $this->tableName . ' where `key`=' . $key;
        $sql .= ' and url=?';
        $stat = $this->pdo->prepare($sql);
        $stat->execute(array(
            $url
        ));
        $uri = $stat->fetchColumn();
        if (! empty($uri)) {
            return $uri;
        }
        $suffix = 0;
        // Find min usable suffix regardless exists values.Very powerful algorithm.
        $batch = 1000;
        $loop = 0;
        $this->pdo->exec('lock tables ' . $this->tableName . ' write');
        while (true) {
            $sql = 'select suffix from ' . $this->tableName;
            $sql .= ' where `key`=' . $key;
            $sql .= ' and suffix>=' . $suffix;
            $sql .= ' order by suffix limit ' . $batch;
            $stat = $this->pdo->query($sql);
            $list = $stat->fetchAll(\PDO::FETCH_NUM);
            if (empty($list)) {
                break;
            }
            foreach ($list as $k => $v) {
                $suffix = ($k + $batch * $loop);
                if ($suffix != $v[0]) {
                    break 2;
                }
            }
            $suffix ++;
            if ($k + 1 < $batch) {
                break;
            }
            $loop ++;
        }
        $data['key'] = $key;
        $data['suffix'] = $suffix;
        $data['url'] = $url;
        $data['num'] = 0;
        $data['timeout'] = $timeout;
        $data['createTime'] = time();
        $sql = 'insert into ' . $this->tableName;
        $sql .= '(`key`,suffix,url,num,timeout,createTime)';
        $sql .= 'values(:key,:suffix,:url,:num,:timeout,:createTime)';
        $stat = $this->pdo->prepare($sql);
        $res = $stat->execute($data);
        $this->pdo->exec('unlock tables');
        if ($res) {
            return dechex($key) . dechex($suffix);
        }
    }

    /**
     *
     * @return boolean
     */
    function clean()
    {
        $time = time();
        $stat = $this->pdo->prepare(
            'delete from ' . $this->tableName .
                 ' where timeout>0 && createTime+timeout<?');
        return $stat->execute(array(
            $time
        ));
    }

    /**
     *
     * @param string $key
     * @return null|integer 1:timeout or unavailable
     */
    function redirect($key)
    {
        $suffix = substr($key, 8);
        $key = substr($key, 0, 8);
        $key = sprintf("%u", hexdec($key));
        $sql = 'select * from ' . $this->tableName;
        $sql .= ' where `key`=? and suffix=?';
        $stat = $this->pdo->prepare($sql);
        $stat->execute(array(
            $key,
            $suffix
        ));
        $row = $stat->fetchObject();
        if (false == $row) {
            return 1;
        }
        if ($row->timeout > 0) {
            $expire = $row->createTime + $row->timeout;
            if ($expire < time()) {
                return 1;
            }
        }
        $sql = 'update ' . $this->tableName . ' set num=num+1 where `key`=?';
        $sql .= ' and suffix=?';
        $stat = $this->pdo->prepare($sql);
        $stat->execute(array(
            $key,
            $suffix
        ));
        header('Location: ' . $row->url);
    }
}

下载:ShortUrl.php

解决浏览器自动填充表单问题

Mozilla 官方文档建议

Mozilla developer documentation 建议使用表单设置属性 tautocomplete=”off” 来阻止浏览器从cache获取数据填充登录表单。

 <input type="text" name="foo" autocomplete="off" />

但是这种方案不兼容某些Chrome、Firefox。

兼容所有浏览器

最终决定使用使用隐藏input来接受浏览器自动填充,这样不会影响用户体验,也可以兼容所有浏览器。

  <input style="display:none"><!-- for disable autocomplete on chrome -->
  <input type="text" id="username"  name="username"  autocomplete="off">

但是实际上在Chrome上并没什么用,在FireFox上也只能阻止用户名自动填充。

接着搜索,又发现了个新东西

<input type="password"  autocomplete="new-password">

把password的autocomplete属性由off变成了new-password,发现Chrome不自动填充了,但是FireFox上仍然会填充用户名

再接着结合第一点尝试,最后结果是使用以下方式

 <input type="password" style="display: none;"/>
 <input type="text" autocomplete="off"/>

 <input class="form-control" type="password" name="tradePassword" id="txPassword" autocomplete="new-password"

这样在Chrome和FireFox上就都不会填充了。

参考:https://segmentfault.com/q/1010000006090445