使用HTTP的.NET Remoting漏洞
初始Golang

初始Golang

基本语法

main.go

1
2
3
4
5
6
7
8
9
10
package main

import(
"fmt"
)

func main(){
fmt.Println("Hello World")
}

Template包

Template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

import (
"fmt"
"text/template"
"os"
"regexp"
)


func main(){
fmt.Println("Hello Go !")
tdata := []info{
{"abcabcabcfsdfsdfsdf"},
{"aaafsdgdfhergdfbdfgbdhdfgdg"},
}
replaceFuncMap := template.FuncMap{
"replaceAll":replaceAll,
}
tmpl, err := template.New("test").Funcs(replaceFuncMap).Parse(`
{{ range . }}
// {{ .Info }}
{{ replaceAll "(aaaa)" "1111" .Info
| replaceAll "(abc)" "【$1】"
| replaceAll "(aaa)" "【$1】"
}}
{{end}}`)
if err != nil { panic(err) }
err = tmpl.Execute(os.Stdout, tdata)
if err != nil { panic(err) }

var a string

fmt.Scanln(&a)
fmt.Print("input", a)
}

func replaceAll(from ,to, input string) string{
m1 := regexp.MustCompile(from)
return m1.ReplaceAllString(input,to)
// return strings.ReplaceAll(input,from ,to)
}


type info struct{
Info string
}

http 库

LSP初识以及gopls是什么

LSP初识以及gopls是什么

要谈 gopls,得先聊聊 LSP。

LSP 是什么

LSP,全称 Language Server Protocol,即语言服务器协议,这是微软创建的一个协议(目前已有 Codenvy,Red Hat 和 Sourcegraph 等公司一起支持它的发展)。定义了在编辑器或 IDE 中与语言服务器之间使用的协议,该语言服务器提供诸如自动完成,转到定义,查找所有引用等语言功能。语言服务器索引格式(LSIF,其发音类似于“ else if”)的目标是支持开发工具或 Web UI 中的富代码导航,而不需要源代码的本地副本。

目前该协议得到了编辑器和语言社区的广泛支持。

LSP 的官方网站:https://microsoft.github.io/language-server-protocol/,GitHub 地址:https://github.com/Microsoft/language-server-protocol。目前最新版本(2020-09-06):3.15。

LSP 解决了什么问题

为编程语言添加诸如自动完成、转到定义或鼠标悬停出现文档之类的功能需要付出大量的努力。传统上,这项工作必须为每个开发工具重复进行,因为每个工具为实现相同的特性提供不同的 api。

语言服务器(Language Server)旨在提供特定语言的智能功能,并通过支持进程间通讯协议与开发工具进行通信。

语言服务器协议(LSP)背后的思想是为这些服务器和开发工具的通信方式提供标准化协议支持。通过这种方式,可以在多个开发工具中重用单个 Language Server,而这些工具反过来可以用最少的工作支持多种语言。

例如,之前需要为 VSCode 构建 Go 插件、为 Sublime Text 构建 Go 插件、为 Vim 构建 Go 插件、为 Sourcegraph 构建 Go 插件,很多重复的工作。现在,对于每种语言,LSP 允许语言社区将精力集中在一个高性能语言服务器上,这个服务器可以提供代码完成,悬停文档提示、跳转到定义、查找引用等功能,而编辑器和客户端社区可以专注于构建一个单一的、高性能的、直观的和惯用的扩展,这个扩展可以与任何语言服务器通信,即时提供深入的语言支持。

LSP 是语言提供商和工具供应商的双赢!

LSP 的工作原理

语言服务器(Language Server)作为单独的进程运行,开发工具在 LSP 基础上通过 JSON-RPC 与服务器通信。下面是一个开发工具和语言服务器在进行编辑时如何通信的例子:
通信的示例
图片来自 LSP 官网,演示了协议如何在文档引用(uri)和文档位置级别与语言服务器通信。这些数据类型与编程语言无关,适用于所有编程语言。

How it works

The user opens a file (referred to as a document) in the tool: The tool notifies the language server that a document is open (‘textDocument/didOpen’). From now on, the truth about the contents of the document is no longer on the file system but kept by the tool in memory. The contents now has to be synchronized between the tool and the language server.

The user makes edits: The tool notifies the server about the document change (‘textDocument/didChange’) and the language representation of the document is updated by the language server. As this happens, the language server analyses this information and notifies the tool with the detected errors and warnings (‘textDocument/publishDiagnostics’).

