LocalStorage跨页面,但是不跨域。如果没跨域,浏览器调试模式看一下localStorage中存储的内容在不在
没有足够的数据
(゚∀゚ )
暂时没有任何数据
Leeee 回答了问题 · 3月23日
LocalStorage跨页面,但是不跨域。如果没跨域,浏览器调试模式看一下localStorage中存储的内容在不在
LocalStorage跨页面,但是不跨域。如果没跨域,浏览器调试模式看一下localStorage中存储的内容在不在
关注 4 回答 3
Leeee 回答了问题 · 1月21日
可以,使用下面命令可以测试一下
su pi -c "~/shairport/shairport -a 'RaspberryPi'"
可以,使用下面命令可以测试一下 {代码...}
关注 1 回答 1
Leeee 回答了问题 · 1月21日
Python方法
1、开机启动,使用request.open去测试公网网址,如www.baidu.com,直至成功
def check_net(testserver):
try:
logger.debug("判断网络是否连接")
ret = request.urlopen(url=testserver, timeout=3.0)
# print(ret)
except:
return False
return True
# 判断网络是否已经连接
while check_net('https://www.baidu.com') == 0:
logger.debug("网络尚未连接,sheep 100")
time.sleep(100)
else:
logger.debug("网络连接成功")
time.sleep(100)
Python方法1、开机启动,使用request.open去测试公网网址,如www.baidu.com,直至成功 {代码...} {代码...}
关注 3 回答 2
Leeee 发布了文章 · 1月19日
平时用的最多的扫描枪通常只是一个简单的输入设备(好比键盘,鼠标), 另一头需要连接电脑, 用的 usb 或者串口. 扫描枪负责识别条码, 电脑收到后执行业务的逻辑. 有时候只是简单的数据采集工作, 数据传到服务器云端;
带 USB 接收器的无线扫码请条码扫描枪(本案例以新大陆OY26-RF无线扫描枪为例)
树莓派 4b
我们将用到 python-evdev 程序库, 封装了对 usb 设备的读写操作. 官网 https://python-evdev.readthedocs.io/
sudo pip install evdev
将扫码枪的无线接收器插入树莓派的USB口,在树莓派上新建python文件,拷贝下方代码并执行,检测设备能否发现
#!/usr/bin/python3
import evdev
# 列出 usb 设备
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
print('发现设备: ')
for device in devices:
print(device.path, device.name, device.phys)
执行结果如下表示发现设备:
/dev/input/event0 Netum. HIDKB usb-0000:01:00.0-1.3/input0
扫码枪接入设备后,默认是以键盘的方式接入,读取二维码时,是以一个字符一个字符的方式逐个读取的,默认扫码不增加结束符后缀,程序无法确认是否扫码结束,需要增加结束符来区分
使用扫码枪,扫瞄下方的条码(一次不行的话可以扫描多次),增加TAB结束符;
import evdev
import time
import findScanGun
from evdev import InputDevice, categorize, ecodes
class ScanGun:
dev = findScanGun.find()
device = InputDevice(dev) # my keyboard
scancodes = {
0: None, 1: u'ESC', 2: u'1', 3: u'2', 4: u'3', 5: u'4', 6: u'5', 7: u'6', 8: u'7', 9: u'8',
10: u'9', 11: u'0', 12: u'-', 13: u'=', 14: u'BKSP', 15: u'TAB', 16: u'q', 17: u'w', 18: u'e', 19: u'r',
20: u't', 21: u'y', 22: u'u', 23: u'i', 24: u'o', 25: u'p', 26: u'[', 27: u']', 28: u'CRLF', 29: u'LCTRL',
30: u'a', 31: u's', 32: u'd', 33: u'f', 34: u'g', 35: u'h', 36: u'j', 37: u'k', 38: u'l', 39: u':',
40: u'"', 41: u'`', 42: u'LSHFT', 43: u'\\', 44: u'z', 45: u'x', 46: u'c', 47: u'v', 48: u'b', 49: u'n',
50: u'm', 51: u',', 52: u'.', 53: u'/', 54: u'RSHFT', 56: u'LALT', 57: u' ', 100: u'RALT'
}
capscodes = {
0: None, 1: u'ESC', 2: u'!', 3: u'@', 4: u'#', 5: u'$', 6: u'%', 7: u'^', 8: u'&', 9: u'*',
10: u'(', 11: u')', 12: u'_', 13: u'+', 14: u'BKSP', 15: u'TAB', 16: u'Q', 17: u'W', 18: u'E', 19: u'R',
20: u'T', 21: u'Y', 22: u'U', 23: u'I', 24: u'O', 25: u'P', 26: u'{', 27: u'}', 28: u'CRLF', 29: u'LCTRL',
30: u'A', 31: u'S', 32: u'D', 33: u'F', 34: u'G', 35: u'H', 36: u'J', 37: u'K', 38: u'L', 39: u':',
40: u'\'', 41: u'~', 42: u'LSHFT', 43: u'|', 44: u'Z', 45: u'X', 46: u'C', 47: u'V', 48: u'B', 49: u'N',
50: u'M', 51: u'<', 52: u'>', 53: u'?', 54: u'RSHFT', 56: u'LALT', 57: u' ', 100: u'RALT'
}
#是否大小写,默认小写
caps = False
#setup vars
x = ''
# grab 是为了独占,保证此设备不会被别的进程捕获
device.grab()
def run(self):
start = time.time()
for event in self.device.read_loop():
if event.type == ecodes.EV_KEY:
data = categorize(event) # Save the event temporarily to introspect it
# 判断按键是不是SHIFT,如果是SHIFT按住的,需要大写锁定,如果事件是松开的那就解除大写锁定
if data.scancode == 42:
if data.keystate == 1:
caps = True
if data.keystate == 0:
caps = False
if data.keystate == 1:
# 判断SHIFT键是不是按住的,如果是按住的就读取大写字母
if self.caps:
key_lookup =self.capscodes.get(data.scancode)
else:
key_lookup = self.scancodes.get(data.scancode)
# SHFT,CTRL,TAB属于特殊按键,不计算在扫码内容结果中
if (data.scancode != 42) and (data.scancode != 28) and (data.scancode != 15):
self.x += key_lookup
if(data.scancode == 15):
print("识别结束:",time.time()-start)
# 解除设备独占,关闭设备
self.device.ungrab()
self.device.close() # Print it all out!
return self.x;
scangun = ScanGun()
list= scangun.run()
print(list)
查看原文平时用的最多的扫描枪通常只是一个简单的输入设备(好比键盘,鼠标), 另一头需要连接电脑, 用的 usb 或者串口. 扫描枪负责识别条码, 电脑收到后执行业务的逻辑. 有时候只是简单的数据采集工作, 数据传到服务器云端;
赞 0 收藏 0 评论 0
Leeee 发布了文章 · 1月19日
树莓派开机启动默认的图片为splash.png
,图像存储路径位于:/usr/share/plymouth/themes/pix/splash.png
直接修改图片就好
在配置文件中,将开机启动图片路径修改成设备本地的图片路径即可
sudo vim /usr/share/plymouth/themes/pix/pix.plymouth
在上述文件中,修改ImageDir配置即可,默认值为:/usr/share/plymouth/themes/pix
ImageDir=/usr/share/plymouth/themes/pix
fbset
它将返回类似
mode "1920x1080"
geometry 1920 1080 1920 1080 32
timings 0 0 0 0 0 0 0
rgba 8/16,8/8,8/0,8/24
endmode
其中,mode "1920x1080"
即代表设备的分辨率是1920x1080;
设计相同分辨率的开机启动图片,命名为splash.png
,然后将该文件复制到树莓派上
scp splash.png pi@192.155.198.46:/home/pi/
然后从桌面将splash.png文件复制到Plymouth目录中。
sudo cp /home/pi/splash.png /usr/share/plymouth/themes/pix/splash.png
如果您希望它干净,现在可以从主目录中删除splash.png
。
sudo vim /boot/config.txt
在内容的第一行增加 disable_splash=1
sudo vim /usr/share/plymouth/themes/pix/pix.script
注释掉以下几行(即,在开头添加“#”):
message_sprite = Sprite();
message_sprite.SetPosition(screen_width * 0.1, screen_height * 0.9, 10000);
my_image = Image.Text(text, 1, 1, 1);
message_sprite.SetImage(my_image);
sudo vim /boot/cmdline.txt
在源文件的末尾添加一下内容,保存
logo.nologo vt.global_cursor_default=0
sudo reboot
查看原文树莓派开机启动默认的图片为splash.png,图像存储路径位于:/usr/share/plymouth/themes/pix/splash.png直接修改图片就好
赞 0 收藏 0 评论 0
Leeee 发布了文章 · 1月19日
ufw是一个主机端的iptables类防火墙配置工具,比较容易上手。如果你有一台暴露在外网的树莓派,则可通过这个简单的配置提升安全性。
sudo apt-get install ufw
开启防火墙并随系统启动同时关闭所有外部对本机的访问(本机访问外部正常)。
sudo ufw enable sudo ufw default deny
sudo ufw disable
sudo ufw status
> sudo ufw allow 80 允许外部访问80端口
> sudo ufw delete allow 80 禁止外部访问80 端口
> sudo ufw allow from 192.168.1.1 允许此IP访问所有的本机端口
> sudo ufw deny smtp 禁止外部访问smtp服务
> sudo ufw delete allow smtp 删除上面建立的某条规则
> ufw deny proto tcp from 10.0.0.0/8 to 192.168.0.1 port 要拒绝所有的流量从TCP的10.0.0.0/8 到端口22的地址192.168.0.1
可以允许所有RFC1918网络(局域网/无线局域网的)访问这个主机(/8,/16,/12是一种网络分级):
sudo ufw allow from 10.0.0.0/8
sudo ufw allow from 172.16.0.0/12
sudo ufw allow from 192.168.0.0/16
sudo apt-get install ufw
sudo ufw enable
sudo ufw default deny
查看原文ufw是一个主机端的iptables类防火墙配置工具,比较容易上手。如果你有一台暴露在外网的树莓派,则可通过这个简单的配置提升安全性。1、安装 {代码...} 2、启用开启防火墙并随系统启动同时关闭所有外部对本机的访问(本机访问外部正常)。 {代码...} 3、关闭 {代码......
赞 0 收藏 0 评论 0
Leeee 收藏了文章 · 1月7日
众所周知 HTTPS 是保证 HTTP 通讯安全的协议,网站启用 HTTPS 可以避免很多安全性的问题, 而且 Chrome 浏览器 从 68 版本开始直接将 HTTP 网站标记为不安全了。
所以把网站升级成 HTTPS 自然是大势所趋,不过启用 HTTPS 有个最重要的问题是 HTTPS 证书要花钱
!如果每年额外花钱去购买 HTTPS 证书,那也是一笔很大的开销。那么有没有免费的HTTPS
证书可以用呢,查了下资料有个叫Let’s Encrypt
的项目就提供了免费签发 HTTPS 证书的服务,这里记录下如何使用Let’s Encrypt
来签发证书。
certbot
是用于从 Let's Encrypt 获取证书的命令行工具,代码开源在github上。
使用certbot
命令行工具可以轻松的实现HTTPS证书
签发,在签发证书之前,需要证明签发的域名是属于你控制的,目前certbot
有两种验证方式:
certbot
会生成一个特定的文件名和文件内容,要求放在你对应域名下对应路径(/.well-known/acme-challenge/
)下,然后certbot
再通过 HTTP 请求访问到此文件,并且文件内容与生成时候的一致。例如:certbot
生成文件名check
和内容!@#$%^
,你需要申请的域名为baidu.com
,则certbot
访问http://baidu.com/.well-known/acme-challenge/check
来校验是否与生成的内容一致。
certbot
生成一段特定的文本,要求在你对应域名中配置一条对应子域名(_acme-challenge
)的TXT
类型解析记录。例如:certbot
生成内容!@#$%^
,你需要申请的域名为baidu.com
,则需要添加一条_acme-challenge.baidu.com
的TXT
类型解析记录,值为之前生成的内容。
在域名验证通过之后,certbot
就可以签发HTTPS
证书了,注意在此验证步骤基础上,certbot
提供了很多开箱即用的自动验证方案,但是都不符合我的需求,原因是我需要支持通配符
域名的证书,但是这种证书只支持DNS
验证方式,而官方提供的DNS
插件中并没有支持我用的阿里云DNS
,所以只能自己去实现 阿里云的 DNS 自动校验。
通过官网教程可以选择对应操作系统,并获取安装步骤:
这里我选择的Debian 9
,根据官网的提示进行安装:
sudo apt-get install certbot -t stretch-backports
注:如果install失败可以先执行下 apt-get update
开始签发证书
certbot certonly --cert-name pdown.org -d *.pdown.org,*.proxyee-down.com --manual --register-unsafely-without-email --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
这里签发了一个支持*.pdown.org
和*.proxyee-down.com
通配符域名的证书,注意如果是通配符域名证书需要指定--server https://acme-v02.api.letsencrypt.org/directory
示例:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Registering without email!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for pdown.org
dns-01 challenge for proxyee-down.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.pdown.org with the following value:
Axdqtserd184wvJc86Dxen386UXqbK2wrgb-*******
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
这里会生成一串随机字符并阻塞住,需要去设置一条对应的 TXT 类型的 DNS 解析记录再继续,在设置好之后可以用nslookup
进行本地验证:
nslookup -type=txt _acme-challenge.pdown.org
服务器: UnKnown
Address: 192.168.200.200
非权威应答:
_acme-challenge.pdown.org text =
"Tit0SAHaO3MVZ4S-d6CjKLv6Z-********"
本地验证通过之后按回车键继续,接着 Let's Encrypt 就会校验这个 DNS 解析记录是否正确,校验通过后就会进行下一个域名的验证直到全部验证通过。
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/pdown.org/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/pdown.org/privkey.pem
Your cert will expire on 2019-12-02. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
当验证通过的时候会输出证书生成的目录,里面会包含证书和对应的私钥,这里目录是/etc/letsencrypt/live/pdown.org/
。
证书截图:
这样证书就生成好了,之后只需要把证书和私钥配置到nginx
中就可以用https
访问了。
上面证书虽然是生成好了,但是证书的有效期只有三个月,意味着每过三个月就得重新签发一个新的证书,一不注意证书就过期了,而且每次手动签发都非常的繁琐需要去手动设置 DNS 解析,所以certbot
提供了一种自动续签的方案:hook
在创建证书的时候certbot
提供了两个hook
参数:
通过自定义这两个脚本就可以做到自动续签了,文档参考pre-and-post-validation-hooks。
在此基础上,官方已经提供了很多云厂商的自动续签方案,但是我用的阿里云官方并没有提供,于是参照官网文档,写了一个基于阿里云的自动续签脚本,在验证域名的脚本中通过阿里提供的 DNS API 添加一条域名解析记录,在验证完成之后再把刚刚那条域名解析记录删除,命令行调用如下:
certbot certonly --cert-name pdown.org -d *.pdown.org,*.proxyee-down.com --manual --register-unsafely-without-email --manual-auth-hook /path/to/dns/authenticator.sh --manual-cleanup-hook /path/to/dns/cleanup.sh --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
为了方便使用,提供了一个docker镜像
,通过环境变量将阿里云 API 调用的 AK 传递就可以生成和续签证书了。
docker run \
--name cert \
-itd \
-v /etc/letsencrypt:/etc/letsencrypt \
-e ACCESS_KEY_ID=XXX \
-e ACCESS_KEY_SECRET=XXX \
liwei2633/certbot-aliyun
docker exec -it cert ./create.sh *.pdown.org
创建过程中会等待一段时间,来确保 dns 记录生效,完成之后在/etc/letsencrypt/live
目录下可以找到对应的证书文件
docker exec cert ./renew.sh
代码开源在github,欢迎 start。
我是MonkeyWie,欢迎扫码👇👇关注!不定期在公众号中分享JAVA
、Golang
、前端
、docker
、k8s
等干货知识。
众所周知 HTTPS 是保证 HTTP 通讯安全的协议,网站启用 HTTPS 可以避免很多安全性的问题, 而且 Chrome 浏览器 从 68 版本开始直接将 HTTP 网站标记为不安全了。
查看全部 个人动态 →
(゚∀゚ )
暂时没有
注册于 2015-01-13
个人主页被 421 人浏览
推荐关注