7 from django import VERSION as DJANGO_VERSION
8 from django.http import HttpResponse
9 from django.utils.translation import ugettext as _
10 from django.utils import simplejson
11 from django.conf import settings
13 from base import get_site_views, get_server_name
14 from settings import SITE_KEY, UPDATE_SERVER_URL
15 from forum.settings import APP_URL, SVN_REVISION
16 from forum.views.admin import admin_tools_page, admin_page
18 @admin_tools_page(_('updater'), _('Update Checker'))
19 def updater_index(request):
21 'modules/updater/index.html',
27 def updater_check(request):
28 # Get the SVN Revision
30 svn_revision = int(SVN_REVISION.replace('SVN-', ''))
32 # Here we'll have to find another way of getting the SVN revision
35 statistics = """<check>
36 <key value="%(site_key)s" />
37 <app_url value="%(app_url)s" />
38 <svn_revision value="%(svn_revision)d" />
39 <views value="%(site_views)d" />
40 <active_users value="11959" />
41 <server value="%(server_name)s" />
42 <python_version value="%(python_version)s" />
43 <django_version value="%(django_version)s" />
44 <database value="%(database)s" />
47 'site_key' : SITE_KEY,
49 'svn_revision' : svn_revision,
50 'site_views' : get_site_views(),
51 'server_name' : get_server_name(),
52 'python_version' : ''.join(sys.version.splitlines()),
53 'django_version' : str(DJANGO_VERSION),
54 'database' : settings.DATABASE_ENGINE,
55 'os' : str(os.uname()),
58 # Compress the statistics XML dump
59 statistics_compressed = bz2.compress(statistics)
61 # Pass the compressed statistics to the update server
63 'statistics' : binascii.b2a_base64(statistics_compressed),
65 data = urllib.urlencode(post_data)
67 # We simulate some browser, otherwise the server can return 403 response
68 user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-us) AppleWebKit/531.21.8 (KHTML, like Gecko) Version/4.0.4 Safari/5'
69 headers={ 'User-Agent' : user_agent,}
72 check_request = urllib2.Request('%s%s' % (UPDATE_SERVER_URL, '/site_check/'), data, headers=headers)
73 check_response = urllib2.urlopen(check_request)
74 content = check_response.read()
75 except urllib2.HTTPError, error:
76 content = error.read()
78 json = simplejson.dumps({})
79 return HttpResponse(content, mimetype='text/html')