-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update setup script and add comments
- Loading branch information
1 parent
a465c05
commit ecfd4ee
Showing
1 changed file
with
29 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,51 @@ | ||
import routeros_api | ||
import os | ||
|
||
|
||
def main(): | ||
user = os.environ.get("ROS_USERNAME") | ||
pswd = os.environ.get("ROS_PASSWORD") | ||
ip_addr = os.environ.get("ROS_IP_ADDRESS") | ||
|
||
connection = routeros_api.RouterOsApiPool(ip_addr, username=user, password=pswd, port=8728, plaintext_login=True) | ||
connection = routeros_api.RouterOsApiPool( | ||
ip_addr, username=user, password=pswd, port=8728, plaintext_login=True) | ||
api = connection.get_api() | ||
|
||
# Set up bridge | ||
|
||
bridge = api.get_resource("/interface/bridge") | ||
bridge.add(name="bridge") | ||
|
||
# Set up certificates to allow use of REST API | ||
|
||
certificate = api.get_resource("/certificate") | ||
certificate.add(name="root-cert", common_name="MyRouter", days_valid="3650", key_usage="key-cert-sign,crl-sign") | ||
certificate.add(name="https-cert", common_name="MyRouter", days_valid="3650") | ||
certificate.add(name="root-cert", common_name="MyRouter", | ||
days_valid="3650", key_usage="key-cert-sign,crl-sign") | ||
certificate.add(name="https-cert", | ||
common_name="MyRouter", days_valid="3650") | ||
certs = certificate.get() | ||
root_cert_id = [x['id'] for x in certs if x['name'] == "root-cert"][0] | ||
http_cert_id = [x['id'] for x in certs if x['name'] == "https-cert"][0] | ||
api.get_binary_resource("/").call("certificate/sign", {"id": bytes(root_cert_id, "utf-8")}) | ||
api.get_binary_resource("/").call("certificate/sign", {"id": bytes(http_cert_id, "utf-8"), "ca": b"root-cert"}) | ||
api.get_binary_resource("/").call("certificate/sign", | ||
{"id": bytes(root_cert_id, "utf-8")}) | ||
api.get_binary_resource("/").call("certificate/sign", | ||
{"id": bytes(http_cert_id, "utf-8"), "ca": b"root-cert"}) | ||
ip_service = api.get_resource("/ip/service") | ||
services = ip_service.get() | ||
www_ssl_service_id = [x['id'] for x in services if x['name'] == 'www-ssl'][0] | ||
ip_service.set(id=www_ssl_service_id, certificate="https-cert", disabled="false") | ||
www_ssl_service_id = [x['id'] | ||
for x in services if x['name'] == 'www-ssl'][0] | ||
ip_service.set(id=www_ssl_service_id, | ||
certificate="https-cert", disabled="false") | ||
|
||
# Create a DHCP pool | ||
|
||
pools = api.get_resource("/ip/pool") | ||
pools.add(name="dhcp", ranges="192.168.88.100-192.168.88.200") | ||
|
||
# Output the list of interfaces | ||
|
||
print(api.get_resource("/interface").get()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
main() |