The user executes “Go to Definition” on a symbol of an open document: The tool sends a ‘textDocument/definition’ request with two parameters: (1) the document URI and (2) the text position from where the ‘Go to Definition’ request was initiated to the server. The server responds with the document URI and the position of the symbol’s definition inside the document.

The user closes the document (file): A ‘textDocument/didClose’ notification is sent from the tool informing the language server that the document is now no longer in memory. The current contents are now up to date on the file system.

以下是在 C++ 文档中针对“Go to Definition”请求在开发工具和语言服务器之间传输的有效负载。

这是请求:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"jsonrpc": "2.0",
"id" : 1,
"method": "textDocument/definition",
"params": {
"textDocument": {
"uri": "file:///p%3A/mseng/VSCode/Playgrounds/cpp/use.cpp"
},
"position": {
"line": 3,
"character": 12
}
}
}

这是响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"uri": "file:///p%3A/mseng/VSCode/Playgrounds/cpp/provide.cpp",
"range": {
"start": {
"line": 0,
"character": 4
},
"end": {
"line": 0,
"character": 11
}
}
}
}

gopls 是什么

经过上面对 LSP 的介绍,你应该猜到 gopls(发音为“Go please”) 是什么了吧?!没错,gopls是由 Go 团队开发的官方 Go 语言服务器。它为任何 LSP 兼容的编辑器提供 IDE 功能。

在 LSP 官网列出了相关的实现,包括三个部分。

1、Language Servers:列出各个语言的 LSP 实现

其中 Go 语言的实现有两个:(Sourcegraph 的不再维护,因为集中维护一个会更好)
Alt text

gopls 是 Go 官方维护的、对 LSP 的实现,即一个 Go 语言的官方 Language Server。

2、LSP Clients:列出支持 LSP 的开发工具

包括 VSCode、Sublime Text、Atom、Emacs、Vim 和 Eclipse 等很多开发工具。在上文提到的两个网站都有列出。

3、SDKs for LSP:为了方便开发

为了方便开发,还有一些 LSP 的 SDK 可以使用。具体可以查看:https://microsoft.github.io/language-server-protocol/implementors/sdks/。

进一步了解 gopls

首先说明下,目前 gopls 还不是稳定版本,处于 alpha 状态,所以 VSCode 默认没有启用它。项目地址:https://github.com/golang/tools/tree/master/gopls。

目前 gopls 支持的特性包括:

  • Autocompletion
  • Jump to definition
  • Signature help
  • Hover
  • Document symbols
  • References
  • Rename

目前已知存在如下的问题:

  • Editing multiple modules in one editor window: #32394[1]
  • Type checking does not work in cgo packages: #35721[2]
  • Does not work with build tags: #29202[3]
  • Find references and rename only work in a single package: #32877[4]

当前 gopls 的工作重点是确保稳定性(期待发布 1.0 版本),之前一直受诟骂的是资源占用,目前已经好太多了。

有如下编辑器支持 gopls,你可以根据自己喜爱的编辑器查看相应的安装、配置说明。

  • VSCode[5]
  • Vim Neovim Vim/Neovim[6]
  • Emacs[7]
  • Acme[8]
  • Sublime Text[9]
  • Atom[10]
Windows工具记录
初始PWA【一】
Lambda表达式常见用法笔记
sqlserver数据库dump文件分析
Shell笔记

Shell笔记

获取入参

方式一:$0,$1,$2..

采用$0,$1,$2..等方式获取脚本命令行传入的参数,值得注意的是,$0获取到的是脚本路径以及脚本名,后面按顺序获取参数,当参数超过10个时(包括10个),需要使用${10},${11}….才能获取到参数,但是一般很少会超过10个参数的情况。

test.sh
1
2
3
4
5
6
7
#!/bin/bash
echo "脚本$0"
echo "第一个参数$1"
echo "第二个参数$2"
……
echo "第十个参数$10"
echo "第十个参数${10}"

在shell中执行脚本,结果如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$>./test.sh a b c d e f g h i j

#shell中将会输出:
脚本名./test.sh
第一个参数a
第二个参数b
第三个参数c
第四个参数d
第五个参数e
第六个参数f
第七个参数g
第八个参数h
第九个参数i
第十个参数a0
第十个参数j

可以看到${10}正确读取到了第十个参数,而$10被分成$1读取到第一个参数a然后拼接字符串0,于是输出a0。

优点:获取参数更容易,执行脚本时需要的输入少

缺点:必须按照顺序输入参数,如果中间漏写则参数对应就会错误

方式二:getopts

