netbox-plugin-plan-drawing 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. netbox_plugin_plan_drawing-1.0.0/LICENSE +21 -0
  2. netbox_plugin_plan_drawing-1.0.0/MANIFEST.in +4 -0
  3. netbox_plugin_plan_drawing-1.0.0/PKG-INFO +67 -0
  4. netbox_plugin_plan_drawing-1.0.0/README.md +44 -0
  5. netbox_plugin_plan_drawing-1.0.0/drawio-overrides/LICENSE +201 -0
  6. netbox_plugin_plan_drawing-1.0.0/drawio-overrides/js/PostConfig.js +15 -0
  7. netbox_plugin_plan_drawing-1.0.0/drawio-overrides/js/PreConfig.js +28 -0
  8. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/__init__.py +25 -0
  9. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/api/__init__.py +0 -0
  10. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/api/serializers.py +35 -0
  11. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/api/urls.py +11 -0
  12. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/api/views.py +37 -0
  13. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/assets.py +26 -0
  14. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/drawio.py +120 -0
  15. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/filtersets.py +87 -0
  16. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/forms.py +72 -0
  17. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/management/__init__.py +0 -0
  18. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/management/commands/__init__.py +0 -0
  19. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/management/commands/plan_drawing_changelog_stats.py +92 -0
  20. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/migrations/0001_initial.py +65 -0
  21. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/migrations/__init__.py +0 -0
  22. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/models.py +198 -0
  23. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/navigation.py +25 -0
  24. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/object_types.py +120 -0
  25. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/search.py +16 -0
  26. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/static/netbox_plugin_plan_drawing/drawio-netbox.js +194 -0
  27. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/static/netbox_plugin_plan_drawing/editor.js +345 -0
  28. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/static/netbox_plugin_plan_drawing/plan-drawing.css +80 -0
  29. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/static/netbox_plugin_plan_drawing/viewer.js +470 -0
  30. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tables.py +22 -0
  31. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/template_content.py +45 -0
  32. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/templates/netbox_plugin_plan_drawing/inc/object_drawings_panel.html +12 -0
  33. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/templates/netbox_plugin_plan_drawing/plandrawing.html +131 -0
  34. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/templates/netbox_plugin_plan_drawing/plandrawing_draw.html +70 -0
  35. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/templatetags/__init__.py +0 -0
  36. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/templatetags/plan_drawing.py +10 -0
  37. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/__init__.py +0 -0
  38. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/test_api.py +69 -0
  39. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/test_drawio.py +87 -0
  40. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/test_models.py +92 -0
  41. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/test_object_types.py +29 -0
  42. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/test_views.py +117 -0
  43. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/tests/utils.py +51 -0
  44. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/urls.py +12 -0
  45. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing/views.py +218 -0
  46. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing.egg-info/PKG-INFO +67 -0
  47. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing.egg-info/SOURCES.txt +52 -0
  48. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing.egg-info/dependency_links.txt +1 -0
  49. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing.egg-info/requires.txt +1 -0
  50. netbox_plugin_plan_drawing-1.0.0/netbox_plugin_plan_drawing.egg-info/top_level.txt +1 -0
  51. netbox_plugin_plan_drawing-1.0.0/pyproject.toml +39 -0
  52. netbox_plugin_plan_drawing-1.0.0/scripts/fetch_drawio.py +120 -0
  53. netbox_plugin_plan_drawing-1.0.0/setup.cfg +4 -0
  54. netbox_plugin_plan_drawing-1.0.0/setup.py +29 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stefan Bethke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ include LICENSE README.md
