CentOS7使用Firewall屏蔽端口

1 安装 Firewalld

yum install -y firewalld

2 开启常用端口

firewall-cmd --add-service=ssh --permanent
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent

3 特殊端口指定IP访问权限

firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.0.0/16" port port="8080" protocol="tcp" accept'

4 只针对 IPV4 或者 IPV6 地址开放端口

firewall-cmd --permanent --add-rich-rule='rule family="ipv4" port port="443" protocol="tcp" accept'

5 重新加载防火墙规则

firewall-cmd --reload

WordPress 禁用 REST

添加以下代码到插件文件里,可以实现:

  1. 已登录用户可以正常使用 wp-json API
  2. 未登录用户禁止使用 wp-json API
/*
 *  disable rest api
 */
function disable_rest_api($access)
{
    if (is_user_logged_in()) {
        return $access;
    } else {
        return new WP_Error('rest_disabled', __('The REST API on this site has been disabled.'), ['status' => rest_authorization_required_code()]);
    }
}

add_filter('rest_authentication_errors', 'disable_rest_api');

阿里云刷新CDN缓存

PHP版本的刷新阿里云CDN缓存最小SDK


define('DebugModel', true);
define('AccessKeyId', 'AccessKeyId');
define('AccessKeySecret', 'AccessKeySecret');

/**
 *  刷新网址
 */
function freshURL($urls = [], $type = 'File')
{
    $sign = getSign(['Action' => 'RefreshObjectCaches', 'ObjectPath' => formatURL($urls), 'ObjectType' => $type]);
    $url = 'https://cdn.aliyuncs.com/?' . $sign['url'] . '&Signature=' . $sign['sign'];
    $request = json_decode(httpRequest($url));
    if (isset($request->Code) && $request->Code == 'OK') {
        return true;
    } else {
        if (DebugModel) {
            var_dump($request);
        }
        return false;
    }
}

/**
 *  格式化网址
 */
function formatURL($urls = [])
{
    $urls = array_map(function($v) {
        return str_replace(['http://', 'https://'], ['', ''], $v);
    }, $urls);
    return implode('\n', $urls);
}

/**
 *  获取签名
 */
function getSign($add)
{
    $data = array(
        "Version" => "2018-05-10",
        "SignatureMethod" => "HMAC-SHA1",
        "SignatureNonce" => uniqid(mt_rand(0, 0xffff), true),
        "SignatureVersion" => "1.0",
        "AccessKeyId" => AccessKeyId,
        "Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
        "Format" => "JSON",
    );
    $data = array_merge($data, $add);
    ksort($data);
    $format = http_build_query($data);
    $signUrl = 'GET&%2F&' . urlencode(str_replace(['+', '*', '%7E'], ['%20', '%2A', '~'], $format));
    $sign = urlencode(base64_encode(hash_hmac('sha1', $signUrl, AccessKeySecret . '&', true)));
    return array('url' => $format, 'sign' => $sign);
}

/**
 *  发起 HTTP 请求
 */
function httpRequest($url)
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    $data = curl_exec($curl);
    $error = curl_error($curl);
    curl_close($curl);
    if ($error) {
        return $error;
    } else {
        return $data;
    }
}

function main() {
    freshURL(['https://abc.com/login/', 'https://abc.com/user/12']);
}

main();

Podman使用阿里云容器镜像

Podman 是一个开源的容器管理工具,语法兼容 Docker ,但是某些方面比原生 Docker 命令更好用,比如能够以非 root 用户的身份去运行容器,而且不需要守护进程。

Podman 引入了一个注册表的概念,注册表就是包括 docker.io 在内的多个容器镜像源,默认的有 redhat docker fedora centos quay

国内直接用 podman pull 拉取镜像会很慢,所以需要配置阿里云容器镜像来加速访问。

Podman 默认注册表配置文件在 /etc/containers/registries.conf

修改为以下内容:

unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "******.mirror.aliyuncs.com"

把 location 对应的值修改为你的阿里云容器加速镜像地址就可以了,现在拉取镜像就是用的阿里云加速

phpMyAdmin登录MySQL8

MySQL8使用了新的密码验证插件,所以pma不能直接登录,解决办法是创建一个旧验证方式的用户和密码,比如用户www密码123456,然后就可以登录了

CREATE USER 'www'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
GRANT ALL PRIVILEGES ON *.* TO 'www'@'%';
FLUSH PRIVILEGES;

