Skip to content

Commit

Permalink
Make PHP Scripts raw strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Snuffy2 committed Sep 2, 2024
1 parent 69154e4 commit c0e8064
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions custom_components/opnsense/pyopnsense/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _restore_config_section(self, section_name, data):

@_apply_timeout
def _exec_php(self, script):
script = """
script = r"""
ini_set('display_errors', 0);
{}
Expand Down Expand Up @@ -184,7 +184,7 @@ def _post(self, path, payload=None):

@_log_errors
def _is_subsystem_dirty(self, subsystem):
script = """
script = r"""
$data = json_decode('{}', true);
$subsystem = $data["subsystem"];
$dirty = is_subsystem_dirty($subsystem);
Expand All @@ -200,7 +200,7 @@ def _is_subsystem_dirty(self, subsystem):

@_log_errors
def _mark_subsystem_dirty(self, subsystem):
script = """
script = r"""
$data = json_decode('{}', true);
$subsystem = $data["subsystem"];
mark_subsystem_dirty($subsystem);
Expand All @@ -211,7 +211,7 @@ def _mark_subsystem_dirty(self, subsystem):

@_log_errors
def _clear_subsystem_dirty(self, subsystem):
script = """
script = r"""
$data = json_decode('{}', true);
$subsystem = $data["subsystem"];
clear_subsystem_dirty($subsystem);
Expand All @@ -222,7 +222,7 @@ def _clear_subsystem_dirty(self, subsystem):

@_log_errors
def _filter_configure(self):
script = """
script = r"""
filter_configure();
clear_subsystem_dirty('natconf');
clear_subsystem_dirty('filter');
Expand All @@ -231,7 +231,7 @@ def _filter_configure(self):

