Skip to content

Commit

Permalink
Merge pull request #310 from doktornotor/patch-8
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgarga committed Feb 22, 2017
2 parents b756d91 + ca49255 commit 35a0d64
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 74 deletions.
2 changes: 1 addition & 1 deletion net/pfSense-pkg-cellular/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-cellular
PORTVERSION= 1.1.3
PORTVERSION= 1.1.4
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
5 changes: 2 additions & 3 deletions net/pfSense-pkg-cellular/files/etc/inc/priv/cellular.priv.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* cellular.priv.inc
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate)
* Copyright (C) 2016 Voleatech GmbH, Fabian Schweinfurth
* All rights reserved.
*
Expand All @@ -23,13 +24,11 @@ global $priv_list;

$priv_list['page-services-lteinterface'] = array();
$priv_list['page-services-lteinterface']['name'] = "WebCfg - Status: Cellular Data module package";
$priv_list['page-services-lteinterface']['descr'] = "GUI package for Cellular Cards";
$priv_list['page-services-lteinterface']['descr'] = "Allow access to Cellular package GUI";

$priv_list['page-services-lteinterface']['match'] = array();
$priv_list['page-services-lteinterface']['match'][] = "pkg.php?xml=cellular.xml*";

$priv_list['page-services-lteinterface']['match'][] = "pkg_edit.php?xml=cellular.xml*";

$priv_list['page-services-lteinterface']['match'][] = "widgets/widgets/cellular.widget.php*";

?>
69 changes: 40 additions & 29 deletions net/pfSense-pkg-cellular/files/usr/local/pkg/cellular.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* cellular.inc
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate)
* Copyright (C) 2016 Voleatech GmbH, Fabian Schweinfurth
* All rights reserved.
*
Expand All @@ -19,25 +20,23 @@
* limitations under the License.
*/

$shortcut_section = "cellular";
require_once("globals.inc");
require_once("config.inc");
require_once("util.inc");
require_once("pfsense-utils.inc");
require_once("pkg-utils.inc");
require_once("service-utils.inc");
require_once("notices.inc");