2
+ include scripts/fetch_drawio.py
3
+ graft drawio-overrides
4
+ prune netbox_plugin_plan_drawing/static/netbox_plugin_plan_drawing/drawio
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: netbox-plugin-plan-drawing
3
+ Version: 1.0.0
4
+ Summary: NetBox plugin for plan drawings (floor plans etc.) with draw.io, linking drawing elements to NetBox objects
5
+ Author-email: Stefan Bethke <stb@lassitu.de>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/stblassitude/netbox-plugin-plan-drawing
8
+ Project-URL: Documentation, https://stblassitude.github.io/netbox-plugin-plan-drawing/
9
+ Project-URL: Issues, https://github.com/stblassitude/netbox-plugin-plan-drawing/issues
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Framework :: Django
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: defusedxml>=0.7
22
+ Dynamic: license-file
23
+
24
+ # Netbox Plugin: Plan Drawing
25
+
26
+ This plugin provides the ability to add plan drawings, like floor plans, to Netbox, and place objects like devices, racks, or locations on those plans.
27
+
28
+ The plugin embeds draw.io to create and update the drawings. Each object in the drawing can be associated with a Netbox object. A draw.io plugin implements the necessary GUI to select the Netbox object to attach to a draw.io object in the drawing.
29
+
30
+ Besides a list of drawings and the ability to edit them with draw.io, a drawing viewer shows a drawing and the Netbox objects associated with the drawing objects in that file. A search allows to highlight elements based on their Netbox objects. Netbox object pages are extended with links to the drawing viewer, so a single click takes you from an object to the drawing it is in, and hightlights the element for that objects.
31
+
32
+ draw.io is included in the plugin and served by NetBox itself: there is no separate service to install, and nothing is sent to draw.io's online services.
33
+
34
+ ![The drawing viewer, with the access point ap1 highlighted](https://raw.githubusercontent.com/stblassitude/netbox-plugin-plan-drawing/main/docs/images/viewer.png)
35
+
36
+ **Documentation: <https://stblassitude.github.io/netbox-plugin-plan-drawing/>**
37
+
38
+ * [Overview](https://stblassitude.github.io/netbox-plugin-plan-drawing/): viewing and editing drawings, and linking elements to NetBox objects
39
+ * [Installation](https://stblassitude.github.io/netbox-plugin-plan-drawing/installation/): installation and configuration
40
+ * [REST API](https://stblassitude.github.io/netbox-plugin-plan-drawing/rest-api/)
41
+ * [Development](https://stblassitude.github.io/netbox-plugin-plan-drawing/development/) and [implementation notes](https://stblassitude.github.io/netbox-plugin-plan-drawing/implementation/)
42
+
43
+ ## Compatibility
44
+
45
+ | NetBox Version | Plugin Version |
46
+ |-----------------|----------------|
47
+ | 4.7 - 4.99 | 1.0.0 |
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install netbox-plugin-plan-drawing
53
+ ```
54
+
55
+ Add `"netbox_plugin_plan_drawing"` to `PLUGINS` in NetBox's `configuration.py`, then run `python manage.py migrate` and `python manage.py collectstatic --no-input`, and restart NetBox. See the [installation guide](https://stblassitude.github.io/netbox-plugin-plan-drawing/installation/) for details and configuration options.
56
+
57
+ ## Development
58
+
59
+ ```bash
60
+ docker compose up -d --build
61
+ ```
62
+
63
+ This starts NetBox with the plugin installed from the source tree, and demo data, at <http://localhost:8000/> (`admin` / `admin`). Run the tests with `docker compose exec netbox python manage.py test netbox_plugin_plan_drawing`. See the [development guide](https://stblassitude.github.io/netbox-plugin-plan-drawing/development/) for more.
64
+
65
+ ## License
66
+
67
+ MIT; see [LICENSE](LICENSE). The bundled [draw.io](https://github.com/jgraph/drawio) is licensed under the Apache License 2.0.
@@ -0,0 +1,44 @@
1
+ # Netbox Plugin: Plan Drawing
2
+
3
+ This plugin provides the ability to add plan drawings, like floor plans, to Netbox, and place objects like devices, racks, or locations on those plans.
4
+
5
+ The plugin embeds draw.io to create and update the drawings. Each object in the drawing can be associated with a Netbox object. A draw.io plugin implements the necessary GUI to select the Netbox object to attach to a draw.io object in the drawing.
6
+
7
+ Besides a list of drawings and the ability to edit them with draw.io, a drawing viewer shows a drawing and the Netbox objects associated with the drawing objects in that file. A search allows to highlight elements based on their Netbox objects. Netbox object pages are extended with links to the drawing viewer, so a single click takes you from an object to the drawing it is in, and hightlights the element for that objects.
8
+
9
+ draw.io is included in the plugin and served by NetBox itself: there is no separate service to install, and nothing is sent to draw.io's online services.
10
+
11
+ ![The drawing viewer, with the access point ap1 highlighted](https://raw.githubusercontent.com/stblassitude/netbox-plugin-plan-drawing/main/docs/images/viewer.png)
12
+
13
+ **Documentation: <https://stblassitude.github.io/netbox-plugin-plan-drawing/>**
14
+
15
+ * [Overview](https://stblassitude.github.io/netbox-plugin-plan-drawing/): viewing and editing drawings, and linking elements to NetBox objects
16
+ * [Installation](https://stblassitude.github.io/netbox-plugin-plan-drawing/installation/): installation and configuration
17
+ * [REST API](https://stblassitude.github.io/netbox-plugin-plan-drawing/rest-api/)
18
+ * [Development](https://stblassitude.github.io/netbox-plugin-plan-drawing/development/) and [implementation notes](https://stblassitude.github.io/netbox-plugin-plan-drawing/implementation/)
19
+
20
+ ## Compatibility
21
+
22
+ | NetBox Version | Plugin Version |
23
+ |-----------------|----------------|
24
+ | 4.7 - 4.99 | 1.0.0 |
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install netbox-plugin-plan-drawing
30
+ ```
31
+
32
+ Add `"netbox_plugin_plan_drawing"` to `PLUGINS` in NetBox's `configuration.py`, then run `python manage.py migrate` and `python manage.py collectstatic --no-input`, and restart NetBox. See the [installation guide](https://stblassitude.github.io/netbox-plugin-plan-drawing/installation/) for details and configuration options.
33
+
34
+ ## Development
35
+
36
+ ```bash
37
+ docker compose up -d --build
38
+ ```
39
+
40
+ This starts NetBox with the plugin installed from the source tree, and demo data, at <http://localhost:8000/> (`admin` / `admin`). Run the tests with `docker compose exec netbox python manage.py test netbox_plugin_plan_drawing`. See the [development guide](https://stblassitude.github.io/netbox-plugin-plan-drawing/development/) for more.
41
+
42
+ ## License
43
+
44
+ MIT; see [LICENSE](LICENSE). The bundled [draw.io](https://github.com/jgraph/drawio) is licensed under the Apache License 2.0.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * draw.io configuration for the copy bundled with netbox-plugin-plan-drawing. Replaces the
3
+ * stock js/PostConfig.js; loaded after draw.io's code, but before the application starts.
4
+ */
5
+ window.ICONSEARCH_PATH = null;
6
+ window.ICON_SERVICE_PATH = null;
7
+
8
+ // Registers the NetBox plugin as a built-in plugin, so that it can be loaded with ?p=netbox.
9
+ // The plugin lives next to the drawio directory in the plugin's static files; the editor page
10
+ // passes a version (nbv) to bypass cached copies of older versions.
11
+ if (typeof App !== 'undefined')
12
+ {
13
+ App.pluginRegistry['netbox'] = '../drawio-netbox.js' +
14
+ ((urlParams['nbv'] != null) ? '?v=' + encodeURIComponent(urlParams['nbv']) : '');
15
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * draw.io configuration for the copy bundled with netbox-plugin-plan-drawing. Replaces the
3
+ * stock js/PreConfig.js; loaded before draw.io initializes.
4
+ *
5
+ * draw.io runs embedded in NetBox pages only: all online services and integrations are off.
6
+ */
7
+ window.DRAWIO_PUBLIC_BUILD = true;
8
+ window.EXPORT_URL = null;
9
+ window.DRAWIO_BASE_URL = null;
10
+ window.DRAWIO_VIEWER_URL = null;
11
+ window.DRAWIO_LIGHTBOX_URL = null;
12
+ window.DRAW_MATH_URL = null;
13
+ window.DRAWIO_CONFIG = null;
14
+ window.DRAWIO_GOOGLE_APP_ID = null;
15
+ window.DRAWIO_GOOGLE_CLIENT_ID = null;
16
+ window.DRAWIO_MSGRAPH_CLIENT_ID = null;
17
+ window.DRAWIO_GITLAB_ID = null;
18
+ window.DRAWIO_GITHUB_ID = null;
19
+ window.DRAWIO_DROPBOX_ID = null;
20
+ window.DRAWIO_NEXTCLOUD_ID = null;
21
+ urlParams['sync'] = 'manual';
22
+ urlParams['gapi'] = '0';
23
+ urlParams['db'] = '0';
24
+ urlParams['od'] = '0';
25
+ urlParams['gh'] = '0';
26
+ urlParams['gl'] = '0';
27
+ urlParams['tr'] = '0';
28
+ urlParams['math'] = '0';
@@ -0,0 +1,25 @@
1
+ from netbox.plugins import PluginConfig
2
+
3
+
4
+ class PlanDrawingConfig(PluginConfig):
5
+ name = 'netbox_plugin_plan_drawing'
6
+ verbose_name = 'Plan Drawings'
7
+ description = 'Plan drawings (floor plans etc.) edited with draw.io, with elements linked to NetBox objects'
8
+ version = '1.0.0'
9
+ author = 'Stefan Bethke'
10
+ author_email = 'stb@lassitu.de'
11
+ base_url = 'plan-drawing'
12
+ min_version = '4.7.0'
13
+ max_version = '4.99.99'
14
+ default_settings = {
15
+ # Apps whose models can be linked to drawing elements.
16
+ 'object_type_apps': ['dcim', 'circuits', 'wireless'],
17
+ # Models from those apps that cannot be linked, as '<app_label>.<model_name>'. Replaces
18
+ # the built-in default list (see object_types.DEFAULT_EXCLUDED_OBJECT_TYPES) when set.
19
+ 'exclude_object_types': None,
20
+ # Additional linkable models from other apps or plugins, as '<app_label>.<model_name>'.
21
+ 'extra_object_types': [],
22
+ }
23
+
24
+
25
+ config = PlanDrawingConfig
@@ -0,0 +1,35 @@
1
+ from dcim.api.serializers import LocationSerializer, SiteSerializer
2
+ from netbox.api.fields import ContentTypeField, RelatedObjectCountField
3
+ from netbox.api.gfk_fields import GFKSerializerField
4
+ from netbox.api.serializers import BaseModelSerializer, PrimaryModelSerializer
5
+
6
+ from ..models import PlanDrawing, PlanDrawingElement
7
+
8
+
9
+ class PlanDrawingSerializer(PrimaryModelSerializer):
10
+ site = SiteSerializer(nested=True, required=False, allow_null=True)
11
+ location = LocationSerializer(nested=True, required=False, allow_null=True)
12
+ element_count = RelatedObjectCountField('elements')
13
+
14
+ class Meta:
15
+ model = PlanDrawing
16
+ fields = (
17
+ 'id', 'url', 'display_url', 'display', 'name', 'site', 'location', 'description', 'content',
18
+ 'element_count', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
19
+ )
20
+ brief_fields = ('id', 'url', 'display', 'name', 'description')
21
+
22
+
23
+ class PlanDrawingElementSerializer(BaseModelSerializer):
24
+ drawing = PlanDrawingSerializer(nested=True, read_only=True)
25
+ assigned_object_type = ContentTypeField(read_only=True)
26
+ assigned_object = GFKSerializerField(read_only=True)
27
+
28
+ class Meta:
29
+ model = PlanDrawingElement
30
+ fields = (
31
+ 'id', 'url', 'display', 'drawing', 'page_id', 'page_name', 'cell_id', 'label',
32
+ 'assigned_object_type', 'assigned_object_id', 'assigned_object',
33
+ )
34
+ brief_fields = ('id', 'url', 'display', 'cell_id', 'label')
35
+
@@ -0,0 +1,11 @@
1
+ from netbox.api.routers import NetBoxRouter
2
+
3
+ from . import views
4
+
5
+ app_name = 'netbox_plugin_plan_drawing'
6
+
7
+ router = NetBoxRouter()
8
+ router.register('drawings', views.PlanDrawingViewSet)
9
+ router.register('elements', views.PlanDrawingElementViewSet)
10
+
11
+ urlpatterns = router.urls
@@ -0,0 +1,37 @@
1
+ from netbox.api.authentication import TokenPermissions
2
+ from netbox.api.viewsets import NetBoxModelViewSet, NetBoxReadOnlyModelViewSet
3
+ from utilities.query import count_related
4
+
5
+ from ..filtersets import PlanDrawingElementFilterSet, PlanDrawingFilterSet
6
+ from ..models import PlanDrawing, PlanDrawingElement
7
+ from .serializers import PlanDrawingElementSerializer, PlanDrawingSerializer
8
+
9
+
10
+ class PlanDrawingViewSet(NetBoxModelViewSet):
11
+ queryset = PlanDrawing.objects.annotate(
12
+ element_count=count_related(PlanDrawingElement, 'drawing'),
13
+ )
14
+ serializer_class = PlanDrawingSerializer
15
+ filterset_class = PlanDrawingFilterSet
16
+
17
+
18
+ class PlanDrawingElementPermissions(TokenPermissions):
19
+ """
20
+ Drawing elements can be viewed by users who may view drawings; the queryset is restricted
21
+ to the drawings they may view (see PlanDrawingElementQuerySet).
22
+ """
23
+ perms_map = {
24
+ **TokenPermissions.perms_map,
25
+ 'GET': ['netbox_plugin_plan_drawing.view_plandrawing'],
26
+ 'HEAD': ['netbox_plugin_plan_drawing.view_plandrawing'],
27
+ }
28
+
29
+ def has_object_permission(self, request, view, obj):
30
+ return True
31
+
32
+
33
+ class PlanDrawingElementViewSet(NetBoxReadOnlyModelViewSet):
34
+ queryset = PlanDrawingElement.objects.select_related('drawing', 'assigned_object_type')
35
+ permission_classes = (PlanDrawingElementPermissions,)
36
+ serializer_class = PlanDrawingElementSerializer
37
+ filterset_class = PlanDrawingElementFilterSet
@@ -0,0 +1,26 @@
1
+ """
2
+ Versioned URLs for the plugin's static files.
3
+
4
+ NetBox serves static files with a long cache lifetime, and the plugin's files keep their names
5
+ across releases; a content hash in the query string makes browsers load changed files.
6
+ """
7
+ import hashlib
8
+ from functools import cache
9
+
10
+ from django.contrib.staticfiles import finders
11
+ from django.templatetags.static import static
12
+
13
+
14
+ @cache
15
+ def static_digest(path):
16
+ found = finders.find(path)
17
+ if not found:
18
+ return None
19
+ with open(found, 'rb') as f:
20
+ return hashlib.sha256(f.read()).hexdigest()[:12]
21
+
22
+
23
+ def versioned_static(path):
24
+ url = static(path)
25
+ digest = static_digest(path)
26
+ return f'{url}?v={digest}' if digest else url
@@ -0,0 +1,120 @@
1
+ """
2
+ Reading draw.io files.
3
+
4
+ A draw.io file is an <mxfile> with one <diagram> per page; each page holds an <mxGraphModel>,
5
+ either as XML or compressed (raw deflate, base64 encoded, of the URL-encoded XML). Cells with
6
+ custom properties are wrapped in an <object> (or <UserObject>) element carrying those
7
+ properties as attributes. A cell linked to a NetBox object carries two of them:
8
+
9
+ <object id="7" label="Rack 1" netbox_type="dcim.rack" netbox_id="12">
10
+ <mxCell style="..." vertex="1" parent="1">...</mxCell>
11
+ </object>
12
+ """
13
+ import base64
14
+ import html
15
+ import re
16
+ import urllib.parse
17
+ import zlib
18
+ from dataclasses import dataclass
19
+ from xml.etree.ElementTree import ParseError
20
+
21
+ from defusedxml import DefusedXmlException
22
+ from defusedxml.ElementTree import fromstring
23
+ from django.utils.html import strip_tags
24
+
25
+ TYPE_ATTRIBUTE = 'netbox_type'
26
+ ID_ATTRIBUTE = 'netbox_id'
27
+ LABEL_MAX_LENGTH = 200
28
+
29
+
30
+ class DrawingParseError(ValueError):
31
+ pass
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class DrawingLink:
36
+ page_id: str
37
+ page_name: str
38
+ cell_id: str
39
+ label: str
40
+ object_type: str
41
+ object_id: int
42
+
43
+
44
+ def _parse_xml(text):
45
+ try:
46
+ return fromstring(text)
47
+ except (ParseError, DefusedXmlException) as e:
48
+ raise DrawingParseError(f'Invalid drawing XML: {e}')
49
+
50
+
51
+ def decompress_diagram(text):
52
+ try:
53
+ data = zlib.decompress(base64.b64decode(text), -zlib.MAX_WBITS)
54
+ except (ValueError, zlib.error) as e:
55
+ raise DrawingParseError(f'Invalid compressed diagram: {e}')
56
+ return urllib.parse.unquote(data.decode('utf-8'))
57
+
58
+
59
+ def iter_pages(content):
60
+ """
61
+ Yield (page_id, page_name, mxGraphModel element) for each page of a drawing.
62
+ """
63
+ root = _parse_xml(content)
64
+ if root.tag == 'mxGraphModel':
65
+ yield '', '', root
66
+ return
67
+ if root.tag != 'mxfile':
68
+ raise DrawingParseError(f'Not a draw.io file: unexpected root element <{root.tag}>')
69
+
70
+ for index, diagram in enumerate(root.findall('diagram')):
71
+ page_id = diagram.get('id') or str(index)
72
+ page_name = diagram.get('name') or f'Page-{index + 1}'
73
+ model = diagram.find('mxGraphModel')
74
+ if model is None:
75
+ text = (diagram.text or '').strip()
76
+ if not text:
77
+ continue
78
+ model = _parse_xml(decompress_diagram(text))
79
+ yield page_id, page_name, model
80
+
81
+
82
+ def label_text(label):
83
+ """
84
+ Return the plain text of a cell label, which may contain HTML.
85
+ """
86
+ text = re.sub(r'<br\s*/?>|</div>|</p>', ' ', label or '', flags=re.IGNORECASE)
87
+ text = ' '.join(html.unescape(strip_tags(text)).split())
88
+ return text[:LABEL_MAX_LENGTH]
89
+
90
+
91
+ def parse_links(content):
92
+ """
93
+ Return a DrawingLink for every cell in the drawing that is linked to a NetBox object.
94
+ """
95
+ if not content or not content.strip():
96
+ return []
97
+
98
+ links = []
99
+ for page_id, page_name, model in iter_pages(content):
100
+ for element in model.iter():
101
+ object_type = element.get(TYPE_ATTRIBUTE)
102
+ object_id = element.get(ID_ATTRIBUTE)
103
+ if not object_type and not object_id:
104
+ continue
105
+ cell_id = element.get('id', '')
106
+ if not object_type or not object_id:
107
+ raise DrawingParseError(f'Cell {cell_id} has an incomplete NetBox object link')
108
+ try:
109
+ object_id = int(object_id)
110
+ except ValueError:
111
+ raise DrawingParseError(f'Cell {cell_id} links to an invalid NetBox object ID: {object_id}')
112
+ links.append(DrawingLink(
113
+ page_id=page_id,
114
+ page_name=page_name,
115
+ cell_id=cell_id,
116
+ label=label_text(element.get('label')),
117
+ object_type=object_type.lower(),
118
+ object_id=object_id,
119
+ ))
120
+ return links