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.

131 lines
3.6 KiB

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