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.

194 lines
5.6 KiB

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