Browse Source

- Добавлена поддержка конфига в web_leases

- Добавлен функционал всяческий
master
Mikhail Grebenkin 7 years ago
parent
commit
edba341936
9 changed files with 390 additions and 187 deletions
  1. +197
    -137
      .idea/workspace.xml
  2. +2
    -1
      config-sample.json
  3. +3
    -9
      kea_host_wacher.py
  4. +8
    -6
      kea_hosts_generane.py
  5. +13
    -9
      tpl/hosts.tpl
  6. +26
    -0
      tpl/import_hosts.tpl
  7. +15
    -3
      tpl/main.tpl
  8. +11
    -0
      tpl/remove_hosts.tpl
  9. +115
    -22
      web-leases.py

+ 197
- 137
.idea/workspace.xml View File

@ -1,9 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="860870ba-65f3-49c8-9afa-136b118d341a" name="Default" comment="Переработаны скрипты с поддержкой конфига, кроме веб-морды">
<list default="true" id="860870ba-65f3-49c8-9afa-136b118d341a" name="Default" comment="">
<change beforePath="" afterPath="$PROJECT_DIR$/tpl/import_hosts.tpl" />
<change beforePath="" afterPath="$PROJECT_DIR$/tpl/remove_hosts.tpl" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change beforePath="$PROJECT_DIR$/config-sample.json" afterPath="$PROJECT_DIR$/config-sample.json" />
<change beforePath="$PROJECT_DIR$/hosts.tpl" afterPath="$PROJECT_DIR$/tpl/hosts.tpl" />
<change beforePath="$PROJECT_DIR$/kea_host_wacher.py" afterPath="$PROJECT_DIR$/kea_host_wacher.py" />
<change beforePath="$PROJECT_DIR$/kea_hosts_generane.py" afterPath="$PROJECT_DIR$/kea_hosts_generane.py" />
<change beforePath="$PROJECT_DIR$/main.tpl" afterPath="$PROJECT_DIR$/tpl/main.tpl" />
<change beforePath="$PROJECT_DIR$/web-leases.py" afterPath="$PROJECT_DIR$/web-leases.py" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
@ -17,14 +24,12 @@
<file leaf-file-name="kea_hosts_generane.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/kea_hosts_generane.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="612">
<caret line="57" column="30" lean-forward="false" selection-start-line="57" selection-start-column="30" selection-end-line="57" selection-end-column="30" />
<state relative-caret-position="468">
<caret line="144" column="19" lean-forward="true" selection-start-line="144" selection-start-column="19" selection-end-line="144" selection-end-column="19" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -33,10 +38,10 @@
<file leaf-file-name="kea_host_wacher.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/kea_host_wacher.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="246">
<caret line="33" column="26" lean-forward="true" selection-start-line="33" selection-start-column="26" selection-end-line="33" selection-end-column="26" />
<state relative-caret-position="-450">
<caret line="15" column="23" lean-forward="true" selection-start-line="15" selection-start-column="23" selection-end-line="15" selection-end-column="23" />
<folding>
<element signature="e#36#47#0" expanded="true" />
<element signature="e#36#50#0" expanded="true" />
</folding>
</state>
</provider>
@ -45,8 +50,18 @@
<file leaf-file-name="config.json" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="11" column="0" lean-forward="false" selection-start-line="11" selection-start-column="0" selection-end-line="11" selection-end-column="0" />
<state relative-caret-position="180">
<caret line="10" column="0" lean-forward="false" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="config-sample.json" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/config-sample.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="216">
<caret line="12" column="0" lean-forward="true" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding />
</state>
</provider>
@ -55,30 +70,51 @@
<file leaf-file-name="web-leases.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/web-leases.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1728">
<caret line="97" column="39" lean-forward="false" selection-start-line="97" selection-start-column="39" selection-end-line="97" selection-end-column="39" />
<state relative-caret-position="450">
<caret line="172" column="24" lean-forward="false" selection-start-line="172" selection-start-column="24" selection-end-line="172" selection-end-column="24" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="import_hosts.tpl" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tpl/import_hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="450">
<caret line="25" column="7" lean-forward="true" selection-start-line="25" selection-start-column="7" selection-end-line="25" selection-end-column="7" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="remove_hosts.tpl" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/tpl/remove_hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="108">
<caret line="6" column="17" lean-forward="false" selection-start-line="6" selection-start-column="17" selection-end-line="6" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="hosts.tpl" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/hosts.tpl">
<entry file="file://$PROJECT_DIR$/tpl/hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="324">
<caret line="18" column="12" lean-forward="false" selection-start-line="18" selection-start-column="12" selection-end-line="18" selection-end-column="12" />
<state relative-caret-position="180">
<caret line="10" column="44" lean-forward="false" selection-start-line="10" selection-start-column="44" selection-end-line="10" selection-end-column="44" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="main.tpl" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="288">
<caret line="16" column="13" lean-forward="false" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
<state relative-caret-position="180">
<caret line="10" column="44" lean-forward="true" selection-start-line="10" selection-start-column="8" selection-end-line="10" selection-end-column="44" />
<folding />
</state>
</provider>
@ -95,8 +131,9 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>print</find>
<find>read_t</find>
<find>print</find>
<find>send_data</find>
</findStrings>
</component>
<component name="Git.Settings">
@ -105,20 +142,24 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/web-leases.py" />
<option value="$PROJECT_DIR$/main.tpl" />
<option value="$PROJECT_DIR$/hosts.tpl" />
<option value="$PROJECT_DIR$/config-sample.json" />
<option value="$PROJECT_DIR$/kea_host_wacher.py" />
<option value="$PROJECT_DIR$/config.json" />
<option value="$PROJECT_DIR$/config-sample.json" />
<option value="$PROJECT_DIR$/hosts.tpl" />
<option value="$PROJECT_DIR$/tpl/import_hosts.tpl" />
<option value="$PROJECT_DIR$/main.tpl" />
<option value="$PROJECT_DIR$/tpl/hosts.tpl" />
<option value="$PROJECT_DIR$/kea_hosts_generane.py" />
<option value="$PROJECT_DIR$/kea_host_wacher.py" />
<option value="$PROJECT_DIR$/tpl/remove_hosts.tpl" />
<option value="$PROJECT_DIR$/web-leases.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="y" value="610" />
<option name="width" value="1366" />
<option name="height" value="772" />
<option name="x" value="2321" />
<option name="y" value="206" />
<option name="width" value="1364" />
<option name="height" value="764" />
</component>
<component name="ProjectLevelVcsManager">
<ConfirmationsSetting value="1" id="Add" />
@ -145,6 +186,11 @@
<item name="kea_for_miners" type="b2602c69:ProjectViewProjectNode" />
<item name="kea_for_miners" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="kea_for_miners" type="b2602c69:ProjectViewProjectNode" />
<item name="kea_for_miners" type="462c0819:PsiDirectoryNode" />
<item name="tpl" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
@ -158,7 +204,11 @@
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/tpl" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/tpl" />
<recent name="$PROJECT_DIR$" />
</key>
</component>
@ -298,23 +348,29 @@
<option name="project" value="LOCAL" />
<updated>1513972942286</updated>
</task>
<option name="localTasksCounter" value="7" />
<task id="LOCAL-00007" summary="Поправил wotcher так, чтобы не цеплял лизинг с нулевым третьим октетом">
<created>1514411099952</created>
<option name="number" value="00007" />
<option name="presentableId" value="LOCAL-00007" />
<option name="project" value="LOCAL" />
<updated>1514411099952</updated>
</task>
<option name="localTasksCounter" value="8" />
<servers />
</component>
<component name="ToolWindowManager">
<frame x="0" y="610" width="1368" height="780" extended-state="6" />
<editor active="true" />
<frame x="1366" y="-4" width="1920" height="1084" extended-state="6" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1420205" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.10104167" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32882884" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3093093" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.21063395" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3997006" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.398773" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
@ -335,11 +391,12 @@
<MESSAGE value="Довел до ума отчет." />
<MESSAGE value="Добавлена поддержа конфига для создания хостов" />
<MESSAGE value="Переработаны скрипты с поддержкой конфига, кроме веб-морды" />
<option name="LAST_COMMIT_MESSAGE" value="Переработаны скрипты с поддержкой конфига, кроме веб-морды" />
<MESSAGE value="Поправил wotcher так, чтобы не цеплял лизинг с нулевым третьим октетом" />
<option name="LAST_COMMIT_MESSAGE" value="Поправил wotcher так, чтобы не цеплял лизинг с нулевым третьим октетом" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<option name="time" value="2" />
<option name="time" value="5" />
</breakpoint-manager>
<watches-manager />
</component>
@ -350,10 +407,8 @@
<caret line="57" column="30" lean-forward="false" selection-start-line="57" selection-start-column="30" selection-end-line="57" selection-end-column="30" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -363,7 +418,8 @@
<state relative-caret-position="1728">
<caret line="97" column="39" lean-forward="false" selection-start-line="97" selection-start-column="39" selection-end-line="97" selection-end-column="39" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
@ -376,7 +432,7 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/hosts.tpl">
<entry file="file://$PROJECT_DIR$/tpl/hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="324">
<caret line="18" column="12" lean-forward="true" selection-start-line="18" selection-start-column="12" selection-end-line="18" selection-end-column="12" />
@ -384,7 +440,7 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="288">
<caret line="16" column="13" lean-forward="true" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
@ -397,7 +453,7 @@
<state relative-caret-position="522">
<caret line="33" column="50" lean-forward="true" selection-start-line="33" selection-start-column="50" selection-end-line="33" selection-end-column="50" />
<folding>
<element signature="e#36#47#0" expanded="true" />
<element signature="e#36#50#0" expanded="true" />
</folding>
</state>
</provider>
@ -408,10 +464,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -421,12 +475,13 @@
<state relative-caret-position="1728">
<caret line="97" column="17" lean-forward="false" selection-start-line="97" selection-start-column="17" selection-end-line="97" selection-end-column="17" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="16" lean-forward="false" selection-start-line="8" selection-start-column="16" selection-end-line="8" selection-end-column="16" />
@ -434,7 +489,7 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/hosts.tpl">
<entry file="file://$PROJECT_DIR$/tpl/hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="468">
<caret line="26" column="34" lean-forward="false" selection-start-line="26" selection-start-column="34" selection-end-line="26" selection-end-column="34" />
@ -448,10 +503,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -461,12 +514,13 @@
<state relative-caret-position="1728">
<caret line="97" column="17" lean-forward="false" selection-start-line="97" selection-start-column="17" selection-end-line="97" selection-end-column="17" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="16" lean-forward="false" selection-start-line="8" selection-start-column="16" selection-end-line="8" selection-end-column="16" />
@ -474,7 +528,7 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/hosts.tpl">
<entry file="file://$PROJECT_DIR$/tpl/hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="468">
<caret line="26" column="34" lean-forward="false" selection-start-line="26" selection-start-column="34" selection-end-line="26" selection-end-column="34" />
@ -488,10 +542,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -501,12 +553,13 @@
<state relative-caret-position="1728">
<caret line="97" column="17" lean-forward="false" selection-start-line="97" selection-start-column="17" selection-end-line="97" selection-end-column="17" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="16" lean-forward="true" selection-start-line="8" selection-start-column="16" selection-end-line="8" selection-end-column="16" />
@ -514,7 +567,7 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/hosts.tpl">
<entry file="file://$PROJECT_DIR$/tpl/hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="468">
<caret line="26" column="34" lean-forward="false" selection-start-line="26" selection-start-column="34" selection-end-line="26" selection-end-column="34" />
@ -528,10 +581,8 @@
<caret line="18" column="7" lean-forward="false" selection-start-line="18" selection-start-column="7" selection-end-line="18" selection-end-column="7" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -541,12 +592,13 @@
<state relative-caret-position="504">
<caret line="28" column="8" lean-forward="false" selection-start-line="28" selection-start-column="8" selection-end-line="28" selection-end-column="8" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="18">
<caret line="1" column="12" lean-forward="false" selection-start-line="1" selection-start-column="12" selection-end-line="1" selection-end-column="12" />
@ -560,10 +612,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -573,7 +623,8 @@
<state relative-caret-position="486">
<caret line="28" column="8" lean-forward="true" selection-start-line="28" selection-start-column="8" selection-end-line="28" selection-end-column="8" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
@ -584,15 +635,13 @@
<caret line="1" column="14" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="1" selection-end-column="14" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="0" lean-forward="false" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
@ -605,7 +654,8 @@
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="true" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
@ -616,15 +666,13 @@
<caret line="1" column="14" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="1" selection-end-column="14" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="0" lean-forward="false" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
@ -637,7 +685,8 @@
<state relative-caret-position="756">
<caret line="43" column="34" lean-forward="false" selection-start-line="43" selection-start-column="34" selection-end-line="43" selection-end-column="34" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
@ -648,10 +697,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -661,7 +708,8 @@
<state relative-caret-position="756">
<caret line="43" column="33" lean-forward="false" selection-start-line="43" selection-start-column="33" selection-end-line="43" selection-end-column="33" />
<folding>
<element signature="e#35#87#0" expanded="true" />
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
@ -672,10 +720,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -686,10 +732,8 @@
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
@ -701,74 +745,90 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config-sample.json">
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="18">
<caret line="1" column="12" lean-forward="true" selection-start-line="1" selection-start-column="12" selection-end-line="1" selection-end-column="12" />
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/.gitignore">
<entry file="file://$PROJECT_DIR$/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<state relative-caret-position="180">
<caret line="10" column="0" lean-forward="false" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/web-leases.py">
<entry file="file://$PROJECT_DIR$/config-sample.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1728">
<caret line="97" column="39" lean-forward="false" selection-start-line="97" selection-start-column="39" selection-end-line="97" selection-end-column="39" />
<folding>
<element signature="e#35#87#0" expanded="true" />
</folding>
<state relative-caret-position="216">
<caret line="12" column="0" lean-forward="true" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config.json">
<entry file="file://$PROJECT_DIR$/tpl/hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="11" column="0" lean-forward="false" selection-start-line="11" selection-start-column="0" selection-end-line="11" selection-end-column="0" />
<state relative-caret-position="180">
<caret line="10" column="44" lean-forward="false" selection-start-line="10" selection-start-column="44" selection-end-line="10" selection-end-column="44" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/kea_hosts_generane.py">
<entry file="file://$PROJECT_DIR$/tpl/main.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="612">
<caret line="57" column="30" lean-forward="false" selection-start-line="57" selection-start-column="30" selection-end-line="57" selection-end-column="30" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#100#246#0" expanded="false" />
<element signature="e#498#592#0" expanded="false" />
<element signature="e#610#1411#0" expanded="false" />
<element signature="e#4821#5607#0" expanded="false" />
</folding>
<state relative-caret-position="180">
<caret line="10" column="44" lean-forward="true" selection-start-line="10" selection-start-column="8" selection-end-line="10" selection-end-column="44" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/hosts.tpl">
<entry file="file://$PROJECT_DIR$/tpl/import_hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="324">
<caret line="18" column="12" lean-forward="false" selection-start-line="18" selection-start-column="12" selection-end-line="18" selection-end-column="12" />
<state relative-caret-position="450">
<caret line="25" column="7" lean-forward="true" selection-start-line="25" selection-start-column="7" selection-end-line="25" selection-end-column="7" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.tpl">
<entry file="file://$PROJECT_DIR$/tpl/remove_hosts.tpl">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="288">
<caret line="16" column="13" lean-forward="false" selection-start-line="16" selection-start-column="13" selection-end-line="16" selection-end-column="13" />
<state relative-caret-position="108">
<caret line="6" column="17" lean-forward="false" selection-start-line="6" selection-start-column="17" selection-end-line="6" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/web-leases.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="450">
<caret line="172" column="24" lean-forward="false" selection-start-line="172" selection-start-column="24" selection-end-line="172" selection-end-column="24" />
<folding>
<element signature="e#35#102#0" expanded="true" />
<element signature="e#3012#4258#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/kea_hosts_generane.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="468">
<caret line="144" column="19" lean-forward="true" selection-start-line="144" selection-start-column="19" selection-end-line="144" selection-end-column="19" />
<folding>
<element signature="e#37#48#0" expanded="true" />
<element signature="e#492#586#0" expanded="false" />
<element signature="e#604#1405#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/kea_host_wacher.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="246">
<caret line="33" column="26" lean-forward="true" selection-start-line="33" selection-start-column="26" selection-end-line="33" selection-end-column="26" />
<state relative-caret-position="-450">
<caret line="15" column="23" lean-forward="true" selection-start-line="15" selection-start-column="23" selection-end-line="15" selection-end-column="23" />
<folding>
<element signature="e#36#47#0" expanded="true" />
<element signature="e#36#50#0" expanded="true" />
</folding>
</state>
</provider>