function cellular_sync() {
require_once("util.inc");

global $config;
$shortcut_section = "cellular";

$python_bin = '/usr/local/bin/python2.7';
$interface_bin = '/usr/local/sbin/cellular';
define('PYTHON_BIN', '/usr/local/bin/python2.7');
define('INTERFACE_BIN', '/usr/local/sbin/cellular');

// exec("$python_bin $interface_bin signal", $sig);
$cellular = $config['installedpackages']['cellular']['config'][0];
function cellular_sync() {
global $config;

if (is_array($config['installedpackages']['cellular']['config'][0])) {
$cellular = $config['installedpackages']['cellular']['config'][0];
} else {
$cellular = array();
}
$device = "";
$vtp = $cellular["port"];

Expand All @@ -49,19 +48,19 @@ function cellular_sync() {
$vtbr = $cellular["baudrate"];

if (isset($vtbr) && $vtbr != "default") {
$baudrate = "-b ".$vtbr;
$baudrate = "-b " . $vtbr;
}

$timeout = "";
$vtto = $cellular["timeout"];

if (isset($vtto) && $vtto != "default" && $vtto != "") {
$timeout = "-t ".$vtto;
$timeout = "-t " . $vtto;
}

foreach (["port", "baudrate", "timeout", "initstring"] as $key) {
$key_val = ($cellular[$key] != "default" && $cellular[$key] != "") ? $cellular[$key] : "";
exec("$python_bin $interface_bin $device $baudrate $timeout setcfg Interface $key $key_val");
exec(PYTHON_BIN . ' ' . INTERFACE_BIN . ' $device $baudrate $timeout setcfg Interface $key $key_val signal');
}
}

Expand Down Expand Up @@ -91,28 +90,23 @@ function get_baudrates() {
}

function cellular_before_everything() {

/// little workaround for dynamic field (content) generation
global $pkg;
global $config;

$cellular = $config['installedpackages']['cellular']['config'][0];
if (is_array($config['installedpackages']['cellular']['config'][0])) {
$cellular = $config['installedpackages']['cellular']['config'][0];
} else {
$cellular = array();
}

// little workaround for dynamic field (content) generation
if (isset($pkg) && array_key_exists('fields', $pkg)) {

$python_bin = '/usr/local/bin/python2.7';
$interface_bin = '/usr/local/sbin/cellular';
$custom_str = $cellular["statuscmd"] ?: "I; +CSQ; +COPS?; +CGPADDR";

$custom_str = "I; +CSQ; +COPS?; +CGPADDR";

if (isset($cellular["statuscmd"]) && $cellular["statuscmd"] != "") {
$custom_str = $cellular["statuscmd"];
}

exec("$python_bin $interface_bin custom '" . $custom_str . "' -v", $sig);
exec(PYTHON_BIN . ' ' . INTERFACE_BIN . " custom " . escapeshellarg($custom_str) . " -v", $sig);

$my_pkg = &$pkg['fields']['field'];

foreach ($my_pkg as &$fld) {

if ($fld['fieldname'] == "info") {
Expand All @@ -135,4 +129,21 @@ function cellular_before_everything() {
}
}
}

function cellular_validate_input($post, &$input_errors) {

// Timeout
if ($post['timeout'] != '' && !is_numericint($post['timeout'])) {
$input_errors[] = "The 'Timeout' field must contain an integer value.";
}

// Custom Status AT Command
if ($post['statuscmd'] != '') {
if (!preg_match('/^[A-Z0-9 _,;+=?"*#]*$/', $post['statuscmd'])) {
$input_errors[] = "The 'Custom Status AT Command' field may only contain A-Z, 0-9 and some other characters matching the /^[A-Z0-9 _,;+=?\"*#-]*$/ regex.";
}
}

}

?>
17 changes: 6 additions & 11 deletions net/pfSense-pkg-cellular/files/usr/local/pkg/cellular.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* cellular.xml
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate)
* Copyright (C) 2016 Voleatech GmbH, Fabian Schweinfurth
* All rights reserved.
*
Expand Down Expand Up @@ -42,14 +43,6 @@
<active/>
</tab>
</tabs>
<additional_files_needed>
<prefix>/usr/local/pkg/</prefix>
<item>https://packages.pfsense.org/packages/config/cellular/cellular.xml</item>
</additional_files_needed>
<additional_files_needed>
<prefix>/usr/local/www/widgets/widgets/</prefix>
<item>https://packages.pfsense.org/packages/config/cellular/cellular.widget.php</item>
</additional_files_needed>
<fields>
<field>
<fielddescr>Source Port</fielddescr>
Expand Down Expand Up @@ -83,19 +76,21 @@
<fielddescr>Custom Status AT Command</fielddescr>
<fieldname>statuscmd</fieldname>
<type>input</type>
<description>(without "AT" Part)</description>
<description>(Custom AT command(s) without the "AT" Part)</description>
</field>
<field>
<fielddescr>Info</fielddescr>
<fieldname>info</fieldname>
<type>info</type>
<description></description>
</field>
</fields>
<custom_php_resync_config_command>
cellular_sync();
</custom_php_resync_config_command>
<custom_php_global_functions>
cellular_before_everything();
cellular_before_everything();
</custom_php_global_functions>
<custom_php_validation_command>
cellular_validate_input($_POST, $input_errors);
</custom_php_validation_command>
</packagegui>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* cellular.widget.php
*
* part of pfSense (https://www.pfsense.org)
* Copyright (c) 2017 Rubicon Communications, LLC (Netgate)
* Copyright (C) 2016 Voleatech GmbH, Fabian Schweinfurth
* All rights reserved.
*
Expand All @@ -19,43 +20,36 @@
* limitations under the License.
*/

@require_once("guiconfig.inc");
@require_once("pfsense-utils.inc");
@require_once("functions.inc");
@require_once("/usr/local/www/widgets/include/interfaces.inc");
require_once("guiconfig.inc");
require_once("pfsense-utils.inc");
require_once("util.inc");
require_once("/usr/local/www/widgets/include/interfaces.inc");

global $config;
$python_bin = '/usr/local/bin/python2.7';
$interface_bin = '/usr/local/sbin/cellular';
$widget_url = '/widgets/widgets/cellular.widget.php';
define('PYTHON_BIN', '/usr/local/bin/python2.7');
define('INTERFACE_BIN', '/usr/local/sbin/cellular');

if (!file_exists(PYTHON_BIN)) {
echo "Error: Python not found.";
return;
}
if (!file_exists(INTERFACE_BIN)) {
echo "Error: /usr/local/sbin/cellular not found. Reinstall pfSense-pkg-cellular package.";
return;
}

if (isset($_POST['getsignalstrength'])) {

if (file_exists($python_bin) && file_exists($interface_bin)) {
exec("$python_bin $interface_bin signal", $sig);
print $sig[0];
}

exec(PYTHON_BIN . ' ' . INTERFACE_BIN . ' signal', $sig);
print $sig[0];
} elseif (isset($_POST['getcarrier'])) {

if (file_exists($python_bin) && file_exists($interface_bin)) {
exec("$python_bin $interface_bin carrier", $carrier);
print $carrier[0];
}

exec(PYTHON_BIN . ' ' . INTERFACE_BIN . ' carrier', $carrier);
print $carrier[0];
} elseif (isset($_POST['getinfoex'])) {

if (file_exists($python_bin) && file_exists($interface_bin)) {
exec("$python_bin $interface_bin infoex", $infoex);
print $infoex[0];
}

exec(PYTHON_BIN . ' ' . INTERFACE_BIN . ' infoex', $infoex);
print $infoex[0];
} elseif (isset($_POST['widget'])) {
if (file_exists($python_bin) && file_exists($interface_bin)) {
exec("$python_bin $interface_bin widget", $widget);
print $widget[0];
}

exec(PYTHON_BIN . ' ' . INTERFACE_BIN . ' widget', $widget);
print $widget[0];
} elseif (isset($_POST['getstatus'])) {
$ifdescrs = get_configured_interface_with_descr();
foreach ($ifdescrs as $ifdescr => $ifname) {
Expand Down

0 comments on commit 35a0d64

Please sign in to comment.