Subversion:在预提交挂钩中获取用户的 IP 地址?
我们正在托管一个用于分布式软件开发的颠覆存储库。因此,非员工可以访问我们的一些源代码。我们公司的 IT 安全策略要求我们对从公司内部网外部上传的所有文件进行病毒扫描。所有内部计算机都配备了最新的病毒扫描程序。
我们计划将病毒扫描集成到 Subversion 预提交挂钩中。但这会在执行大型提交时导致延迟。因此,我们只想扫描源自内部网外部的提交。为了识别来源,我们需要执行提交的用户的 IP 地址。由于我们的一些员工在家工作,我们无法使用用户名来识别来自互联网的提交。
因此,最后我的问题是:
如何获取在颠覆预提交挂钩中执行提交的 IP 地址?
We're hosting a subversion repository for distrubuted software development. So non-employees have access to some of our sorce code. Our company's IT security policy requires us to virusscan all files uploaded from outside of our corporate intranet. All internal computers are equipped with up to date virus scanners.
We're planning on integration the virus scan in a Subversion precommit-hook. But this causes delays when performing large commits. So we would like to scan only the commits, that are originated outside of our intranet. To identify the origin, we need the IP adress of the user performing the commit. Since some of our employees work from home we can't use the usernames to identify commits from the internet.
Thus finally my question:
How can I get the IP-adress from which a commit ist performed in a subversion precommit hook?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我想象一下你用 Perl 编写你的钩子,在这种情况下,你可以使用以下库: DocumentationClientIP
您可以通过此链接从 Git 安装该库:GITClientIP (或使用包含的代码)。
安装后,您需要在代码中添加类似的内容:
Let me imagine that you write your hook in Perl, in that case, you can use the following lib : DocumentationClientIP
you can install the lib from Git thru this link : GITClientIP (or use the code included).
After installation, you need to add something like that in your code :
我正在使用 lsof(bash 脚本预提交):
srcip=$(/usr/sbin/lsof -Pn -p $PPID | grep ESTABLISHED)
或者,仅获取 IP:
<代码>srcip=$(/usr/sbin/lsof -Pn|grep ssh|grep ESTA|cut -d\> -f 2|cut -d: -f 1)
当客户端连接到服务器时,会执行预提交。
lsof
显示所有打开的文件(包括TCP连接等);我选择此进程的所有“文件”(-p $PPID
),并选择 grep 来查找ESTABLISHED
(这是客户端和服务器之间的连接)。I'm using lsof (bash-script pre-commit):
srcip=$(/usr/sbin/lsof -Pn -p $PPID | grep ESTABLISHED)
or, to get only the IP:
srcip=$(/usr/sbin/lsof -Pn|grep ssh|grep ESTA|cut -d\> -f 2|cut -d: -f 1)
While client connects to server, pre-commit is executed.
lsof
shows all open files (including TCP connections etc); I select all "files" for this process (-p $PPID
) and grep forESTABLISHED
(this is the connection between client and server).