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.

189 lines
6.4 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 django.core.management.base import BaseCommand
  18. from django.contrib.auth.models import User
  19. from django.contrib.sites.models import Site
  20. from django.conf import settings
  21. from mumble.models import Mumble, MumbleServer
  22. class TestFailed( Exception ):
  23. pass
  24. class Command( BaseCommand ):
  25. help = "Run a few tests on Mumble-Django's setup."
  26. def handle(self, **options):
  27. try:
  28. import Ice
  29. except ImportError:
  30. pass
  31. else:
  32. self.check_slice()
  33. self.check_rootdir()
  34. self.check_dbase()
  35. self.check_sites()
  36. self.check_mumbles()
  37. self.check_admins()
  38. self.check_secret_key()
  39. def check_slice( self ):
  40. print "Checking slice file for %d server instances..." % MumbleServer.objects.count(),
  41. for serv in MumbleServer.objects.all():
  42. if serv.method_ice:
  43. serv.ctl
  44. print "[ OK ]"
  45. def check_rootdir( self ):
  46. print "Checking root directory access...",
  47. if not os.path.exists( settings.MUMBLE_DJANGO_ROOT ):
  48. raise TestFailed( "The mumble-django root directory does not exist." )
  49. elif settings.DATABASE_ENGINE != "sqlite3":
  50. print "not using sqlite [ OK ]"
  51. else:
  52. for checkdir in ( settings.MUMBLE_DJANGO_ROOT, os.path.join( settings.MUMBLE_DJANGO_ROOT, "db" ) ):
  53. statinfo = os.stat( checkdir )
  54. if statinfo.st_uid == 0:
  55. raise TestFailed(
  56. "The directory '%s' belongs to user root. This is "
  57. "most certainly not what you want because it will prevent your "
  58. "web server from being able to write to the database. Please check." % checkdir )
  59. elif not os.access( checkdir, os.W_OK ):
  60. raise TestFailed( "The directory '%s' is not writable." % checkdir )
  61. print "[ OK ]"
  62. def check_dbase( self ):
  63. print "Checking database access...",
  64. if settings.DATABASE_ENGINE == "sqlite3":
  65. if not os.path.exists( settings.DATABASE_NAME ):
  66. raise TestFailed( "database does not exist. Have you run syncdb yet?" )
  67. else:
  68. statinfo = os.stat( settings.DATABASE_NAME )
  69. if statinfo.st_uid == 0:
  70. raise TestFailed(
  71. "the database file belongs to root. This is most certainly not what "
  72. "you want because it will prevent your web server from being able "
  73. "to write to it. Please check." )
  74. elif not os.access( settings.DATABASE_NAME, os.W_OK ):
  75. raise TestFailed( "database file is not writable." )
  76. else:
  77. print "[ OK ]"
  78. else:
  79. print "not using sqlite, so I can't check."
  80. def check_sites( self ):
  81. print "Checking URL configuration...",
  82. try:
  83. site = Site.objects.get_current()
  84. except Site.DoesNotExist:
  85. try:
  86. sid = settings.SITE_ID
  87. except AttributeError:
  88. from django.core.exceptions import ImproperlyConfigured
  89. raise ImproperlyConfigured(
  90. "You're using the Django \"sites framework\" without having set the SITE_ID "
  91. "setting. Create a site in your database and rerun this command to fix this error.")
  92. else:
  93. print( "none set.\n"
  94. "Please enter the domain where Mumble-Django is reachable." )
  95. dom = raw_input( "> " ).strip()
  96. site = Site( id=sid, name=dom, domain=dom )
  97. site.save()
  98. if site.domain == 'example.com':
  99. print( "still the default.\n"
  100. "The domain is configured as example.com, which is the default but does not make sense. "
  101. "Please enter the domain where Mumble-Django is reachable." )
  102. site.domain = raw_input( "> " ).strip()
  103. site.save()
  104. print site.domain, "[ OK ]"
  105. def check_admins( self ):
  106. print "Checking if an Admin user exists...",
  107. for user in User.objects.all():
  108. if user.is_superuser:
  109. print "[ OK ]"
  110. return
  111. raise TestFailed( ""
  112. "No admin user exists, so you won't be able to log in to the admin system. You "
  113. "should run `./manage.py createsuperuser` to create one." )
  114. def check_mumbles( self ):
  115. print "Checking Murmur instances...",
  116. mm = Mumble.objects.all()
  117. if mm.count() == 0:
  118. raise TestFailed(
  119. "no Mumble servers are configured, you might want to run "
  120. "`./manage.py syncdb` to run an auto detection." )
  121. else:
  122. for mumble in mm:
  123. try:
  124. mumble.ctl
  125. except Exception, err:
  126. raise TestFailed(
  127. "Connecting to Murmur `%s` (%s) failed: %s" % ( mumble.name, mumble.server, err )
  128. )
  129. print "[ OK ]"
  130. def check_secret_key( self ):
  131. print "Checking SECRET_KEY...",
  132. blacklist = ( 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v', )
  133. if settings.SECRET_KEY in blacklist:
  134. raise TestFailed(
  135. "Your SECRET_KEY setting matches one of the keys that were put in the settings.py "
  136. "file shipped with Mumble-Django, which means your SECRET_KEY is all but secret. "
  137. "You should change the setting, or remove it altogether and allow the key to be "
  138. "generated automatically."
  139. )
  140. else:
  141. print "[ OK ]"