@_log_errors
def get_device_id(self):
script = """
script = r"""
$file = "/conf/hassid";
$id;
if (!file_exists($file)) {
Expand All @@ -250,7 +250,7 @@ def get_device_id(self):
@_log_errors
def get_system_info(self):
# TODO: add bios details here
script = """
script = r"""
global $config;
$file = "/conf/hassid";
Expand Down Expand Up @@ -356,7 +356,7 @@ def firmware_changelog(self, version):

@_log_errors
def get_config(self):
script = """
script = r"""
global $config;
$toreturn = [
Expand Down Expand Up @@ -487,7 +487,7 @@ def disable_nat_outbound_rule_by_created_time(self, created_time):

@_log_errors
def get_configured_interface_descriptions(self):
script = """
script = r"""
$toreturn = [
"data" => get_configured_interface_with_descr(),
];
Expand All @@ -498,7 +498,7 @@ def get_configured_interface_descriptions(self):
@_log_errors
def get_gateways(self):
# {'GW_WAN': {'interface': '<if>', 'gateway': '<ip>', 'name': 'GW_WAN', 'weight': '1', 'ipprotocol': 'inet', 'interval': '', 'descr': 'Interface wan Gateway', 'monitor': '<ip>', 'friendlyiface': 'wan', 'friendlyifdescr': 'WAN', 'isdefaultgw': True, 'attribute': 0, 'tiername': 'Default (IPv4)'}}
script = """
script = r"""
$gateways = new \OPNsense\Routing\Gateways(legacy_interfaces_details());
//$default_gwv4 = $gateways->getDefaultGW(return_down_gateways(), "inet");
//$default_gwv6 = $gateways->getDefaultGW(return_down_gateways(), "inet6");
Expand Down Expand Up @@ -528,7 +528,7 @@ def get_gateway(self, gateway):
@_log_errors
def get_gateways_status(self):
# {'GW_WAN': {'monitorip': '<ip>', 'srcip': '<ip>', 'name': 'GW_WAN', 'delay': '0.387ms', 'stddev': '0.097ms', 'loss': '0.0%', 'status': 'online', 'substatus': 'none'}}
script = """
script = r"""
$toreturn = [
// function return_gateways_status($byname = false, $gways = false)
"data" => return_gateways_status(true),
Expand All @@ -553,7 +553,7 @@ def get_gateway_status(self, gateway):
@_log_errors
def get_arp_table(self, resolve_hostnames=False):
# [{'hostname': '?', 'ip-address': '<ip>', 'mac-address': '<mac>', 'interface': 'em0', 'expires': 1199, 'type': 'ethernet'}, ...]
script = """
script = r"""
$data = json_decode('{}', true);
$resolve_hostnames = $data["resolve_hostnames"];
Expand Down Expand Up @@ -629,7 +629,7 @@ def get_dhcp_leases(self):
# function system_get_dhcpleases()
# {'lease': [], 'failover': []}
# {"lease":[{"ip":"<ip>","type":"static","mac":"<mac>","if":"lan","starts":"","ends":"","hostname":"<hostname>","descr":"","act":"static","online":"online","staticmap_array_index":48} ...
script = """
script = r"""
require_once '/usr/local/etc/inc/plugins.inc.d/dhcpd.inc';
$toreturn = [
Expand All @@ -641,7 +641,7 @@ def get_dhcp_leases(self):

@_log_errors
def get_virtual_ips(self):
script = """
script = r"""
global $config;
$vips = [];
Expand All @@ -663,7 +663,7 @@ def get_carp_status(self):
# carp enabled or not
# readonly attribute, cannot be set directly
# function get_carp_status()
script = """
script = r"""
function get_carp_status() {
/* grab the current status of carp */
$status = get_single_sysctl('net.inet.carp.allow');
Expand All @@ -679,7 +679,7 @@ def get_carp_status(self):

@_log_errors
def get_carp_interfaces(self):
script = """
script = r"""
global $config;
$vips = [];
Expand Down Expand Up @@ -716,7 +716,7 @@ def get_carp_interfaces(self):
def delete_arp_entry(self, ip):
if len(ip) < 1:
return
script = """
script = r"""
$data = json_decode('{}', true);
$ip = trim($data["ip"]);
$ret = mwexec("arp -d " . $ip, true);
Expand All @@ -735,7 +735,7 @@ def delete_arp_entry(self, ip):
@_log_errors
def arp_get_mac_by_ip(self, ip, do_ping=True):
"""function arp_get_mac_by_ip($ip, $do_ping = true)"""
script = """
script = r"""
$data = json_decode('{}', true);
$ip = $data["ip"];
$do_ping = $data["do_ping"];
Expand Down Expand Up @@ -782,7 +782,7 @@ def arp_get_mac_by_ip(self, ip, do_ping=True):

@_log_errors
def system_reboot(self):
script = """
script = r"""
// /usr/local/opnsense/mvc/app/library/OPNsense/Core/Backend.php
use OPNsense\Core\Backend;
Expand All @@ -801,7 +801,7 @@ def system_reboot(self):

@_log_errors
def system_halt(self):
script = """
script = r"""
use OPNsense\Core\Backend;
$backend = new Backend();
Expand All @@ -823,7 +823,7 @@ def send_wol(self, interface, mac):
interface should be wan, lan, opt1, opt2 etc, not the description
"""

script = """
script = r"""
$data = json_decode('{}', true);
$if = $data["interface"];
$mac = $data["mac"];
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def _get_telemetry_gateways(self) -> dict:

@_log_errors
def are_notices_pending(self):
script = """
script = r"""
if (file_exists('/usr/local/etc/inc/notices.inc')) {
require_once '/usr/local/etc/inc/notices.inc';
Expand All @@ -1177,7 +1177,7 @@ def are_notices_pending(self):

@_log_errors
def get_notices(self):
script = """
script = r"""
if (file_exists('/usr/local/etc/inc/notices.inc')) {
require_once '/usr/local/etc/inc/notices.inc';
Expand Down Expand Up @@ -1219,7 +1219,7 @@ def get_notices(self):

@_log_errors
def file_notice(self, notice):
script = """
script = r"""
$data = json_decode('{}', true);
$notice = $data["notice"];
Expand Down Expand Up @@ -1250,7 +1250,7 @@ def close_notice(self, id):
"""
id = "all" to wipe everything
"""
script = """
script = r"""
$data = json_decode('{}', true);
$id = $data["id"];
Expand Down

0 comments on commit c0e8064

Please sign in to comment.