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.

146 lines
4.1 KiB

15 years ago
15 years ago
  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright (C) 2009, 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_dbase();
  26. self.check_sites();
  27. self.check_mumbles();
  28. self.check_admins();
  29. self.check_secret_key();
  30. def check_dbase( self ):
  31. print "Checking database access...",
  32. if settings.DATABASE_ENGINE == "sqlite3":
  33. if not os.path.exists( settings.DATABASE_NAME ):
  34. raise TestFailed( "database does not exist. Have you run syncdb yet?" );
  35. else:
  36. statinfo = os.stat( settings.DATABASE_NAME );
  37. if statinfo.st_uid == 0:
  38. raise TestFailed(
  39. "the database file belongs to root. This is most certainly not what "
  40. "you want because it will prevent your web server from being able "
  41. "to write to it. Please check." );
  42. elif not os.access( settings.DATABASE_NAME, os.W_OK ):
  43. raise TestFailed( "database file is not writable." );
  44. else:
  45. print "[ OK ]";
  46. else:
  47. print "not using sqlite, so I can't check.";
  48. def check_sites( self ):
  49. print "Checking URL configuration...",
  50. try:
  51. site = Site.objects.get_current();
  52. except Site.DoesNotExist:
  53. try:
  54. sid = settings.SITE_ID
  55. except AttributeError:
  56. from django.core.exceptions import ImproperlyConfigured
  57. raise ImproperlyConfigured(
  58. "You're using the Django \"sites framework\" without having set the SITE_ID "
  59. "setting. Create a site in your database and rerun this command to fix this error.")
  60. else:
  61. print( "none set.\n"
  62. "Please enter the domain where Mumble-Django is reachable." );
  63. dom = raw_input( "> " ).strip();
  64. site = Site( id=sid, name=dom, domain=dom );
  65. site.save();
  66. if site.domain == 'example.com':
  67. print( "still the default.\n"
  68. "The domain is configured as example.com, which is the default but does not make sense. "
  69. "Please enter the domain where Mumble-Django is reachable." );
  70. site.domain = raw_input( "> " ).strip();
  71. site.save();
  72. print site.domain, "[ OK ]";
  73. def check_admins( self ):
  74. print "Checking if an Admin user exists...",
  75. for user in User.objects.all():
  76. if user.is_superuser:
  77. print "[ OK ]";
  78. return;
  79. raise TestFailed( ""
  80. "No admin user exists, so you won't be able to log in to the admin system. You "
  81. "should run `./manage.py createsuperuser` to create one." );
  82. def check_mumbles( self ):
  83. print "Checking Murmur instances...",
  84. mm = Mumble.objects.all();
  85. if mm.count() == 0:
  86. raise TestFailed(
  87. "no Mumble servers are configured, you might want to run "
  88. "`./manage.py syncdb` to run an auto detection." );
  89. else:
  90. for mumble in mm:
  91. try:
  92. ctl = mumble.ctl;
  93. except Exception, err:
  94. raise TestFailed(
  95. "Connecting to Murmur `%s` (%s) failed: %s" % ( mumble.name, mumble.dbus, err )
  96. );
  97. print "[ OK ]";
  98. def check_secret_key( self ):
  99. print "Checking SECRET_KEY...",
  100. blacklist = ( 'u-mp185msk#z4%s(do2^5405)y5d!9adbn92)apu_p^qvqh10v', );
  101. if settings.SECRET_KEY in blacklist:
  102. raise TestFailed(
  103. "Your SECRET_KEY setting matches one of the keys that were put in the settings.py "
  104. "file shipped with Mumble-Django, which means your SECRET_KEY is all but secret. "
  105. "You should change the setting, or run gen_secret_key.sh to do it for you."
  106. );
  107. else:
  108. print "[ OK ]";