语法格式:getopts [option[:]] [DESCPRITION] VARIABLE
option:表示为某个脚本可以使用的选项
“:”:如果某个选项(option)后面出现了冒号(”:”),则表示这个选项后面可以接参数(即一段描述信息DESCPRITION)
VARIABLE:表示将某个选项保存在变量VARIABLE中

test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
while getopts ":a:b:c:" opt
do
case $opt in
a)
echo "参数a的值$OPTARG"
;;
b)
echo "参数b的值$OPTARG"
;;
c)
echo "参数c的值$OPTARG"
;;
?)
echo "未知参数"
exit 1;;
esac
done

用一个while循环加case分支获取不同参数,:a:b:c相当于定义参数的变量名,有时候可能会有未知参数,所以增加一个?的分支。

在shell中执行脚本,结果如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$>./test.sh -a 1 -b 2 -c 3

#在shell中的输出
参数a的值1
参数b的值2
参数c的值3
$>./test.sh -a 1 -c 3

#在shell中的输出
参数a的值1
参数c的值3
$>./test.sh -a 1 -c 3 -d 4

#在shell中的输出
参数a的值1
参数c的值3
未知参数

优点:由于使用了-a加参数值的方式进行一一匹配,所以不会参数匹配错误,同时也可以缺省参数,并不会导致参数错误,同时也便于后期参数的扩展和移植

缺点:脚本执行时参数需要的输入会增多

字符串变量截取、替换和删除

获取变量字符串长度

想要知道"www.baidu.com"的变量net的长度十分简单,通过$

IIS应用HTTP协议升级HTTPS

IIS应用HTTP协议升级HTTPS

前言

应用旧访问地址:http://192.168.1.1:6622/xxxx

SSL证书生成

绑定证书

一、IIS配置证书绑定,启用HTTPS

优点:方便、快捷,删除原先端口绑定的HTTP,添加新的HTTPS协议至原端口。

缺点:如果应用程序在很多地方使用,协议升级后,原地址:http://192.168.1.1:6622 这种访问形式会失效,如果存在大量引用,会导致工作量大、难排查的问题

改进

IIS配置里删除应用的旧绑定端口(6622),新增一个端口(6500)用于Nginx代理目标
tips: IIS里6500端口可以不配置证书,使用Nginx中配置的证书。
通过Nginx监听原先端口,配置SSL证书文件,利用Nginx自带的497状态,将HTTP访问升级至HTTPS访问

配置文件:

nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
server {
listen 6622 ssl;
server_name 192.168.1.1;
# SSL
ssl_certificate cert/DEMO.crt;
ssl_certificate_key cert/DEMO.key;
# 中间证书
ssl_trusted_certificate cert/RootCA.crt;
error_page 497 301 =307 https://$host:6622$request_uri;
location /{
proxy_pass http://$host:6500; #请求转发至新端口
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl on;
}
}

# 情况 服务器只开放6530 一个https的端口
# nginx 通过监听6530的访问情况,使用497处理http访问异常,重定向至https的6530端口
# https访问后,nginx内部代理访问内网的6529端口【实际服务所在端口】,
# 再 使用proxy_redirect 修改6529传来的应答头中的"Location"和"Refresh"字段
# 这样就实现了http和https的兼容,并且不需要修改其它项目中的地址。
server {
listen 6530 ssl;
server_name localhost;
# SSL
ssl_certificate cert/124-221-233-39_DEMO.crt;
ssl_certificate_key cert/124-221-233-39_DEMO.key;
ssl_trusted_certificate cert/124-221-233-39_RootCA.crt;

location /{
# proxy_ssl_server_name on;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host:$server_port;;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://10.0.4.13:6529;
proxy_redirect http://10.0.4.13:6529 /;
}
error_page 497 301 =307 https://$host:$server_port$request_uri;
}

参考:
https://stackoverflow.com/questions/16669773/nginx-reverse-proxy-to-backend-running-on-localhost
https://blog.csdn.net/faye0412/article/details/75200607
https://blog.csdn.net/jycjyc/article/details/106191981
https://blog.csdn.net/qq_27745471/article/details/124735251
How to redirect on the same port from http to https with nginx reverse proxy
nginx redirect http to https with custom port server

二、使用IIS的URL重写组件【只适用有域名的】

参考:
https://aboutssl.org/iis-redirection-http-to-https/
https://learn.microsoft.com/en-us/answers/questions/762252/iis-10-redirect-http-to-httpsmysitecom.html
IIS中实现HTTPS的自动跳转
URL 重写模块配置引用
URL Rewrite Module 2.0 Configuration Reference
IIS Server Variables

