Skip to content

Commit

Permalink
Lastest changes from internal version: Logstash management, user serv…
Browse files Browse the repository at this point in the history
…er delegation , force

http at home page, and misc fi
  • Loading branch information
the-glu committed May 26, 2014
1 parent a43db1c commit a635d86
Show file tree
Hide file tree
Showing 45 changed files with 1,681 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.pyc
.ropeproject/
7 changes: 6 additions & 1 deletion app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

'main',
'servers',
'groups',
'groups',
'keymanager',
'hostnameforwarding',
'portforwarding',
Expand All @@ -112,6 +112,7 @@
'fabrun',
'wizard',
'samba',
'logstash',
)

LOGGING = {
Expand Down Expand Up @@ -157,6 +158,10 @@

CREATE_VM_STORAGE = 'local'

FORCE_SECURE_FOR_USER = False

NGNIX_DEFAULT_REDIRECT = ''

try:
from settingsLocal import *
except ImportError:
Expand Down
7 changes: 7 additions & 0 deletions app/settingsLocal.py.dist
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ BROKER_URL = ''

NGNIX_SSL_PEM = ''
NGNIX_SSL_KEY = ''

LOGSTASH_SERVER = ''

MYSQL_USERNAME = ''
MYSQL_PASSWORD = ''

NGNIX_DEFAULT_REDIRECT = ''
1 change: 1 addition & 0 deletions app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
url(r'^fabrun/', include('fabrun.urls')),
url(r'^wizards/', include('wizard.urls')),
url(r'^samba/', include('samba.urls')),
url(r'^logstash/', include('logstash.urls')),

(r'^users/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^users/logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
Expand Down
10 changes: 6 additions & 4 deletions backups/templates/backups/backups/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ <h3>{{object.name}}</h3>
</form>

<div class="row-fluid box-section" style="text-align: right;">
<a href="{% url 'backups.views.backups_run' object.pk %}" class="btn btn btn-warning" onclick="return confirm('{% trans "Are you sure ?" %}');"><i class="icon-refresh icon-white"></i> {% trans "Force execution" %}</a>
<a href="{% url 'backups.views.backups_list' %}" class="btn"><i class="icon-list icon-black"></i> {% trans "Back to the list" %}</a>
<a href="{% url 'backups.views.backups_edit' object.pk %}" class="btn btn-primary"><i class="icon-pencil icon-white"></i> {% trans "Edit" %}</a>
</div>
{% if user.is_staff %}
<a href="{% url 'backups.views.backups_run' object.pk %}" class="btn btn btn-warning" onclick="return confirm('{% trans "Are you sure ?" %}');"><i class="icon-refresh icon-white"></i> {% trans "Force execution" %}</a>
<a href="{% url 'backups.views.backups_list' %}" class="btn"><i class="icon-list icon-black"></i> {% trans "Back to the list" %}</a>
<a href="{% url 'backups.views.backups_edit' object.pk %}" class="btn btn-primary"><i class="icon-pencil icon-white"></i> {% trans "Edit" %}</a>
{% endif %}
</div>

</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions backups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ def backups_list(request):


@login_required
@staff_member_required
def backups_show(request, pk):
"""Show details of a hostname forwarder"""
"""Show details of a backup"""

object = get_object_or_404(Backup, pk=pk)

if not request.user.is_staff and (request.user not in object.server_from.users_owning_the_server.all() and request.user not in object.server_to.users_owning_the_server.all()):
raise Http404

liste = object.backuprun_set.order_by('-start_date').all()

return render_to_response('backups/backups/show.html', {'object': object, 'liste': liste}, context_instance=RequestContext(request))
Expand Down
2 changes: 1 addition & 1 deletion fabrun/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def show_run(request, pk):
@staff_member_required
def clean_up(request):

Task.objects.filter(creation_date__lt = timezone.now() - datetime.timedelta(days=1)).delete()
Task.objects.filter(creation_date__lt=timezone.now() - datetime.timedelta(days=1)).delete()

messages.success(request, "Old fabric runs have been deleted")

Expand Down
7 changes: 7 additions & 0 deletions hostnameforwarding/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ def get_conf(request, pk):
root /usr/share/nginx/www;
index index.html index.htm;
"""

if settings.NGNIX_DEFAULT_REDIRECT:
script += """
return 301 """ + settings.NGNIX_DEFAULT_REDIRECT + """;
"""

script += """
server_name localhost;
}
Expand Down
6 changes: 6 additions & 0 deletions keymanager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,10 @@ def get_keys(request, server, user):
if key.key not in ssh_keys:
ssh_keys.append(key.key)

# Allow each user who 'own' the server
for user in server.users_owning_the_server.all():
for key in user.sshkey_set.all():
if key.key not in ssh_keys:
ssh_keys.append(key.key)

return render_to_response('keymanager/get_keys.html', {'ssh_keys': ssh_keys}, context_instance=RequestContext(request))
Empty file added logstash/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions logstash/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.forms import ModelForm

from logstash.models import File

from servers.models import Server


class FileForm(ModelForm):
class Meta:
model = File
exclude = ()

def __init__(self, *args, **kwargs):
super(FileForm, self).__init__(*args, **kwargs)

self.fields["server"].queryset = Server.objects.order_by('name').filter(logstash_shipper=True)
59 changes: 59 additions & 0 deletions logstash/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'File'
db.create_table(u'logstash_file', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('server', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['servers.Server'])),
('file', self.gf('django.db.models.fields.CharField')(max_length=255)),
('type', self.gf('django.db.models.fields.CharField')(max_length=255)),
('tags', self.gf('django.db.models.fields.CharField')(max_length=512)),
))
db.send_create_signal(u'logstash', ['File'])


