Public
Edited
Nov 28, 2022
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hello = `:put "hello world"`
Insert cell
// this function (defined at bottom of notebook) tell webcode.run to serve the contents of the `hello` cell via the URL in green above
Hello = exportRsc('hello', hello)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Hello2 = exportRsc("hello2", `:put "${inputHello2}"`)
Insert cell
Insert cell
Insert cell
Insert cell
rscOWC = `
:global ${owcCommandName}
:set ${owcCommandName} do={
:if ([:typeof $1]="nothing") do={
# take note that in both RSC a plain needs to be escaped: "\$", on the RouterOS side
:error "\$${owcCommandName}: name of exported code to load is required - \$${owcCommandName} <name_to_import>"
}
:local rsc [/tool fetch url="https://webcode.run/observablehq.com${(new URL(document.baseURI)).pathname};$1" as-value output="user"]
:return [[:parse "$($rsc->"data")"]]
}
`
Insert cell
Insert cell
Insert cell
OWC = exportRsc(owcCommandName, rscOWC)
Insert cell
Insert cell
oneLineBootstrap = rscOneLineLoader(OWC)
Insert cell
Insert cell
Insert cell
viewof elvStartVlanId = Inputs.number([1,4094], {label: "Starting VLAN ID", value: 1001})
Insert cell
viewof elvEndVlanId = Inputs.number([1,4094], {label: "Ending VLAN ID", value: 1002})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
elvIpRange = (vlanid) => [172, (vlanid >> 8) + 16, vlanid & 0xFF]
Insert cell
Insert cell
elvComment = `#${owcCommandName}-exvlan`
Insert cell
Insert cell
function rscSingleVlanCreate(vlanid) {
return `
# VLAN id=${vlanid} interface=${elvVlanListenOn} name="vlan${vlanid}"
{
:local ipoctet [:toarray "${elvIpRange(vlanid)}"]
:local name "vlan${vlanid}"
/interface vlan
add interface=${elvVlanListenOn} name=$name vlan-id=${vlanid} comment="${elvComment}"
/ip address
add address="$($ipoctet->0).$($ipoctet->1).$($ipoctet->2).1/24" interface=$name comment="${elvComment}"
/
}
`}
Insert cell
Insert cell
rscSingleVlanCreate(101)
Insert cell
Insert cell
function rscManyVlans() {
let rsc = "{"
for (let vid = elvStartVlanId; vid <= elvEndVlanId; vid++ ) {
rsc += rscSingleVlanCreate(vid)
}
rsc += "}"
return rsc
}
Insert cell
Insert cell
function rscRemoveVlans() {
return `{
/interface vlan remove [find comment~"${elvComment}"]
/ip address remove [find comment~"${elvComment}"]
}`
}
Insert cell
Insert cell
Insert cell
rscElvCallableArray = `
:global ELV
:set ELV [:toarray ""]
:set ($ELV->"make") do=${rscManyVlans()}
:set ($ELV->"kill") do=${rscRemoveVlans()}
:set ($ELV->"show") do={
/ip address print where comment~"${elvComment}"
/interface vlan print where comment~"${elvComment}"
}

# and to use them at the Mikrotik terminal:
#[admin@Mikrotik]> $${owcCommandName} ELV
#[admin@Mikrotik]> ($ELV->"make")
#[admin@Mikrotik]> ($ELV->"show")
#[admin@Mikrotik]> ($ELV->"kill")

`
Insert cell
Insert cell
// "ELV" == "Everyone Loves VLANs"
exportRsc(elvName, rscElvCallableArray)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// load the webcode.run runtime need to server the cells as plain text
import {endpoint, getContext} from '@endpointservices/webcode'
Insert cell
Insert cell
function exportRsc(name, code) {
return endpoint(name, async (request, response) => {
response.send(`${code}`);
})
}
Insert cell
Insert cell
rscOneLineLoader = (webcodeEndpoint) => `[:parse "$([/tool/fetch url="${webcodeEndpoint.value.href}" as-value output="user"]->"data")"]`
Insert cell
mename = `${(new URL(document.baseURI)).pathname.substr(1)}`
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more