Oracle创建视图并授权

Oracle创建视图并授权

Oracle 创建视图

Oracle 用户创建、授权

Oracle创建用户、角色、授权、建表空间
Oracle创建视图(View)

Sql

test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

--在CDR有创建视图权限的帐户下,创建视图test2

CREATE OR REPLACE VIEW TEST2 AS
SELECT HIS_PAT_PAGE from HIS_PAT_INFO
WITH READ ONLY


--在使用DBA或者有权限的用户帐户下执行

create user VTEST identified by VTEST;--创建用户VTEST

grant create session to VTEST;--授予登录权限

grant select on CDR."TEST2" to VTEST;--授予VTEST用户查看CDR的TEST2视图权限

grant CREATE SYNONYM to VTEST; --授权VTEST用户创建同义词权限

create synonym VTEST.TEST2 for CDR.TEST2;--创建同义词 TEST2 替代CDR.TEST2


--使用VTEST用户登录查询

select * from

select * from TEST2 where rownum <5;--同义词

select * from CDR.TEST2 where rownum <5;--没有同义词,必须使用用户名前缀。


--在使用DBA或者有权限的用户帐户下执行

--撤销授权

REVOKE CREATE SYNONYM FROM VTEST;--撤销创建同义词权限

REVOKE select on CDR."TEST2" FROM VTEST;--撤销TEST2视图的查看权限
--删除用户

drop user VTEST cascade;--使用 cascade参数可以删除该用户的全部objects【并没有删除相应的表空间】

--删除视图TEST2

drop view TEST2

CASCADE参数:

CASCADE

使用 cascade参数可以删除该用户的全部objects。要说明的如下:

如果用户的schema中有表,则在删除表的时候自动删除与该表相关的主键和外键。

如果用户的schema中有表,则在删除表的时候自动删除与该表相关的索引。

删除用户时,用户在其他用户中的objects不会被删除,只会被置为无效。

视图,同义词,存储过程,函数,包;

其他用户建立的基于被删除用户的物化视图不会被删除,只是不能在刷新了。

用户模式下的所有触发器全部被删除

被删除用户建立的其他用户不会被删除

参考

oracle删除当前用户以及当前用户所有表、索引等操作
Oracle中drop user和drop user cascade的区别

拓展笔记

oracle表名不打双引号查不到原因

1、oracle表和字段是有大小写的区别。oracle默认是大写,如果我们用双引号括起来的就区分大小写,如果没有,系统会自动转成大写。

2、我们在使用navicat使用可视化创建数据库时候,navicat自动给我们加上了“”

Oracle 创建、查看用户

  • 查看所有用户:
1
2
3
4
5
select * from dba_users;--描述数据库的所有用户

select * from all_users;--列出对当前用户可见的数据库的所有用户

select * from user_users;--描述当前用户。此视图不显示 PASSWORD 、 PROFILE 、 PASSWORD_VERSIONS 、 EDITIONS_ENABLED 、 AUTHENTICATION_TYPE 和 LAST_LOGIN 列。
  • 查看用户或角色系统权限(直接赋值给用户或角色的系统权限):
1
2
3
select * from dba_sys_privs;--描述授予用户和角色的系统权限

select * from user_sys_privs;-- (查看当前用户所拥有的权限)
  • 查看角色(只能查看登陆用户拥有的角色)所包含的权限
1
2
select * from role_sys_privs;

  • 查看用户对象权限:
1
2
3
4
5
select * from dba_tab_privs;

select * from all_tab_privs;

select * from user_tab_privs;
  • 查看所有角色:
1
select * from dba_roles;
  • 查看用户或角色所拥有的角色:
1
2
3
select * from dba_role_privs;

select * from user_role_privs;
  • 查看哪些用户有sysdba或sysoper系统权限(查询时需要相应权限)
1
select * from V$PWFILE_USERS
  • SqlPlus中查看一个用户所拥有权限
1
2
3
4
select * from dba_sys_privs where grantee='username'; --其中的username即用户名要大写才行。

--比如:
select * from dba_sys_privs where grantee='TOM';

REVOKE回收权限

  • 回收角色权限
1
REVOKE CONNECT,RESOURCE FROM chenmh;
  • 回收系统权限
1
REVOKE CREATE FROM chenmh;
  • 回收用户对象权限,回收zhang用户下person表的所有权限,如果是单个授予的权限需要单个的收回
1
REVOKE ALL PRIVILEGES ON zhang.person FROM chenmh;
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×