Win10设置绿色版谷歌浏览器为默认浏览器

第一步:将另外一台Win10电脑上安装好的谷歌浏览器,复制到当前电脑的指定目录下

安装目录:C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

第二步:修复注册表

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"Google Chrome"="Software\\Clients\\StartMenuInternet\\Google Chrome\\Capabilities"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome]
@="Google Chrome"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities]
"ApplicationDescription"="Google Chrome 浏览器是一款可高速运行网页和应用的网络浏览器。它快捷、稳定且易于使用。Google Chrome 浏览器内置的恶意软件和网上诱骗防护功能可让您更安全地浏览网页。"
"ApplicationIcon"="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe,0"
"ApplicationName"="Google Chrome"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities\FileAssociations]
".htm"="ChromeHTML"
".html"="ChromeHTML"
".pdf"="ChromeHTML"
".shtml"="ChromeHTML"
".svg"="ChromeHTML"
".xht"="ChromeHTML"
".xhtml"="ChromeHTML"
".webp"="ChromeHTML"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities\Startmenu]
"StartMenuInternet"="Google Chrome"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\Capabilities\URLAssociations]
"http"="ChromeHTML"
"https"="ChromeHTML"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\DefaultIcon]
@="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe,0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\InstallInfo]
"ReinstallCommand"="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --make-default-browser"
"HideIconsCommand"="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --hide-icons"
"ShowIconsCommand"="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\" --show-icons"
"IconsVisible"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell]

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\Google Chrome\shell\open\command]
@="\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\""

第三步:在系统设置里,设置谷歌浏览器为默认浏览器

阿里云绿网内容安全API

PHP版本:


define('AccessKeyId', 'AccessKeyId');
define('AccessKeySecret', 'AccessKeySecret');

/**
 *  获取签名
 */
function getSign($md5, $date, $rand)
{
    $data = array(
        "x-acs-version" => "2018-05-09",
        "x-acs-signature-nonce" => $rand,
        "x-acs-signature-version" => '1.0',
        "x-acs-signature-method" => "HMAC-SHA1",
    );
    ksort($data);
    $signUrl = '';
    foreach ($data as $k => $v) {
        $signUrl .= $k . ':' . $v . "\n";
    }
    $signUrl = sprintf("POST\napplication/json\n%s\napplication/json\n%s\n%s/green/text/scan", $md5, $date, $signUrl);
    $sign = base64_encode(hash_hmac('sha1', $signUrl, AccessKeySecret, true));
    return $sign;
}

/**
 *  发起 HTTP 请求
 */
function httpRequest($url, $body)
{
    $date = gmdate('D, d M Y H:i:s T');
    $md5 = base64_encode(md5($body, true));
    $rand = md5(rand(10000, 99999) . time());
    $sign = getSign($md5, $date, $rand);
    $header = array(
        'Accept: application/json',
        'Content-Type: application/json',
        'Content-MD5: ' . $md5,
        'Date: ' . $date,
        'x-acs-version: 2018-05-09',
        'x-acs-signature-nonce: ' . $rand,
        'x-acs-signature-version: 1.0',
        'x-acs-signature-method: HMAC-SHA1',
        'Authorization: acs ' . AccessKeyId . ':' . $sign,
    );

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
    $data = curl_exec($curl);
    $error = curl_error($curl);
    curl_close($curl);
    if ($error) {
        return $error;
    } else {
        return $data;
    }
}

/**
 *  内容检测
 */
function greenTextScan($content) {
    $api = 'https://green.cn-beijing.aliyuncs.com/green/text/scan';
    $body = [
        'scenes' => ['antispam'],
        'tasks' => []
    ];
    foreach($content as $k=>$v) {
        $body['tasks'][] = [
            'dataId' => $k,
            'content' => $v
        ];
    }
    return httpRequest($api, json_encode($body));
}

function main()
{
    echo greenTextScan(['需要检测的文本']);
}

main();

Javascript 数组操作

一 数组转换为字符串

var w = ['a', 'b', 'c'];
w.toString(); // "a,b,c"
w.join(''); // "abc"
w.join('-'); // "a-b-c"

二 数组添加元素

var w = ['a'];
w.push('b'); // w: ["a", "b"]
w.unshift('c'); // w: ["c", "a", "b"]

三 数组删除元素

