Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
6.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. import os
  17. from os.path import dirname
  18. from django.core.management.base import BaseCommand
  19. from django.contrib.auth.models import User
  20. from django.contrib.sites.models import Site
  21. from django.conf import settings
  22. from mumble.models import Mumble, MumbleServer
  23. class TestFailed( Exception ):
  24. pass
  25. class Command( BaseCommand ):
  26. help = "Run a few tests on Mumble-Django's setup."
  27. def handle(self, **options):
  28. try:
  29. import Ice
  30. except ImportError:
  31. pass
  32. else:
  33. self.check_slice()
  34. self.check_rootdir()
  35. self.check_dbase()
  36. self.check_sites()
  37. self.check_mumbles()
  38. self.check_admins()
  39. self.check_secret_key()
  40. def check_slice( self ):
  41. print "Checking slice file for %d server instances..." % MumbleServer.objects.count(),
  42. for serv in MumbleServer.objects.all():
  43. if serv.method_ice:
  44. serv.ctl
  45. print "[ OK ]"
  46. def check_rootdir( self ):
  47. print "Checking root directory access...",
  48. if not os.path.exists( settings.MUMBLE_DJANGO_ROOT ):
  49. raise TestFailed( "The mumble-django root directory does not exist." )
  50. elif "sqlite3" not in settings.DATABASES["default"]["ENGINE"]:
  51. print "not using sqlite [ OK ]"
  52. else:
  53. for checkdir in ( settings.MUMBLE_DJANGO_ROOT, dirname(settings.DATABASES["default"]["NAME"]) ):
  54. statinfo = os.stat( checkdir )
  55. if statinfo.st_uid == 0:
  56. raise TestFailed(
  57. "The directory '%s' belongs to user root. This is "
  58. "most certainly not what you want because it will prevent your "
  59. "web server from being able to write to the database. Please check." % checkdir )
  60. elif not os.access( checkdir, os.W_OK ):
  61. raise TestFailed( "The directory '%s' is not writable." % checkdir )
  62. print "[ OK ]"
  63. def check_dbase( self ):
  64. print "Checking database access...",
  65. if "sqlite3" in settings.DATABASES["default"]["ENGINE"]:
  66. if not os.path.exists( settings.DATABASES["default"]["NAME"] ):
  67. raise TestFailed( "database does not exist. Have you run syncdb yet?" )
  68. else:
  69. statinfo = os.stat( settings.DATABASES["default"]["NAME"] )
  70. if statinfo.st_uid == 0:
  71. raise TestFailed(
  72. "the database file belongs to root. This is most certainly not what "
  73. "you want because it will prevent your web server from being able "
  74. "to write to it. Please check." )
  75. elif not os.access( settings.DATABASES["default"]["NAME"], os.W_OK ):
  76. raise TestFailed( "database file is not writable." )
  77. else:
  78. print "[ OK ]"
  79. else:
  80. print "not using sqlite, so I can't check."
  81. def check_sites( self ):
  82. print "Checking URL configuration...",
  83. try:
  84. site = Site.objects.get_current()
  85. except Site.DoesNotExist:
  86. try:
  87. sid = settings.SITE_ID
  88. except AttributeError:
  89. from django.core.exceptions import ImproperlyConfigured
  90. raise ImproperlyConfigured(
  91. "You're using the Django \"sites framework\" without having set the SITE_ID "
  92. "setting. Create a site in your database and rerun this command to fix this error.")
  93. else:
  94. print( "none set.\n"
  95. "Please enter the domain where Mumble-Django is reachable." )
  96. dom = raw_input( "> " ).strip()
  97. site = Site( id=sid, name=dom, domain=dom )
  98. site.save()
  99. if site.domain == 'example.com':
  100. print( "still the default.\n"
  101. "The domain is configured as example.com, which is the default but does not make sense. "
  102. "Please enter the domain where Mumble-Django is reachable." )
  103. site.domain = raw_input( "> " ).strip()
  104. site.save()
  105. print site.domain, "[ OK ]"
  106. def check_admins( self ):
  107. print "Checking if an Admin user exists...",
  108. for user in User.objects.all():
  109. if user.is_superuser:
  110. print "[ OK ]"
  111. return
  112. raise TestFailed( ""
  113. "No admin user exists, so you won't be able to log in to the admin system. You "
  114. "should run `./manage.py createsuperuser` to create one." )
  115. def check_mumbles( self ):
  116. print "Checking Murmur instances...",
  117. mm = Mumble.objects.all()
  118. if mm.count() == 0:
  119. raise TestFailed(
  120. "no Mumble servers are configured, you might want to run "
  121. "`./manage.py syncdb` to run an auto detection." )
  122. else:
  123. for mumble in mm:
  124. try:
  125. mumble.ctl
  126. except Exception, err:
  127. raise TestFailed(
  128. "Connecting to Murmur `%s` (%s) failed: %s" % ( mumble.name, mumble.server, err )
  129. )
  130. print "[ OK ]"
  131. def check_secret_key( self ):
  132. print "Checking SECRET_KEY...",
  133. blacklist = ( 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v', )
  134. if settings.SECRET_KEY in blacklist:
  135. raise TestFailed(
  136. "Your SECRET_KEY setting matches one of the keys that were put in the settings.py "
  137. "file shipped with Mumble-Django, which means your SECRET_KEY is all but secret. "
  138. "You should change the setting, or remove it altogether and allow the key to be "
  139. "generated automatically."
  140. )
  141. else:
  142. print "[ OK ]"