def backwards(self, orm):
# Deleting model 'File'
db.delete_table(u'logstash_file')


models = {
u'logstash.file': {
'Meta': {'object_name': 'File'},
'file': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'server': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['servers.Server']"}),
'tags': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
u'servers.server': {
'Meta': {'object_name': 'Server'},
'external_hostname_for_vms_creation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'external_interface': ('django.db.models.fields.CharField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'external_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'hostname_for_vms_creation': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'internal_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'is_proxmox': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_vm': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'keymanger_name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'logstash_shipper': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'ngnix_server': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'ngnixed_server_set'", 'null': 'True', 'to': u"orm['servers.Server']"}),
'proxmox_node_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'samba_base_folder': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'samba_management': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'ssh_connection_string_from_backup': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'ssh_connection_string_from_gestion': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'vm_host': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'server_set'", 'null': 'True', 'to': u"orm['servers.Server']"})
}
}

complete_apps = ['logstash']
65 changes: 65 additions & 0 deletions logstash/migrations/0002_auto__add_execution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'Execution'
db.create_table(u'logstash_execution', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('output', self.gf('django.db.models.fields.TextField')()),
('done', self.gf('django.db.models.fields.BooleanField')(default=False)),
('sugested_result', self.gf('django.db.models.fields.TextField')()),
))
db.send_create_signal(u'logstash', ['Execution'])


def backwards(self, orm):
# Deleting model 'Execution'
db.delete_table(u'logstash_execution')


models = {
u'logstash.execution': {
'Meta': {'object_name': 'Execution'},
'done': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'output': ('django.db.models.fields.TextField', [], {}),
'sugested_result': ('django.db.models.fields.TextField', [], {})
},
u'logstash.file': {
'Meta': {'object_name': 'File'},
'file': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'server': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['servers.Server']"}),
'tags': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'type': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
u'servers.server': {
'Meta': {'object_name': 'Server'},
'external_hostname_for_vms_creation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'external_interface': ('django.db.models.fields.CharField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'external_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'hostname_for_vms_creation': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'internal_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15', 'null': 'True', 'blank': 'True'}),
'is_proxmox': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_vm': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'keymanger_name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'logstash_shipper': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'ngnix_server': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'ngnixed_server_set'", 'null': 'True', 'to': u"orm['servers.Server']"}),
'proxmox_node_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'samba_base_folder': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255', 'null': 'True', 'blank': 'True'}),
'samba_management': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'ssh_connection_string_from_backup': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'ssh_connection_string_from_gestion': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'vm_host': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'server_set'", 'null': 'True', 'to': u"orm['servers.Server']"})
}
}

complete_apps = ['logstash']
Empty file added logstash/migrations/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions logstash/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.db import models


from servers.models import Server


class File(models.Model):
"""A file to monitor"""

server = models.ForeignKey(Server)

file = models.CharField(max_length=255)

TYPE_CHOICES = (('apachelog', 'Apache log'), ('syslog', 'Syslog'), ('misc', 'Misc'))
type = models.CharField(max_length=255, choices=TYPE_CHOICES)

tags = models.CharField(max_length=512)

def sorted_tags(self):
"""Return the list of tags, sorted"""
return ','.join(sorted(self.tags.split(',')))




class Execution(models.Model):

output = models.TextField()
done = models.BooleanField(default=False)
sugested_result = models.TextField()
Loading

0 comments on commit a635d86

Please sign in to comment.