1 | # -*- coding: utf-8 -*- |
||
2 | # Copyright (C) 2017-2021 Greenbone Networks GmbH |
||
3 | # |
||
4 | # SPDX-License-Identifier: GPL-3.0-or-later |
||
5 | # |
||
6 | # This program is free software: you can redistribute it and/or modify |
||
7 | # it under the terms of the GNU General Public License as published by |
||
8 | # the Free Software Foundation, either version 3 of the License, or |
||
9 | # (at your option) any later version. |
||
10 | # |
||
11 | # This program is distributed in the hope that it will be useful, |
||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | # GNU General Public License for more details. |
||
15 | # |
||
16 | # You should have received a copy of the GNU General Public License |
||
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | |||
19 | import sys |
||
20 | |||
21 | from random import choice |
||
22 | |||
23 | from gvmtools.helper import generate_id |
||
24 | |||
25 | |||
26 | def check_args(args): |
||
27 | len_args = len(args.script) - 1 |
||
28 | if len_args != 1: |
||
29 | message = """ |
||
30 | This script will create random data in the given GVM database |
||
31 | |||
32 | 1. <count> -- Number of datasets to create |
||
33 | |||
34 | Example: |
||
35 | $ gvm-script --gmp-username name --gmp-password pass \ |
||
36 | ssh --hostname <gsm> scripts/create-dummy-data.gmp.py <count> |
||
37 | """ |
||
38 | print(message) |
||
39 | sys.exit() |
||
40 | |||
41 | |||
42 | def create_data(gmp, count): |
||
43 | config_ids = [] |
||
44 | target_ids = [] |
||
45 | |||
46 | for _ in range(0, count): |
||
47 | name = generate_id() |
||
48 | gmp.create_credential( |
||
49 | name, |
||
50 | login=name, |
||
51 | password=name, |
||
52 | credential_type=gmp.types.CredentialType.PASSWORD_ONLY, |
||
53 | ) |
||
54 | print(str(count) + ' random credentials generated.') |
||
55 | |||
56 | for _ in range(0, count): |
||
57 | name = generate_id() |
||
58 | gmp.create_port_list(name, port_range='T:1-42') |
||
59 | print(str(count) + ' random port lists generated.') |
||
60 | |||
61 | for _ in range(0, count): |
||
62 | name = generate_id() |
||
63 | res = gmp.create_config('085569ce-73ed-11df-83c3-002264764cea', name) |
||
64 | config_ids.append(res.xpath('@id')[0]) |
||
65 | print(str(count) + ' random scan configs generated.') |
||
66 | |||
67 | for _ in range(0, count): |
||
68 | name = generate_id() |
||
69 | res = gmp.create_target(name, hosts=['127.0.0.1']) |
||
70 | |||
71 | target_ids.append(res.xpath('@id')[0]) |
||
72 | print(str(count) + ' random targets generated.') |
||
73 | |||
74 | for _ in range(0, count): |
||
75 | name = generate_id() |
||
76 | config_id = choice(config_ids) |
||
77 | target_id = choice(target_ids) |
||
78 | gmp.create_task( |
||
79 | name, config_id, target_id, '08b69003-5fc2-4037-a479-93b440211c73' |
||
80 | ) |
||
81 | print(str(count) + ' random tasks generated.') |
||
82 | |||
83 | |||
84 | def main(gmp, args): |
||
85 | # pylint: disable=undefined-variable |
||
86 | |||
87 | check_args(args) |
||
88 | |||
89 | create_data(gmp, int(args.script[1])) |
||
90 | |||
91 | |||
92 | if __name__ == '__gmp__': |
||
93 | main(gmp, args) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() Comprehensibility
Best Practice
introduced
by
|
|||
94 |