-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
44 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
VERSION = (0, 0, 5) | ||
VERSION = (0, 1) | ||
|
||
|
||
def get_version(): | ||
return '.'.join([str(v) for v in VERSION]) | ||
return '.'.join(map(str, VERSION)) | ||
|
||
__version__ = get_version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
class Script(models.Model): | ||
name = models.CharField(max_length=100) | ||
source = models.TextField() | ||
name = models.CharField(_('Name'), max_length=100) | ||
source = models.TextField(_('Source')) | ||
|
||
class Meta: | ||
verbose_name = _('Script') | ||
verbose_name_plural = _('Scripts') | ||
|
||
def __unicode__(self): | ||
return self.name | ||
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from django.conf.urls import patterns, url | ||
from .views import execute_script_view | ||
|
||
urlpatterns = patterns('webshell.views', | ||
url(r'^execute/$', 'execute_script_view', name='execute-script'), | ||
) | ||
urlpatterns = patterns('', | ||
url(r'^execute/$', execute_script_view, name='execute-script'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import commands | ||
import sys | ||
import traceback | ||
from contextlib import contextmanager | ||
try: | ||
from StringIO import StringIO | ||
except ImportError: | ||
from io import StringIO | ||
|
||
from django.http import HttpResponse | ||
from django.views.decorators.http import require_POST | ||
from django.contrib.auth.decorators import permission_required | ||
|
||
|
||
@contextmanager | ||
def catch_stdout(buff): | ||
stdout = sys.stdout | ||
sys.stdout = buff | ||
yield | ||
sys.stdout = stdout | ||
|
||
|
||
@require_POST | ||
@permission_required('is_superuser') | ||
def execute_script_view(request): | ||
source = request.POST.get('source', '').replace('"', r'\"') | ||
result = commands.getoutput('python -c "%s"' % source) | ||
buff = StringIO() | ||
try: | ||
with catch_stdout(buff): | ||
exec(request.POST.get('source', '')) | ||
except: | ||
traceback.print_exc(file=buff) | ||
|
||
return HttpResponse(result) | ||
return HttpResponse(buff.getvalue()) |