Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Django execute_code command #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions deployer/contrib/services/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def settings_module(self):
def wsgi_app_location(self):
return '/etc/wsgi-apps/%s.py' % self.slug

def execute_code(self, code):
self.hosts.run(self._get_management_command('shell --plain') + " <<__HEREDOC__\n" + code + "\n__HEREDOC__")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on magic escape characters and can possibly suffer from injection.

Please refactor to something like this:

self.hosts.run(self._get_management_command('shell --plain'), initial_input = '%s\nimport sys; sys.exit(0)' % code)

That should already work out of the box.

Better would even be, to add a boolean option to Host._run and Host._posix_shell called "send_EOF_after_initial_input"
If True, send Ctrl-D after the initial input.

Then it becomes:

self.hosts.run(self._get_management_command('shell --plain'), initial_input=code, send_EOF_after_initial_input=True)

Not sure about the naming, but that's the idea.


# ===========[ WSGI setup ]============

Expand Down