easy_whitelist 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ .vscode/
3
+ *.code-workspace
4
+ dist/
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ .
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) qiqilelebaobao
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.1
2
+ Name: easy_whitelist
3
+ Version: 1.0.2
4
+ Summary: Easy_whitelist is a small tool that detects the local Internet IP address and automatically updates the local Internet IP address to the cloud security group whitelist.
5
+ Author: qiqilelebaobao
6
+ Author-email: qiqilelebaobao <qiqilelebaobao@163.com>
7
+ Description-Content-Type: text/markdown
8
+ Classifier: License :: OSI Approved :: Apache Software License
9
+ Project-URL: Homepage, https://github.com/qiqilelebaobao/easy_whitelist
10
+
11
+ # Easy_whitelist
12
+
13
+ Easy_whitelist 是一个探测本机互联网 IP 地址,将并本机互联网IP地址,自动更新到云安全组白名单的小工具。工具使用 Python 编写。
14
+
15
+ Easy_whitelist is a small tool that detects the local Internet IP address and automatically updates the local Internet IP address to the cloud security group whitelist. The tool is written in Python.
16
+
17
+ 主要功能包括:
18
+ * 自动探测本机互联网 IP 地址
19
+ * 支持阿里云、腾讯云的安全组白名单更新
20
+ * 腾讯云支持地址模板更新
21
+
22
+ Main functions include:
23
+ * Automatically detect the local Internet IP address
24
+ * Support security group whitelist updates for Alibaba Cloud and Tencent Cloud
25
+ * Tencent Cloud supports address template updates
26
+
27
+ ## 适用场景 Applicable Scenarios
28
+
29
+ * 场景一:不知道如何探测本机的公网IP的用户,通过本工具自动探测公网 IP,并添加云安全组白名单
30
+ * 场景二:IP 地址因为 NAT 环境经常变化,包括家庭环境或者公司无固定出口 IP 的宽带环境,需要安全的使用云环境资源
31
+ * 场景三:测试场景,频繁变换客户端环境,需要安全的使用云环境资源
32
+
33
+ * Scene1: Users who do not know how to detect the public IP of their local machine can use this tool to automatically detect the public IP and add it to the cloud security group whitelist
34
+ * Scene2: IP addresses often change due to NAT environments, including home environments or broadband environments without fixed export IPs in companies, which require safe use of cloud environment resources
35
+ * Scene3: Test scenarios, frequent changes in client environments, which require safe use of cloud environment resources
36
+
37
+ ## 安装指南 Installation Guide
38
+
39
+ 需要 Python3 环境
40
+ Python3 is required
41
+
42
+ ```shell
43
+ $ pip3 install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python
44
+ ```
45
+
46
+ ## 使用说明 Instructions
47
+
48
+ ```shell
49
+ $ python3 easy.py -t template list
50
+ ```
51
+
@@ -0,0 +1,40 @@
1
+ # Easy_whitelist
2
+
3
+ Easy_whitelist 是一个探测本机互联网 IP 地址,将并本机互联网IP地址,自动更新到云安全组白名单的小工具。工具使用 Python 编写。
4
+
5
+ Easy_whitelist is a small tool that detects the local Internet IP address and automatically updates the local Internet IP address to the cloud security group whitelist. The tool is written in Python.
6
+
7
+ 主要功能包括:
8
+ * 自动探测本机互联网 IP 地址
9
+ * 支持阿里云、腾讯云的安全组白名单更新
10
+ * 腾讯云支持地址模板更新
11
+
12
+ Main functions include:
13
+ * Automatically detect the local Internet IP address
14
+ * Support security group whitelist updates for Alibaba Cloud and Tencent Cloud
15
+ * Tencent Cloud supports address template updates
16
+
17
+ ## 适用场景 Applicable Scenarios
18
+
19
+ * 场景一:不知道如何探测本机的公网IP的用户,通过本工具自动探测公网 IP,并添加云安全组白名单
20
+ * 场景二:IP 地址因为 NAT 环境经常变化,包括家庭环境或者公司无固定出口 IP 的宽带环境,需要安全的使用云环境资源
21
+ * 场景三:测试场景,频繁变换客户端环境,需要安全的使用云环境资源
22
+
23
+ * Scene1: Users who do not know how to detect the public IP of their local machine can use this tool to automatically detect the public IP and add it to the cloud security group whitelist
24
+ * Scene2: IP addresses often change due to NAT environments, including home environments or broadband environments without fixed export IPs in companies, which require safe use of cloud environment resources
25
+ * Scene3: Test scenarios, frequent changes in client environments, which require safe use of cloud environment resources
26
+
27
+ ## 安装指南 Installation Guide
28
+
29
+ 需要 Python3 环境
30
+ Python3 is required
31
+
32
+ ```shell
33
+ $ pip3 install -i https://mirrors.tencent.com/pypi/simple/ --upgrade tencentcloud-sdk-python
34
+ ```
35
+
36
+ ## 使用说明 Instructions
37
+
38
+ ```shell
39
+ $ python3 easy.py -t template list
40
+ ```
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
@@ -0,0 +1,9 @@
1
+ r"""Easy_whitelist is a small tool that detects the local Internet IP address and automatically updates the local Internet IP address to the cloud security group whitelist.
2
+
3
+ Reference: https://github.com/qiqilelebabao/easy_whitelist
4
+ The tool is written in Python.
5
+ """
6
+ __version__ = '1.0.2'
7
+ __author__ = 'qiqileleabaobao <qiqilelebaobao@163.com>'
8
+
9
+ __all__ = []
@@ -0,0 +1,2 @@
1
+
2
+ __all__ = ['arg']
@@ -0,0 +1,22 @@
1
+ import argparse
2
+
3
+ def init_arg():
4
+ '''parse parameter from command line.'''
5
+
6
+ parser = argparse.ArgumentParser(prog='python3 easy.py', description='This is a cloud acl auto whitelist program.', epilog='Enjoy the tool. :) ')
7
+
8
+ my_group = parser.add_mutually_exclusive_group(required=True)
9
+ my_group.add_argument('-t', '-T', '--tencent', action='store_true', help='tencent cloud')
10
+ my_group.add_argument('-a', '-A', '--alibaba', action='store_true', help='alibaba cloud')
11
+
12
+ parser.add_argument('-p', '-P', '--proxy', action='store', default=-1, type=int, help ='local HTTP proxy port')
13
+
14
+ parser.add_argument('target', help='template or rule', choices=['template', 'rule'])
15
+ parser.add_argument('action', help='list', choices=['list', 'set', 'create'])
16
+ parser.add_argument('target_id', help='template id or rule id', nargs='?')
17
+
18
+ args = parser.parse_args()
19
+
20
+ # print(args)
21
+
22
+ return args.tencent, args.alibaba, args.action, args.target, args.target_id, args.proxy
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import json
5
+ import os
6
+ import pprint
7
+ import string
8
+ import sys
9
+
10
+ from whitelist.config import arg
11
+ from whitelist.tcloud import client
12
+ from whitelist.tcloud.template import list_template, set_template, create_template
13
+
14
+ def loop_list(common_client):
15
+ template_ids = list_template(common_client)
16
+ last_input = None
17
+ while True:
18
+ input_from_user = input('Please choose # template to set (or [L]ist or [Q]uit): ')
19
+ if last_input == '' and input_from_user == '':
20
+ break
21
+ last_input = input_from_user
22
+ if input_from_user.isdigit():
23
+ if template_ids:
24
+ if (a := int(input_from_user)) > 0 and a <= len(template_ids):
25
+ set_template(common_client, template_ids[a - 1])
26
+ else:
27
+ print('Wrong #, please input # from list.')
28
+ elif input_from_user == 'l' or input_from_user == 'L':
29
+ list_template(common_client)
30
+ elif input_from_user == 'q' or input_from_user == 'Q':
31
+ break
32
+ else:
33
+ print('Input error...')
34
+
35
+ def main():
36
+ tencent, alibaba, action, target, target_id, proxy = arg.init_arg()
37
+ # print(tencent, alibaba, action, target, target_id, proxy)
38
+
39
+ common_client = client.get_common_client(proxy)
40
+
41
+ if tencent and target == 'template':
42
+ if action == 'list':
43
+ loop_list(common_client)
44
+ elif action == 'set':
45
+ set_template(common_client, target_id)
46
+ elif action == 'create':
47
+ create_template(common_client, target_id)
48
+ else:
49
+ print('Wrong postion, shall not be here.')
50
+
51
+ if __name__ == '__main__':
52
+
53
+ main()
File without changes
@@ -0,0 +1,5 @@
1
+
2
+ safari_user_ageent = ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15']
3
+ chrome_user_agent = ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36']
4
+ edge_user_agent = ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0']
5
+ curl_user_agent = ['curl/8.6.0', 'curl/7.29.0']
@@ -0,0 +1,57 @@
1
+ import requests
2
+ import sys
3
+ import random
4
+ import re
5
+
6
+ from . import url
7
+
8
+ def get_local_ip_from_url_and_parse(u, patt, ag):
9
+ # 发送GET请求
10
+ headers = {'user-agent': ag}
11
+ # print(f'user_agent:{ag}')
12
+ try:
13
+ response = requests.get(u, headers=headers, timeout=60)
14
+ # 获取响应内容
15
+ respon = response.text
16
+ l_ip = url.parse_ip_from_response(respon, patt)
17
+ return l_ip
18
+ except Exception:
19
+ return None
20
+
21
+ def validate_ip(l_ip):
22
+ if not l_ip:
23
+ return False
24
+
25
+ # r'(?:(?:25[0-5]|2[0-4][0-9]|[1]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[1]?[0-9][0-9]?)'
26
+ # r'(?:\d{1,3}\.){3}\d{1,3}'
27
+ # r'((?:[1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:[1-9]?\d|1\d\d|2[0-4]\d|25[0-5])'
28
+ # r'(?<![\.\d])(?:25[0-5]\.|2[0-4]\d\.|[01]?\d\d?\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)(?![\.\d])'
29
+ pat = r'((?:[1-9]?\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(?:[1-9]?\d|1\d\d|2[0-4]\d|25[0-5])'
30
+ if re.fullmatch(pat, l_ip):
31
+ return True
32
+ else:
33
+ return False
34
+
35
+ def get_local_ips():
36
+ ip_list = []
37
+ for i, u in enumerate(url.detect_url, 1):
38
+ l_ip = get_local_ip_from_url_and_parse(u[0], u[1], u[2])
39
+ if validate_ip(l_ip):
40
+ ip_list.append(l_ip)
41
+ return ip_list
42
+
43
+ def print_ip_list(ip_list):
44
+ number = 100
45
+ print(f'{"Detected Local IP List":=^{number}}\n'
46
+ f'{"#":<38}IP Address\n'
47
+ f'{"-" * number}'
48
+ )
49
+
50
+ for i, ip in enumerate(ip_list, 1):
51
+ print(f'{str(i):<38}{ip}')
52
+
53
+ print('-' * number)
54
+
55
+
56
+ if __name__ == '__main__':
57
+ print(validate_ip('1.0.0.0'))
@@ -0,0 +1,4 @@
1
+
2
+ IFCONFIG_ME_PATTERN = r'(.+)'
3
+ CIP_CC_PATTERN = r'URL\s+?:\s+?http://www.cip.cc/(.+)'
4
+ TOOL_LU_PATTERN = r'<p>你的外网IP地址是:\s*?(.+)</p>'
@@ -0,0 +1,16 @@
1
+ import re
2
+ import random
3
+
4
+ from .agent import *
5
+ from .pattern import *
6
+
7
+
8
+ def parse_ip_from_response(response, patt):
9
+ if result:=re.search(patt, response):
10
+ return result.group(1)
11
+
12
+ detect_url = [
13
+ ['https://ifconfig.me', IFCONFIG_ME_PATTERN, random.choice(curl_user_agent)],
14
+ ['https://cip.cc', CIP_CC_PATTERN, random.choice(curl_user_agent)],
15
+ ['https://tool.lu/ip/', TOOL_LU_PATTERN, random.choice(chrome_user_agent)]
16
+ ]
File without changes
@@ -0,0 +1,24 @@
1
+ import os
2
+
3
+ from tencentcloud.common import credential
4
+ from tencentcloud.common.profile.http_profile import HttpProfile
5
+ from tencentcloud.common.profile.client_profile import ClientProfile
6
+ from tencentcloud.common.common_client import CommonClient
7
+
8
+
9
+ def get_common_client(proxy):
10
+ cred = credential.Credential(
11
+ os.environ.get("TENCENTCLOUD_SECRET_ID"),
12
+ os.environ.get("TENCENTCLOUD_SECRET_KEY"))
13
+
14
+ httpProfile = HttpProfile()
15
+ httpProfile.endpoint = "vpc.tencentcloudapi.com"
16
+ if proxy != -1:
17
+ httpProfile.proxy = f'127.0.0.1:{proxy}'
18
+
19
+ clientProfile = ClientProfile()
20
+ clientProfile.httpProfile = httpProfile
21
+
22
+ common_client = CommonClient("vpc", "2017-03-12", cred, "ap-nanjing", profile=clientProfile)
23
+
24
+ return common_client
@@ -0,0 +1,155 @@
1
+ import json
2
+ import random
3
+
4
+
5
+ from ..ip import ip
6
+ from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
7
+
8
+
9
+ def write_template_list_to_temp_file(template_ids):
10
+
11
+ with open('/tmp/template_0000.txt', 'w') as temp_file:
12
+ json.dump(template_ids, temp_file)
13
+
14
+ return temp_file.name
15
+
16
+ def get_template(common_client):
17
+ try:
18
+ headers = {}
19
+ templates = common_client.call_json("DescribeAddressTemplates", headers)
20
+ return templates
21
+
22
+ except TencentCloudSDKException as err:
23
+ print(err)
24
+ return None
25
+
26
+ def list_template(common_client):
27
+ number = 150
28
+ print(f'{"Tencent Cloud Template List":=^{number}}\n' \
29
+ f'{"#":<10}{"Template ID":<20}{"CreatedTime":<30}{"Addresses":<60}{"AddressTemplateName":<30}\n' \
30
+ f'{"-" * number}'
31
+ )
32
+
33
+ template_ids = []
34
+ if not(templates := get_template(common_client)):
35
+ return template_ids
36
+
37
+ for i, template in enumerate(templates['Response']['AddressTemplateSet'], 1):
38
+ template_ids.append(template['AddressTemplateId'])
39
+ # print(template_ids)
40
+ addreset = ' ~ '.join(template['AddressSet'][:3])
41
+ if len(template['AddressSet']) > 3:
42
+ addreset += f' ~~~{len(template["AddressSet"])-3} more...'
43
+ print(f"{str(i):10}"
44
+ f"{template['AddressTemplateId']:20}"
45
+ f"{template['CreatedTime']:30}"
46
+ f"{addreset:<60}"
47
+ f"{template['AddressTemplateName']:30}"
48
+ )
49
+ print('-' * number)
50
+
51
+ # write_template_list_to_temp_file(template_ids)
52
+
53
+ return template_ids
54
+
55
+ def format_addres_extra_string_from_list(client_ips):
56
+ cs = '"AddressesExtra":['
57
+ for client_ip in client_ips:
58
+ cs += '{{"Address":"{}","Description":"client_ip"}},'.format(client_ip)
59
+ cs_format = cs.rstrip(',')
60
+ cs_format += ']'
61
+
62
+ return cs_format
63
+
64
+ def modify_template_address(common_client, client_ips, target_id):
65
+
66
+ if not target_id:
67
+ return False
68
+
69
+ # 增加描述校验,避免更改错误
70
+ params = f"{{\"Filters\":[{{\"Name\":\"address-template-id\",\"Values\":[\"{target_id}\"]}}]}}"
71
+ try:
72
+ respon = common_client.call_json("DescribeAddressTemplates", json.loads(params))
73
+ if (TemplateSet := respon['Response']['AddressTemplateSet']) and \
74
+ TemplateSet[0]['AddressTemplateName'].startswith('temp-open-'):
75
+ # print(respon)
76
+ pass
77
+ else:
78
+ print('This is not a template generated from this tool. Shall not be modified.')
79
+ return False
80
+ except (TencentCloudSDKException, IndexError) as err:
81
+ # IndexError catch when there is no match target.Example: 'AddressTemplateSet': []
82
+ print(f"{err=}, {type(err)=}, {respon=}")
83
+ return False
84
+
85
+ params = "{{\"AddressTemplateId\":\"{}\",{}}}".format(target_id, client_ips)
86
+ try:
87
+ respon = common_client.call_json("ModifyAddressTemplateAttribute", json.loads(params))
88
+ # print(respon)
89
+ # print('-' * 100)
90
+ except TencentCloudSDKException as err:
91
+ print(f"Unexpected {err=}, {type(err)=}")
92
+ return False
93
+
94
+ return True
95
+
96
+ def get_local_ip_and_format_addressesextra():
97
+ client_ip_list = ip.get_local_ips()
98
+ # ip.print_ip_list(client_ip_list)
99
+ client_ip_list = list(set(client_ip_list))
100
+ addresses_extra = format_addres_extra_string_from_list(client_ip_list)
101
+
102
+ return addresses_extra
103
+
104
+ def set_template(common_client, target_id):
105
+ # with open('/tmp/template_0000.txt', 'r') as temp_file:
106
+ # data = json.load(temp_file)
107
+ # print(data)
108
+ if target_id:
109
+ if target_id.startswith('ipm-'):
110
+ addresses_extra = get_local_ip_and_format_addressesextra()
111
+ if modify_template_address(common_client, addresses_extra, target_id):
112
+ print(f'Successfully set {{{target_id}}} to {{{addresses_extra}}}')
113
+ else:
114
+ print('Wrong template id.')
115
+ else:
116
+ print('Set template shall input template id.')
117
+
118
+ def create_template(common_client, rule_id):
119
+
120
+ if not rule_id:
121
+ print('Create template shall input security group id.')
122
+ return False
123
+
124
+ params = "{}"
125
+ try:
126
+ templates = []
127
+ respon = common_client.call_json("DescribeAddressTemplates", json.loads(params))
128
+ print(json.dumps(respon, ensure_ascii=False))
129
+ for template in respon['Response']['AddressTemplateSet']:
130
+ if template['AddressTemplateName'].startswith('temp-open-'):
131
+ templates.append((template['AddressTemplateId'], template['AddressTemplateName'], template['CreatedTime']))
132
+ if templates:
133
+ print(f'Already have template without creation: {templates}')
134
+ return True
135
+
136
+ except TencentCloudSDKException as err:
137
+ print(f"{err=}, {type(err)=}")
138
+ return False
139
+
140
+ addresses_extra = get_local_ip_and_format_addressesextra()
141
+ params = f"{{\"AddressTemplateName\":\"temp-open-{random.randint(1,9999):04d}\",{addresses_extra}}}"
142
+ try:
143
+ respon = common_client.call_json("CreateAddressTemplate", json.loads(params))
144
+ print(json.dumps(respon, ensure_ascii=False))
145
+
146
+ if template_id := respon['Response']['AddressTemplate']['AddressTemplateId']:
147
+ params = f"{{\"SecurityGroupId\":\"{rule_id}\",\"SecurityGroupPolicySet\":{{\"Ingress\":[{{\"PolicyIndex\":0,\"Protocol\":\"ALL\",\"AddressTemplate\":{{\"AddressId\":\"{template_id}\"}},\"Action\":\"accept\",\"PolicyDescription\":\"temp-open\"}}]}}}}"
148
+ respon = common_client.call_json("CreateSecurityGroupPolicies", json.loads(params))
149
+ print(json.dumps(respon))
150
+
151
+ except TencentCloudSDKException as err:
152
+ print(f"{err=}, {type(err)=}")
153
+ return False
154
+
155
+ return True
@@ -0,0 +1,14 @@
1
+ [build-system]
2
+ requires = ["flit_core >=3.2,<4"]
3
+ build-backend = "flit_core.buildapi"
4
+
5
+ [project]
6
+ name = "easy_whitelist"
7
+ authors = [{name = "qiqilelebaobao", email = "qiqilelebaobao@163.com"},{name = "qiqilelebaobao"}]
8
+ readme = "README.md"
9
+ license = {text = "MIT License"}
10
+ classifiers = ["License :: OSI Approved :: Apache Software License"]
11
+ dynamic = ["version", "description"]
12
+
13
+ [project.urls]
14
+ Homepage = "https://github.com/qiqilelebaobao/easy_whitelist"
@@ -0,0 +1,2 @@
1
+
2
+ __all__ = ["aa", ]
@@ -0,0 +1,7 @@
1
+
2
+
3
+ print(f'name:{__name__}, file:{__file__}, package:{(__package__)}')
4
+
5
+ aaa = 3
6
+ aab = 4
7
+ aac = 5
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2017-2021 Tencent Ltd.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ import os
16
+ import json
17
+
18
+ from tencentcloud.common.common_client import CommonClient
19
+ from tencentcloud.common import credential
20
+ from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
21
+ from tencentcloud.common.profile.client_profile import ClientProfile
22
+ from tencentcloud.common.profile.http_profile import HttpProfile
23
+
24
+ try:
25
+ cred = credential.Credential(
26
+ os.environ.get("TENCENTCLOUD_SECRET_ID"),
27
+ os.environ.get("TENCENTCLOUD_SECRET_KEY"))
28
+
29
+ httpProfile = HttpProfile()
30
+ # 域名首段必须和下文中CommonClient初始化的产品名严格匹配
31
+ httpProfile.endpoint = "cvm.tencentcloudapi.com"
32
+ clientProfile = ClientProfile()
33
+ clientProfile.httpProfile = httpProfile
34
+
35
+ # common client方法支持指定header,如 X-TC-TraceId、X-TC-Canary
36
+ headers = {
37
+ "X-TC-TraceId": "ffe0c072-8a5d-4e17-8887-a8a60252abca"
38
+ }
39
+
40
+ # 实例化要请求的common client对象,clientProfile是可选的。
41
+ common_client = CommonClient("cvm", '2017-03-12', cred, "ap-nanjing", profile=clientProfile)
42
+ # 接口参数作为json字典传入,得到的输出也是json字典,请求失败将抛出异常,headers为可选参数
43
+ print(common_client.call_json("DescribeInstances", {"Limit": 10}, headers=headers))
44
+ except TencentCloudSDKException as err:
45
+ print(err)
@@ -0,0 +1,23 @@
1
+ Here is Hogan’s full memo:
2
+ 、、、
3
+ At Microsoft, we deliver mission-critical infrastructure that the world depends on to achieve more. With that trust in us comes a great responsibility: to protect our customers, our company, and our world from cyber threats. As Microsoft employees, we all have a role in that responsibility.
4
+
5
+ As Satya referenced in his May 3 email and again during his FY25 kick off on July 9, security is our number-one priority, and everyone at Microsoft will have security as a Core Priority. When faced with a tradeoff, the answer is clear and simple: security above all else. Our commitment to security is enduring. New and novel attacks will require us to continue to learn, innovate, and defend. Yet working together, we will make nonlinear improvements, stay alert, and meet the expectations of our customers. They are counting on us, and our future depends on their trust.
6
+
7
+ Our new Security Core Priority reinforces our commitment to security and holds us accountable for building secure products and services. It is now available in the Connect tool for most employees, and we are partnering with geo HR teams to expand access to all employees globally. The Security Core Priority is not a check-the-box compliance exercise; it is a way for every employee and manager to commit to—and be accountable for—prioritizing security, and a way for us to codify your contributions and to recognize you for your impact. We all must act with a security-first mindset, speak up, and proactively look for opportunities to ensure security in everything we do.
8
+
9
+ The core priority will have two parts:
10
+
11
+ Core and common elements that apply to all employees
12
+
13
+ An optional section for employees to further specify how they will activate the Security Core Priority based on their role, team, org, etc.
14
+
15
+ All employees will set their Security Core Priority as part their first FY25 Connect, with the intent that during regular Connect conversations, you and your manager will discuss your Security Core Priority progress and impact. This process will follow the same approach as our other company-wide core priorities for Diversity & Inclusion and Managers. You can learn more about the Security Core Priority here, including FAQs and Security Core Priority activation examples for three main types of roles: technical, customer and partner-facing, and all other roles.
16
+
17
+ As we kick off our 50th year as a company, I know we all feel honored and humbled that we are still here—as a relevant and consequential company—pursuing our mission together. When we empower every person and organization on the planet to achieve more, we take on society’s biggest challenges and empower the world. What a big, bold, and meaningful mission we have, and yet none of us can take this for granted. We are here because our customers trust us, and we must continue to earn their trust every day.
18
+
19
+ Thank you for your commitment to our Security Core Priority that will help protect Microsoft, our customers, and our partners.
20
+
21
+ Kathleen
22
+
23
+ 、、、
@@ -0,0 +1,20 @@
1
+ import os
2
+ from tencentcloud.common import credential
3
+ from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
4
+ from tencentcloud.cvm.v20170312 import cvm_client, models
5
+
6
+ try:
7
+ # 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。
8
+ # 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
9
+ # cred = credential.Credential("secretId", "secretKey")
10
+ cred = credential.Credential(
11
+ os.environ.get("TENCENTCLOUD_SECRET_ID"),
12
+ os.environ.get("TENCENTCLOUD_SECRET_KEY"))
13
+ client = cvm_client.CvmClient(cred, "ap-nanjing")
14
+
15
+ req = models.DescribeInstancesRequest()
16
+ resp = client.DescribeInstances(req)
17
+
18
+ print(resp.to_json_string())
19
+ except TencentCloudSDKException as err:
20
+ print(err)
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ import json
3
+ import os
4
+
5
+ from tencentcloud.common.common_client import CommonClient
6
+ from tencentcloud.common import credential
7
+ from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
8
+ from tencentcloud.common.profile.client_profile import ClientProfile
9
+ from tencentcloud.common.profile.http_profile import HttpProfile
10
+
11
+ try:
12
+ cred = credential.Credential(
13
+ os.environ.get("TENCENTCLOUD_SECRET_ID"),
14
+ os.environ.get("TENCENTCLOUD_SECRET_KEY"))
15
+
16
+ pass
17
+
18
+ httpProfile = HttpProfile()
19
+ httpProfile.endpoint = "vpc.tencentcloudapi.com"
20
+ httpProfile.proxy = '127.0.0.1:8080'
21
+ clientProfile = ClientProfile()
22
+ clientProfile.httpProfile = httpProfile
23
+
24
+ headers = {}
25
+ common_client = CommonClient("vpc", "2017-03-12", cred, "ap-nanjing", profile=clientProfile)
26
+ templates = common_client.call_json("DescribeAddressTemplates", headers)
27
+ print(json.dumps(templates, ensure_ascii=False))
28
+
29
+ except TencentCloudSDKException as err:
30
+ print(err)
@@ -0,0 +1,14 @@
1
+
2
+ def outer():
3
+ x = "local"
4
+ def inner():
5
+ global y
6
+ print("inner:", y)
7
+ x = "nonlocal"
8
+
9
+ inner()
10
+ print("outer:", x)
11
+
12
+ x = 'global'
13
+ outer()
14
+ print('glabal:', x)
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import os
4
+ from setuptools import setup, find_packages
5
+
6
+ import whitelist
7
+
8
+ # ROOT = os.path.dirname(__file__)
9
+
10
+ setup(
11
+ name='easy_whitelist',
12
+ install_requires=[
13
+ 'tencentcloud-sdk-python',
14
+ ],
15
+ description='Easy_whitelist is a small tool that detects the local Internet IP address and automatically updates the local Internet IP address to the cloud security group whitelist.',
16
+ # long_description=open('README.md').read(),
17
+ long_description = 'nihao',
18
+ author='qiqilelebaobao',
19
+ author_email='qiqilelebaobao@163.com',
20
+ maintainer_email="qiqilelebaobao@163.com",
21
+ version=whitelist.__version__,
22
+ url='https://baidu.com',
23
+ scripts=[],
24
+ license="Apache License 2.0",
25
+ platforms='any',
26
+ packages=find_packages(exclude=['output', 'sample']),
27
+ classifiers=[
28
+ 'Development Status :: 5 - Production/Stable',
29
+ 'Intended Audience :: Developers',
30
+ 'License :: OSI Approved :: Apache Software License',
31
+ 'Programming Language :: Python',
32
+ 'Programming Language :: Python :: 3',
33
+ 'Programming Language :: Python :: 3.6',
34
+ 'Programming Language :: Python :: 3.7',
35
+ 'Programming Language :: Python :: 3.8',
36
+ 'Programming Language :: Python :: 3.9',
37
+ 'Programming Language :: Python :: 3.10',
38
+ ],
39
+
40
+ )