+ 2
- 1
config-sample.json View File

@ -7,5 +7,6 @@
"dbuser":"kea",
"dbpass":"kea1234",
"dbbase":"dhcp4",
"ippool":["10","210"]
"ippool":["10","210"],
"ttl_min":"1"
}

+ 3
- 9
kea_host_wacher.py View File

@ -1,9 +1,7 @@
#! /usr/bin/python3
# coding=utf-8
import time
import MySQLdb
import json
import datetime
from kea_hosts_generane import read_table, read_conf
@ -45,7 +43,6 @@ def update_seen(sql, id, dbhost, dbuser, dbpass, dbbase):
conn.close()
try:
cur = conn.cursor(MySQLdb.cursors.DictCursor)
print(sql % id)
cur.execute(sql % id)
data = cur.fetchall()
except MySQLdb.Error as err:
@ -78,24 +75,21 @@ def main():
conf = read_conf()
dbconf = [conf['dbhost'], conf['dbuser'], conf['dbpass'], conf['dbbase']]
online_hosts = read_table(qonline, *dbconf)
print(online_hosts)
seen = read_table(qselect_last_seen, *dbconf)
print(seen)
seen_list = []
for seen_h in seen:
seen_list.append(seen_h['id_1c_import'])
print(seen_list)
for online_host in online_hosts:
if online_host['1c_id'] in seen_list:
print('need to update host 1c_id = %s' % online_host['1c_id'])
# print('need to update host 1c_id = %s' % online_host['1c_id'])
update_seen(qupdate_last_seen, online_host['1c_id'], *dbconf)
elif online_host not in seen:
print('need to add host 1c_id = %s' % online_host['1c_id'])
# print('need to add host 1c_id = %s' % online_host['1c_id'])
update_seen(qinsert_last_seen, online_host['1c_id'], *dbconf)
seen = read_table(qselect_last_seen, *dbconf)
for seen_host in seen:
if seen_host['datetime'] < (datetime.datetime.now() - datetime.timedelta(minutes=1)):
print('need to remove host 1c_id = %s' % seen_host['id_1c_import'])
# print('need to remove host 1c_id = %s' % seen_host['id_1c_import'])
update_hosts(qdelete_host, seen_host['id_1c_import'], *dbconf)
update_seen(qdelete_last_seen, seen_host['id_1c_import'], *dbconf)