var w = ['a', 'b', 'c'];
w.pop(); // c
// w: ['a', 'b'];
w.shift(); // a
// w: ['b'];
delete w[0]

四 合并数组

var w1 = ['a'];
var w2 = ['b'];
var w = w1.concat(w2); // ["a", "b"]

五 查找数组元素

var w = ['a', 'b', 'c'];
w.indexOf('b'); // 1
w.includes('c'); // true
w.find(function(v, i, a) {
    if (v === 'b') {
    // do something
    }
}); // 'b'
w.findIndex(function(v, i, a) {
    if (v === 'b') {
    // do something
    }
}); // 1
w.forEach(function(v, i) { 
    if (v === 'b') { 
    // do something
    }
});

六 反转数组元素

var w = ['a', 'b', 'c'];
w.reverse(); // ["c", "b", "a"]

七 数组切片

var w = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
w.slice(2, 4); // ["c", "d"]

八 数组元素排序

var w = [4, 'e', 'z', 2, 'a', 'q', 9];
w.sort(); // [2, 4, 9, "a", "e", "q", "z"]
var w = [4, 7, 3, 2, 5, 8, 9];
w.sort(function(a, b) {
    return a - b;
}); // [2, 3, 4, 5, 7, 8, 9]

九 数组筛选

var w = [4, 'e', 'z', 2, 'a', 'q', 9];
var _w = w.filter(function(i) { return i > 0; }); // [4, 2, 9]

Javascript 字符串操作

一 字符串转换

// int to string
var n = 1; 
n.toString();
String(n);
'' + n
// string to int
var s = '123a';
Number(s);
parseInt(s); // 123 十进制
parseInt(s, 16); // 4666 十六进制
parseFloat(s); // 123
s = '123'; s - 0;

二 字符串分割

var s = 'abcdef-123456';
s.split('-'); // ['abcdef', '123456']
s.split('-', 1); // ['abcdef']

三 字符串查找

var s = 'abcdef';
s.indexOf('e'); // 4
s.lastIndexOf('e'); // 4
s.charAt(4); // e

四 字符串替换

var s = 'abcabc';
s.replace('a', '1'); // "1bcabc"
s.replace(/a/g, '1'); // "1bc1bc"

五 字符串匹配

var s = 'abcdef-123456';
s.match('ef'); // ["ef", index: 4, input: "abcdef-123456", ...]
s.match(/\w+/); // ["abcdef", index: 0, input: "abcdef-123456", ...]
s.match(/\w+/g); // ["abcdef", "123456"]
s.search(/\d+/); // 7

var reg = /\w+/;
reg.exec(s); // ["abcdef", index: 0, input: "abcdef-123456", ...]

六 字符串切割

var s = 'abcdef-123456';
s.substr(1, 4); // "bcde"
s.substring(1, 4); // "bcd"
s.slice(-3, -1); // "45"

七 大小写转换

var s = 'abcDEF-123456';
s.toLowerCase(); // "abcdef-123456"
s.toUpperCase(); // "ABCDEF-123456"

八 去除空格

var s = '  abc  ';
s.trim(); // "abc"

九 附录:字符串对象的所有方法

length
anchor()
big()
blink()
bold()
charAt()
charCodeAt()
concat()
constructor()
endsWith()
fixed()
fontcolor()
fontsize()
includes()
indexOf()
italics()
lastIndexOf()
link()
match()
matchAll()
normalize()
padEnd()
padStart()
repeat()
replace()
search()
slice()
small()
split()
startsWith()
strike()
sub()
substr()
substring()
sup()
toLocaleLowerCase()
toLocaleUpperCase()
toLowerCase()
toString()
toUpperCase()
trim()
trimEnd()
trimLeft()
trimRight()
trimStart()
valueOf()
hasOwnProperty()
isPrototypeOf()

清理Win10我的电脑中的各个文件夹

REM 我的电脑

REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{f86fa3ab-70d2-4fc7-9c99-fcbf05467f3a} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{24ad3ad4-a569-4530-98e1-ab02f9417aa8} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{d3162b92-9365-467a-956b-92703aca08af} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{088e3905-0323-4b02-9826-5d99428e115f} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{3dfdf296-dbec-4fb4-81d1-6a3438bcf4de} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641} /f
REG DELETE HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\{0DB7E03F-FC29-4DC6-9020-FF41B59E513A} /f

REM Onedrive

%SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall
REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f

保存为del.cmd,右键管理员权限运行