can get device id
This commit is contained in:
parent
3c0eece311
commit
3d90ed0708
3
.env
3
.env
|
@ -2,6 +2,3 @@ SYNCTHING_VERSION=latest
|
|||
PUID=1001
|
||||
PGID=1001
|
||||
TZ=Europe/London
|
||||
SYNC_LISTEN_PORT=22000
|
||||
SYNC1_LISTEN_PORT=22100
|
||||
SYNC2_LISTEN_PORT=22101
|
||||
|
|
|
@ -8,15 +8,19 @@ services:
|
|||
- sync1
|
||||
- sync2
|
||||
volumes:
|
||||
- sync1data:/data1
|
||||
- sync2data:/data2
|
||||
- sync1data:/data1
|
||||
- sync2data:/data2
|
||||
networks:
|
||||
- syncnet
|
||||
|
||||
sut1:
|
||||
build: .
|
||||
links:
|
||||
- sync1
|
||||
- sync1:sync
|
||||
volumes:
|
||||
- sync1config:/config:ro
|
||||
- sync1config:/config
|
||||
networks:
|
||||
- syncnet
|
||||
|
||||
sync1:
|
||||
image: ghcr.io/linuxserver/syncthing:${SYNCTHING_VERSION}
|
||||
|
@ -27,15 +31,17 @@ services:
|
|||
volumes:
|
||||
- sync1config:/config
|
||||
- sync1data:/data
|
||||
ports:
|
||||
- ${SYNC1_LISTEN_PORT}:22000
|
||||
networks:
|
||||
- syncnet
|
||||
|
||||
sut2:
|
||||
build: .
|
||||
links:
|
||||
- sync2
|
||||
- sync2:sync
|
||||
volumes:
|
||||
- sync2config:/config:ro
|
||||
- sync2config:/config
|
||||
networks:
|
||||
- syncnet
|
||||
|
||||
sync2:
|
||||
image: ghcr.io/linuxserver/syncthing:${SYNCTHING_VERSION}
|
||||
|
@ -46,17 +52,16 @@ services:
|
|||
volumes:
|
||||
- sync2config:/config
|
||||
- sync2data:/data
|
||||
ports:
|
||||
- ${SYNC2_LISTEN_PORT}:22000
|
||||
networks:
|
||||
- syncnet
|
||||
|
||||
etcd:
|
||||
image: quay.io/coreos/etcd
|
||||
command: /usr/local/bin/etcd --data-dir=/etcd-data
|
||||
ports:
|
||||
- 2379:2379
|
||||
- 2380:2380
|
||||
volumes:
|
||||
- etcd-data:/etcd-data
|
||||
- etcd-data:/etcd-data
|
||||
networks:
|
||||
- syncnet
|
||||
|
||||
volumes:
|
||||
sync1data:
|
||||
|
@ -64,3 +69,6 @@ volumes:
|
|||
sync2data:
|
||||
sync2config:
|
||||
etcd-data:
|
||||
|
||||
networks:
|
||||
syncnet:
|
|
@ -0,0 +1,2 @@
|
|||
retrying
|
||||
requests
|
|
@ -1,10 +1,17 @@
|
|||
from syncthing_monitor.config_xml import parse_api_key
|
||||
from syncthing_monitor.config_xml import parse_api_key, set_listen_ip_to_any
|
||||
from syncthing_monitor.syncthing_rest import get_device_id
|
||||
|
||||
|
||||
def loop():
|
||||
def loop(gui_port="8384", host="sync"):
|
||||
|
||||
api_key = parse_api_key()
|
||||
print("Found API Key: {0}".format(api_key))
|
||||
|
||||
set_listen_ip_to_any()
|
||||
|
||||
device_id = get_device_id(host, gui_port, api_key)
|
||||
print("Found Device ID: {0}".format(device_id))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
loop()
|
||||
|
|
|
@ -8,3 +8,13 @@ def parse_api_key(xml_path='/config/config.xml'):
|
|||
# noinspection SpellCheckingInspection
|
||||
api_key = gui.find('apikey').text
|
||||
return api_key
|
||||
|
||||
|
||||
def set_listen_ip_to_any(in_xml_path='/config/config.xml', out_xml_path='/config/config.xml', gui_port='8384'):
|
||||
with open(in_xml_path, 'r') as file:
|
||||
xml = file.read()
|
||||
|
||||
xml = xml.replace("127.0.0.1:8384", "0.0.0.0:"+gui_port)
|
||||
|
||||
with open(out_xml_path, 'w') as file:
|
||||
file.write(xml)
|
||||
|
|
11
syncthing_monitor/syncthing_rest.py
Normal file
11
syncthing_monitor/syncthing_rest.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import json
|
||||
|
||||
import requests
|
||||
from retrying import retry
|
||||
|
||||
|
||||
@retry
|
||||
def get_device_id(host, gui_port, api_key):
|
||||
syncthing_headers = {'X-API-Key': api_key}
|
||||
response = requests.get("http://" + host + ":" + gui_port + "/rest/system/status", headers=syncthing_headers)
|
||||
return json.loads(response.content)["myID"]
|
114
test/test-syncthing-config-any-ip.xml
Normal file
114
test/test-syncthing-config-any-ip.xml
Normal file
|
@ -0,0 +1,114 @@
|
|||
<configuration version="32">
|
||||
<folder id="data" label="Data" path="/data" type="sendreceive" rescanIntervalS="3600" fsWatcherEnabled="true" fsWatcherDelayS="10" ignorePerms="false" autoNormalize="true">
|
||||
<filesystemType>basic</filesystemType>
|
||||
<device id="MKXXCDW-3YWBXU4-PWJZU5P-VFOPIMT-22L7BAY-7GZY4I5-TQMLIYY-JSILEQC" introducedBy="">
|
||||
<encryptionPassword></encryptionPassword>
|
||||
</device>
|
||||
<device id="OSRS6BZ-WRXI67N-55XSQSH-X64E4CL-52D7BGZ-7X2CPEX-OMUZ42H-F52URAI" introducedBy="">
|
||||
<encryptionPassword></encryptionPassword>
|
||||
</device>
|
||||
<minDiskFree unit="%">1</minDiskFree>
|
||||
<versioning>
|
||||
<cleanupIntervalS>0</cleanupIntervalS>
|
||||
</versioning>
|
||||
<copiers>0</copiers>
|
||||
<pullerMaxPendingKiB>0</pullerMaxPendingKiB>
|
||||
<hashers>0</hashers>
|
||||
<order>random</order>
|
||||
<ignoreDelete>false</ignoreDelete>
|
||||
<scanProgressIntervalS>0</scanProgressIntervalS>
|
||||
<pullerPauseS>0</pullerPauseS>
|
||||
<maxConflicts>10</maxConflicts>
|
||||
<disableSparseFiles>false</disableSparseFiles>
|
||||
<disableTempIndexes>false</disableTempIndexes>
|
||||
<paused>false</paused>
|
||||
<weakHashThresholdPct>25</weakHashThresholdPct>
|
||||
<markerName>.stfolder</markerName>
|
||||
<copyOwnershipFromParent>false</copyOwnershipFromParent>
|
||||
<modTimeWindowS>0</modTimeWindowS>
|
||||
<maxConcurrentWrites>2</maxConcurrentWrites>
|
||||
<disableFsync>false</disableFsync>
|
||||
<blockPullOrder>standard</blockPullOrder>
|
||||
<copyRangeMethod>standard</copyRangeMethod>
|
||||
<caseSensitiveFS>false</caseSensitiveFS>
|
||||
<junctionsAsDirs>false</junctionsAsDirs>
|
||||
</folder>
|
||||
<device id="MKXXCDW-3YWBXU4-PWJZU5P-VFOPIMT-22L7BAY-7GZY4I5-TQMLIYY-JSILEQC" name="honeydew" compression="metadata" introducer="false" skipIntroductionRemovals="false" introducedBy="">
|
||||
<address>dynamic</address>
|
||||
<paused>false</paused>
|
||||
<allowedNetwork>10.122.122.0/24</allowedNetwork>
|
||||
<autoAcceptFolders>false</autoAcceptFolders>
|
||||
<maxSendKbps>0</maxSendKbps>
|
||||
<maxRecvKbps>0</maxRecvKbps>
|
||||
<maxRequestKiB>0</maxRequestKiB>
|
||||
<untrusted>false</untrusted>
|
||||
<remoteGUIPort>0</remoteGUIPort>
|
||||
</device>
|
||||
<device id="OSRS6BZ-WRXI67N-55XSQSH-X64E4CL-52D7BGZ-7X2CPEX-OMUZ42H-F52URAI" name="blackberry" compression="metadata" introducer="false" skipIntroductionRemovals="false" introducedBy="">
|
||||
<address>tcp://blackberry</address>
|
||||
<paused>false</paused>
|
||||
<allowedNetwork>10.122.122.0/24</allowedNetwork>
|
||||
<autoAcceptFolders>false</autoAcceptFolders>
|
||||
<maxSendKbps>0</maxSendKbps>
|
||||
<maxRecvKbps>0</maxRecvKbps>
|
||||
<maxRequestKiB>0</maxRequestKiB>
|
||||
<untrusted>false</untrusted>
|
||||
<remoteGUIPort>0</remoteGUIPort>
|
||||
</device>
|
||||
<gui enabled="true" tls="false" debugging="true">
|
||||
<address>0.0.0.0:8384</address>
|
||||
<user>syncadmin</user>
|
||||
<password>$2a$10$.nzDwmF2w9gWfPFWto1wmOOek4RzEF/MlolVyzOLsOCXL733IleVC</password>
|
||||
<apikey>dFoLNEaqEZFSP62EFVGC2Ds5juuTmvH2</apikey>
|
||||
<theme>default</theme>
|
||||
</gui>
|
||||
<ldap></ldap>
|
||||
<options>
|
||||
<listenAddress>default</listenAddress>
|
||||
<globalAnnounceServer>default</globalAnnounceServer>
|
||||
<globalAnnounceEnabled>false</globalAnnounceEnabled>
|
||||
<localAnnounceEnabled>false</localAnnounceEnabled>
|
||||
<localAnnouncePort>21027</localAnnouncePort>
|
||||
<localAnnounceMCAddr>[ff12::8384]:21027</localAnnounceMCAddr>
|
||||
<maxSendKbps>0</maxSendKbps>
|
||||
<maxRecvKbps>0</maxRecvKbps>
|
||||
<reconnectionIntervalS>60</reconnectionIntervalS>
|
||||
<relaysEnabled>false</relaysEnabled>
|
||||
<relayReconnectIntervalM>10</relayReconnectIntervalM>
|
||||
<startBrowser>true</startBrowser>
|
||||
<natEnabled>false</natEnabled>
|
||||
<natLeaseMinutes>60</natLeaseMinutes>
|
||||
<natRenewalMinutes>30</natRenewalMinutes>
|
||||
<natTimeoutSeconds>10</natTimeoutSeconds>
|
||||
<urAccepted>-1</urAccepted>
|
||||
<urSeen>3</urSeen>
|
||||
<urUniqueID></urUniqueID>
|
||||
<urURL>https://data.syncthing.net/newdata</urURL>
|
||||
<urPostInsecurely>false</urPostInsecurely>
|
||||
<urInitialDelayS>1800</urInitialDelayS>
|
||||
<restartOnWakeup>true</restartOnWakeup>
|
||||
<autoUpgradeIntervalH>12</autoUpgradeIntervalH>
|
||||
<upgradeToPreReleases>false</upgradeToPreReleases>
|
||||
<keepTemporariesH>24</keepTemporariesH>
|
||||
<cacheIgnoredFiles>false</cacheIgnoredFiles>
|
||||
<progressUpdateIntervalS>5</progressUpdateIntervalS>
|
||||
<limitBandwidthInLan>false</limitBandwidthInLan>
|
||||
<minHomeDiskFree unit="%">1</minHomeDiskFree>
|
||||
<releasesURL>https://upgrades.syncthing.net/meta.json</releasesURL>
|
||||
<overwriteRemoteDeviceNamesOnConnect>false</overwriteRemoteDeviceNamesOnConnect>
|
||||
<tempIndexMinBlocks>10</tempIndexMinBlocks>
|
||||
<trafficClass>0</trafficClass>
|
||||
<defaultFolderPath>~</defaultFolderPath>
|
||||
<setLowPriority>true</setLowPriority>
|
||||
<maxFolderConcurrency>0</maxFolderConcurrency>
|
||||
<crashReportingURL>https://crash.syncthing.net/newcrash</crashReportingURL>
|
||||
<crashReportingEnabled>false</crashReportingEnabled>
|
||||
<stunKeepaliveStartS>180</stunKeepaliveStartS>
|
||||
<stunKeepaliveMinS>20</stunKeepaliveMinS>
|
||||
<stunServer>default</stunServer>
|
||||
<databaseTuning>auto</databaseTuning>
|
||||
<maxConcurrentIncomingRequestKiB>0</maxConcurrentIncomingRequestKiB>
|
||||
<announceLANAddresses>false</announceLANAddresses>
|
||||
<sendFullIndexOnUpgrade>false</sendFullIndexOnUpgrade>
|
||||
</options>
|
||||
</configuration>
|
|
@ -1,10 +1,35 @@
|
|||
import io
|
||||
import os
|
||||
import unittest
|
||||
from os import path
|
||||
|
||||
from syncthing_monitor.config_xml import parse_api_key
|
||||
from syncthing_monitor.config_xml import parse_api_key, set_listen_ip_to_any
|
||||
|
||||
SYNCTHING_TEST_CONFIG_XML = 'test/test-syncthing-config.xml'
|
||||
|
||||
EXPECTED_API_KEY = "dFoLNEaqEZFSP62EFVGC2Ds5juuTmvH2"
|
||||
SYNCTHING_EXPECTED_ANY_IP_CONFIG_XML = 'test/test-syncthing-config-any-ip.xml'
|
||||
|
||||
TEST_OUT_XML = 'test/out.xml'
|
||||
|
||||
|
||||
def read_file(filename=TEST_OUT_XML):
|
||||
with open(filename, 'r') as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
class ConfigTests(unittest.TestCase):
|
||||
|
||||
def test_can_parse_api_key(self):
|
||||
# noinspection SpellCheckingInspection
|
||||
self.assertEqual(parse_api_key('test/test-syncthing-config.xml'), "dFoLNEaqEZFSP62EFVGC2Ds5juuTmvH2")
|
||||
self.assertEqual(parse_api_key(SYNCTHING_TEST_CONFIG_XML), EXPECTED_API_KEY)
|
||||
|
||||
def test_can_set_listen_ip_to_any(self):
|
||||
set_listen_ip_to_any(SYNCTHING_TEST_CONFIG_XML, TEST_OUT_XML)
|
||||
self.assertListEqual(
|
||||
list(io.open(TEST_OUT_XML)),
|
||||
list(io.open(SYNCTHING_EXPECTED_ANY_IP_CONFIG_XML)))
|
||||
|
||||
def tearDown(self):
|
||||
if path.exists(TEST_OUT_XML):
|
||||
os.remove(TEST_OUT_XML)
|
||||
|
|
Loading…
Reference in New Issue
Block a user