+ 8
- 6
kea_hosts_generane.py View File

@ -11,7 +11,7 @@ import json
q1c = "SELECT REPLACE(hw_addr, ':','') as hw_addr, " \
"serial, " \
"net_num " \
"FROM dhcp4.1c_import " \
"FROM 1c_import " \
"where imported = 0;"
qleases4 = "SELECT INET_NTOA(address) as ip4, " \
@ -19,7 +19,7 @@ qleases4 = "SELECT INET_NTOA(address) as ip4, " \
"expire, " \
"valid_lifetime " \
"FROM lease4 " \
"where INET_NTOA(address) like '10.%s.0%';"
"where INET_NTOA(address) like '10.{}.0%';"
qhosts_ip = "SELECT " \
"INET_NTOA(ipv4_address) AS ipv4_address " \
@ -66,7 +66,7 @@ def send_data(user, password, name, host):
allow_agent=False) # пытаемся подключиться, look_for_keys=False, allow_agent=False - зачем-то
# нужны циске.
except Exception as exept: # в случае исключения -
errorcode = exept # возвращаем код и описание исключения
print(exept) # возвращаем код и описание исключения
else: # усли все в порядке
conn = client.invoke_shell() # врубаем интерактивный шелл - с цисками только так.
time.sleep(1) # задержка
@ -82,7 +82,7 @@ def send_data(user, password, name, host):
for command in commands: # Читаем и исполняем команды
conn.send(command + '\n') # засылаем команду
time.sleep(0.1) # ждем указанный таймаут
conn.recv(99999999999) # хаваем его в никуда
print(conn.recv(99999999999)) # хаваем его в никуда
else:
print("nothing to do")
finally: # по окончании всех процедур
@ -159,7 +159,8 @@ def make_hosts(sql, ip, hostname, hw_addr, dbhost, dbuser, dbpass, dbbase):
def read_conf():
conf = json.load(open('config.json'))
with open('config.json') as f:
conf = json.load(f)
return conf
@ -167,7 +168,7 @@ def main():
conf = read_conf()
dbconf = [conf['dbhost'], conf['dbuser'], conf['dbpass'], conf['dbbase']]
data_1c = read_table(q1c, *dbconf)
data_leases = read_table(qleases4 % conf['ip_oct2'], *dbconf)
data_leases = read_table(qleases4.format(conf['ip_oct2']), *dbconf)
for line in data_1c:
set_ip = first_free_ip(read_table(qhosts_ip, *dbconf),
@ -180,6 +181,7 @@ def main():
for line in data_1c:
for lease in data_leases:
if line['hw_addr'] == lease['hw_addr']:
print('rebooting %s' % lease['ip4'])
send_data(conf['sshuser'], conf['sshpass'], line['serial'], lease['ip4'])


hosts.tpl → tpl/hosts.tpl View File

@ -7,28 +7,32 @@
<a href="/">отчет по занятым хостам в динамическом адресном пространстве</a>
<h1>Статические адреса</h1>
<br /><br />
<form action="/hosts/" name="add_hosts" method="post">
<input type="submit" value="Submit">
<table border="1">
<caption>Таблица аренды статических адресов </caption>
<tr>
<th>IP адрес</th>
<th>Имя хоста</th>
<th>Mac адрес</th>
<th>адрес арендован</th>
<th>арендован</th>
<th>Освободить <br> адрес</th>
<th>Удалить из <br> импорта</th>
</tr>
%for a in A:
<tr>
%for i in a:
<td>
%if i == '-':
<td><a target="_blank" href="http://{{a[0]}}">{{a[0]}}</a></td>
<td>{{a[1]}}</td>
<td>{{a[2]}}</td>
<td align="center">
%if a[3]== '-':
<font size="5" color="red" face="Arial">-</font>
%elif i == '+':
%elif a[3] == '+':
<font size="5" color="green" face="Arial">+</font>
%elif '10.' in i:
<a target="_blank" href="http://{{i}}">{{i}}</a>
%else:
{{i}}
%end
</td>
<td align="center"><input type="checkbox" name="remove_host" value={{a[2]}} /></td>
<td align="center"><input type="checkbox" name="remove_import" value={{a[2]}} /></td>
%end
</tr>
%end

+ 26
- 0
tpl/import_hosts.tpl View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<head>
<title>DHCP web-viewer</title>
</head>
<html>
<body>
<h1>Таблица импорта обновлена.</h1>
Если устройства не перезагружены автоматически, это необходимо сделать вручную.
<table border="1">
<caption>Добавленные хосты</caption>
<tr>
<th>IP адрес</th>
<th>Mac адрес</th>
<th>Имя хоста</th>
</tr>
%for a in A:
<tr>
<td>{{a[0]}}</td>
<td>{{a[1]}}</td>
<td>{{a[2]}}</td>
%end
</tr>
</table>
<a target="_blank" href="/">Назад</a>
</body>
</html>

main.tpl → tpl/main.tpl View File

@ -7,6 +7,8 @@
<a href="/hosts/">отчет по хостам в статическом адресном пространстве</a>
<h1>Динамические адреса</h1>
<br /><br />
<form action="/" name="add_hosts" method="post">
<input type="submit" value="Submit">
<table border="1">
<caption>Таблица аренды динамических адресов</caption>
<tr>
@ -14,14 +16,24 @@
<th>IP адрес</th>
<th>Mac адрес</th>
<th>Имя хоста</th>
<th>Новое имя</th>
<th>№ сети</th>
<th>Импортировать</th>
</tr>
%i = 0
%for a in A:
%i = i + 1
<tr>
%for i in a:
<td>{{i}}</td>
%end
<td>{{a[0]}}</td>
<td>{{a[1]}}</td>
<td>{{a[2]}}</td>
<td>{{a[3]}}</td>
<td><input type="text" pattern="[A-Za-z0-9]{4,}" name="hostname_{{i}}" size="12"></td>
<td><input type="number" size="3" max="255" value="1" name="hostname_{{i}}"/></td>
<td><input type="checkbox" name="hostname_{{i}}" value="{{a[2]}}" /></td>
%end
</tr>
</table>
</form>
</body>
</html>

+ 11
- 0
tpl/remove_hosts.tpl View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<head>
<title>DHCP web-viewer</title>
</head>
<html>
<body>
<h1>Хосты удалены.</h1>
Если устройства в сети, их нужно перезагрузить вручную.
<a target="_blank" href="/hosts/">Назад</a>
</body>
</html>

+ 115
- 22
web-leases.py View File

@ -1,10 +1,15 @@
#!/usr/bin/python3
# coding=utf-8
from bottle import route, run, static_file, template
from bottle import route, run, static_file, template, post, request
import json
import MySQLdb
HOST = 'localhost'
def read_conf():
with open('config.json') as f:
conf = json.load(f)
return conf
@route('/static/')
@ -14,17 +19,18 @@ def server_static(filepath):
@route('/')
def server_homepage():
dbhost = '10.5.1.248'
dbuser = 'kea'
dbpass = 'kea1234'
dbbase = 'dhcp4'
conf = read_conf()
dbhost = conf['dbhost']
dbuser = conf['dbuser']
dbpass = conf['dbpass']
dbbase = conf['dbbase']
sql = "SELECT " \
" expire, " \
" INET_NTOA(address) as ip4, " \
" HEX(hwaddr)as hw_addr, " \
" hostname " \
" FROM lease4 " \
"where INET_NTOA(address) like '10.5.0%'" \
"where INET_NTOA(address) like '%.%.0.%'" \
" ORDER BY expire DESC;"
try:
conn = MySQLdb.connect(host=dbhost, user=dbuser,
@ -41,21 +47,62 @@ def server_homepage():
conn.close()
data_list = []
for row in data:
temp = []
temp.append(row['expire'])
temp.append(row['ip4'])
temp.append(row['hw_addr'])
temp.append(row['hostname'])
temp = [row['expire'], row['ip4'], row['hw_addr'], row['hostname']]
data_list.append(temp)
return template('main.tpl', A=data_list)
return template('tpl/main.tpl', A=data_list)
@post('/')
def adding_hosts():
conf = read_conf()
dbhost = conf['dbhost']
dbuser = conf['dbuser']
dbpass = conf['dbpass']
dbbase = conf['dbbase']
s_select = "SELECT " \
" expire, " \
" INET_NTOA(address) as ip4, " \
" HEX(hwaddr)as hw_addr, " \
" hostname " \
" FROM lease4 " \
"where INET_NTOA(address) like '10.100.0%'" \
" ORDER BY expire DESC;"
s_insert = "insert into 1c_import (serial, net_num, hw_addr, imported) values ('%s', %s, '%s', 0);"
i = 1
data = []
while request.POST.get("hostname_%s" % i, default=False):
hostname = request.POST.getall('hostname_%s' % i)
print(request.POST.getall('hostname_%s' % i))
if len(hostname) == 3:
data.append(request.POST.getall('hostname_%s' % i))
try:
conn = MySQLdb.connect(host=dbhost, user=dbuser,
passwd=dbpass, db=dbbase)
except MySQLdb.Error as err:
print("Connection error: {}".format(err))
conn.close()
try:
cur = conn.cursor(MySQLdb.cursors.Cursor)
print(s_insert % tuple(hostname))
cur.execute(s_insert % tuple(hostname))
conn.commit()
except MySQLdb.Error as err:
print("Query error: {}".format(err))
conn.close()
i += 1
return template('tpl/import_hosts.tpl', A=data)
@route('/hosts/')
def server_hosts_repo():
dbhost = '10.5.1.248'
dbuser = 'kea'
dbpass = 'kea1234'
dbbase = 'dhcp4'
conf = read_conf()
dbhost = conf['dbhost']
dbuser = conf['dbuser']
dbpass = conf['dbpass']
dbbase = conf['dbbase']
sql = "SELECT " \
"INET_NTOA(hosts.ipv4_address) AS ip4," \
" hosts.hostname," \
@ -67,9 +114,7 @@ def server_hosts_repo():
" lease4" \
" on" \
" dhcp_identifier = hwaddr " \
"ORDER BY ip4;" \
# "where " \
# " INET_NTOA(hosts.ipv4_address) LIKE '10.5.1%';"
"ORDER BY ip4;"
try:
conn = MySQLdb.connect(host=dbhost, user=dbuser,
passwd=dbpass, db=dbbase)
@ -91,8 +136,56 @@ def server_hosts_repo():
temp.append(row['hw_addr'])
temp.append(row['leased'])
data_list.append(temp)
print(data_list)
return template('hosts.tpl', A=data_list)
return template('tpl/hosts.tpl', A=data_list)
@post('/hosts/')
def remove_host():
conf = read_conf()
dbhost = conf['dbhost']
dbuser = conf['dbuser']
dbpass = conf['dbpass']
dbbase = conf['dbbase']
s_remove1c = "delete from 1c_import where replace(hw_addr, ':', '') = '%s';"
s_removehost = "delete from hosts where dhcp_identifier = unhex('%s');"
hosts_del = request.forms.getall('remove_host')
del_1c = request.forms.getall('remove_import')
try:
conn = MySQLdb.connect(host=dbhost, user=dbuser,
passwd=dbpass, db=dbbase)
except MySQLdb.Error as err:
print("Connection error: {}".format(err))
conn.close()
try:
cur = conn.cursor(MySQLdb.cursors.Cursor)
for host in hosts_del:
try:
cur.execute(s_removehost % host)
conn.commit()
except MySQLdb.Error as err:
print("Query error: {}".format(err))
print(s_removehost % host)
for host in del_1c:
try:
cur.execute(s_removehost % host)
conn.commit()
except MySQLdb.Error as err:
print("Query error: {}".format(err))
try:
cur.execute(s_remove1c % host)
conn.commit()
except MySQLdb.Error as err:
print("Query error: {}".format(err))
print(s_remove1c % host)
conn.commit()
conn.close()
except MySQLdb.Error as err:
print("Query error: {}".format(err))
conn.close()
print(request.forms.getall('remove_host'))
print(request.forms.getall('remove_import'))
return template('tpl/remove_hosts.tpl')
run(host='0.0.0.0', port=8080, debug=True)

Loading…
Cancel
Save

Powered by TurnKey Linux.