-
-
Notifications
You must be signed in to change notification settings - Fork 95
add management commands #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
furlongm
wants to merge
46
commits into
main
Choose a base branch
from
add-management-commands
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
9f08e61
Update __init__.py
grumo35 bc964ca
Merge branch 'master' into patch-1
furlongm 57b33e1
Merge branch 'master' into patch-1
furlongm 15e9be0
Add management commands
skatsaounis 726fa74
Add set_site command
skatsaounis 6d0b4b0
Fix option
skatsaounis 58d36e3
Update apps.py
furlongm 8072e34
Merge branch 'master' into patch-1
furlongm fecca1c
Merge branch 'main' into patch-1
furlongm 684516b
Merge branch 'main' into add-management-commands
furlongm ae7d58e
Merge branch 'main' into patch-1
furlongm cd577bf
Update __init__.py
furlongm 80a2d60
Update __init__.py
furlongm 12b2d79
Merge branch 'main' into patch-1
furlongm e1dde1b
Merge branch 'main' into add-management-commands
furlongm d44a2ce
handle duplicate CVSSes better
08faacd
Merge pull request #681 from furlongm/cvss-fix
furlongm bf626c9
reduce max charfield length for mysql
furlongm 382cd29
further reduce charfield size for mysql
furlongm 20a42ed
reduce URLField max_length to 765
furlongm 33d15b2
Merge pull request #673 from furlongm/bug/mysql-max-col-length
furlongm 5685ef3
Merge branch 'main' into patch-1
furlongm bf5478c
Bump django from 4.2.20 to 4.2.21
dependabot[bot] d9c6df7
Merge pull request #682 from furlongm/dependabot/pip/django-4.2.21
furlongm 57e5c0d
Bump django from 4.2.21 to 4.2.22
dependabot[bot] 6a45e90
Bump requests from 2.32.3 to 2.32.4
dependabot[bot] 64b1920
Merge pull request #684 from furlongm/dependabot/pip/django-4.2.22
furlongm 334af8f
Merge pull request #685 from furlongm/dependabot/pip/requests-2.32.4
furlongm 5674853
Remove unused dependency 'chardet' from requirements.txt
vtalos cf8c77f
Merge pull request #689 from vtalos/remove-unused-chardet
furlongm 94fcb04
get_or_create_module only returns module
furlongm 1480468
Bump django from 4.2.22 to 4.2.24
dependabot[bot] 36cefb1
Merge pull request #700 from furlongm/dependabot/pip/django-4.2.24
furlongm 6aee812
Merge pull request #693 from furlongm/module-creation
furlongm b616296
Package types are in the Package class
willfurnell 3f8756c
Merge pull request #701 from willfurnell/package-fix
furlongm 3676e78
Bump django from 4.2.24 to 4.2.25
dependabot[bot] 1328e52
Merge pull request #704 from furlongm/dependabot/pip/django-4.2.25
furlongm 1c26001
bump redis
furlongm 0f54454
Update license in common.py
furlongm ce9f4f0
fix licenses
furlongm c651c3f
use GPL-3.0-only for debian copyright
furlongm 807e5de
Merge pull request #377 from grumo35/patch-1
furlongm 1c7ef23
Update patchman/management/commands/createsuperuser_with_password.py
furlongm f5b34d7
Update patchman/management/commands/createsuperuser_with_password.py
furlongm c3468c8
Merge branch 'main' into add-management-commands
furlongm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class PatchmanConfig(AppConfig): | ||
| name = 'patchman' |
Empty file.
Empty file.
33 changes: 33 additions & 0 deletions
33
patchman/management/commands/createsuperuser_with_password.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from django.contrib.auth.management.commands import createsuperuser | ||
| from django.core.management import CommandError | ||
|
|
||
|
|
||
| class Command(createsuperuser.Command): | ||
| help = 'Crate a superuser, and allow password to be provided' | ||
|
|
||
| def add_arguments(self, parser): | ||
| super().add_arguments(parser) | ||
| parser.add_argument( | ||
| '--password', dest='password', default=None, | ||
| help='Specifies the password for the superuser.', | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
| password = options.get('password') | ||
| username = options.get('username') | ||
| database = options.get('database') | ||
|
|
||
| if options['interactive']: | ||
| raise CommandError( | ||
| 'Command is required to run with --no-input option') | ||
| if password and not username: | ||
| raise CommandError( | ||
| '--username is required if specifying --password') | ||
|
|
||
| super().handle(*args, **options) | ||
|
|
||
| if password: | ||
| user = self.UserModel._default_manager.db_manager( | ||
| database).get(username=username) | ||
| user.set_password(password) | ||
| user.save() |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from django.core.management.base import BaseCommand, CommandError | ||
| from hosts.models import Host | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = 'Enable/Disable rDNS check for hosts' | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| '--disable', action='store_false', default=True, dest='rdns_check', | ||
| help='If set, disables rDNS check') | ||
|
|
||
| def handle(self, *args, **options): | ||
| try: | ||
| Host.objects.all().update(check_dns=options['rdns_check']) | ||
| except Exception as e: | ||
| raise CommandError('Failed to update rDNS check', str(e)) |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import os | ||
| import re | ||
| import sys | ||
| import codecs | ||
| from random import choice | ||
| from tempfile import NamedTemporaryFile | ||
| from shutil import copy | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = 'Set SECRET_KEY of Patchman Application.' | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| '--key', help=( | ||
| 'The SECRET_KEY to be used by Patchman. If not set, a random ' | ||
| 'key of length 50 will be created.')) | ||
|
|
||
| @staticmethod | ||
| def get_random_key(): | ||
| chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | ||
| return ''.join([choice(chars) for i in range(50)]) | ||
|
|
||
| def handle(self, *args, **options): | ||
| secret_key = options.get('key', self.get_random_key()) | ||
|
|
||
| if sys.prefix == '/usr': | ||
| conf_path = '/etc/patchman' | ||
| else: | ||
| conf_path = os.path.join(sys.prefix, 'etc/patchman') | ||
| # if conf_path doesn't exist, try ./etc/patchman | ||
| if not os.path.isdir(conf_path): | ||
| conf_path = './etc/patchman' | ||
| local_settings = os.path.join(conf_path, 'local_settings.py') | ||
|
|
||
| settings_contents = codecs.open( | ||
| local_settings, 'r', encoding='utf-8').read() | ||
| settings_contents = re.sub( | ||
| r"(?<=SECRET_KEY = ')'", secret_key + "'", settings_contents) | ||
|
|
||
| f = NamedTemporaryFile(delete=False) | ||
| temp = f.name | ||
| f.close() | ||
|
|
||
| fh = codecs.open(temp, 'w+b', encoding='utf-8') | ||
| fh.write(settings_contents) | ||
| fh.close() | ||
|
|
||
| copy(temp, local_settings) | ||
| os.remove(temp) | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from django.core.management.base import BaseCommand, CommandError | ||
| from django.contrib.sites.models import Site | ||
| from django.conf import settings | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = 'Set Patchman Site Name' | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| '-n', '--name', dest='site_name', help='Site name') | ||
| parser.add_argument( | ||
| '--clear-cache', action='store_true', default=False, | ||
| dest='clear_cache', help='Clear Site cache') | ||
|
|
||
| def handle(self, *args, **options): | ||
| try: | ||
| Site.objects.filter(pk=settings.SITE_ID).update( | ||
| name=options['site_name'], domain=options['site_name']) | ||
| if options['clear_cache']: | ||
| Site.objects.clear_cache() | ||
| except Exception as e: | ||
| raise CommandError('Failed to update Site name', str(e)) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.