2 import urllib.request, urllib.parse, json, os, sys
4 def is_github(remote_addr):
5 '''Returns whether the address is a github hook address. This function requires Python 3.3.'''
6 from ipaddress import ip_address, ip_network
7 remote_addr = ip_address(ip_network)
8 github = urllib.request.urlopen('https://api.github.com/meta').read()
9 github = json.loads(github.decode('utf-8'))
10 for net in github['hooks']:
11 if remote_addr in ip_network(net):
15 # get repository from query string
16 query = os.getenv("QUERY_STRING")
17 query = urllib.parse.parse_qs(query)
18 repository = query.get('repository', [])
19 repository = repository[0] if len(repository) else ''
21 # execute the actual script
22 webhook_core = "/home/ralf/git-mirror/webhook-core.py"
23 os.execlp("sudo", "sudo", "-n", "-u", "git", webhook_core, repository)