aboutsummaryrefslogtreecommitdiffstats
path: root/config/filer
diff options
context:
space:
mode:
Diffstat (limited to 'config/filer')
-rw-r--r--config/filer/filer.inc71
-rw-r--r--config/filer/filer.xml57
-rw-r--r--config/filer/filer_sync.xml3
3 files changed, 103 insertions, 28 deletions
diff --git a/config/filer/filer.inc b/config/filer/filer.inc
index b4512a49..b89553e4 100644
--- a/config/filer/filer.inc
+++ b/config/filer/filer.inc
@@ -4,8 +4,8 @@
filerinc
part of pfSense (http://www.pfSense.com)
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
- Copyright (C) 2011 Marcello Coutinho
- Copyright (C) 2011 Brian Scholer
+ Copyright (C) 2012 Marcello Coutinho
+ Copyright (C) 2012 Brian Scholer
All rights reserved.
*/
/* ========================================================================== */
@@ -48,30 +48,71 @@ function filer_start() {
// reserved
}
+function filer_text_area_decode($text){
+ return preg_replace('/\r\n/', "\n",base64_decode($text));
+}
function sync_package_filer() {
global $config, $g;
+ $update_conf=0;
+ #mount filesystem writeable
+ conf_mount_rw();
+ #loop on configured files
if($config['installedpackages']['filer']['config']!="") {
+ $count=0;
foreach($config['installedpackages']['filer']['config'] as $file) {
- $fname = $file['fullfile'];
- $fdata = str_replace("\r", "", base64_decode($file['filedata']));
- if($file['mod']) {
- if(!preg_match("/0?[0-7]{3}/", $file['mod']))
- $mod = 0700;
- else
- $mod = octdec($file['mod']);
- }
- conf_mount_rw();
- file_put_contents($fname, $fdata);
- if($mod)
- chmod($fname, $mod);
- conf_mount_ro();
+ if ($file['filedata']=="" && file_exists($file['fullfile'])){
+ $config['installedpackages']['filer']['config'][$count]['filedata']=base64_encode(file_get_contents($file['fullfile']));
+ $file['filedata']=base64_encode(file_get_contents($file['fullfile']));
+ $update_conf++;
+ }
+ $count++;
+ if(preg_match("/0?[0-7]{3}/", $file['mod']))
+ $mod = octdec($file['mod']);
+ else
+ $mod = 0700;
+
+ #write file
+ file_put_contents($file['fullfile'], filer_text_area_decode($file['filedata']),LOCK_EX);
+ chmod($file['fullfile'], $mod);
+
+ #check if there is a script to run after file save
+ if($file['cmd']!= "")
+ switch ($file['background']){
+ case "background":
+ mwexec_bg($file['cmd']);
+ break;
+ case "foreground":
+ mwexec($file['cmd']);
+ break;
+ }
+
}
+
+ #Write config if any file from filesystem was loaded
+ if ($update_conf > 0)
+ write_config();
}
+ #mount filesystem readonly
+ conf_mount_ro();
filer_sync_on_changes();
}
+function filer_validate_input($post, &$input_errors) {
+ foreach ($post as $key => $value) {
+ if (empty($value))
+ continue;
+ if (substr($key, 0, 3) == "mod" && !preg_match("/^0?[0-7]{3}$/", $value))
+ $input_errors[] = "{$value} is valid permission number";
+ if (substr($key, 0, 11) == "description" && !preg_match("@^[a-zA-Z0-9 _/.-]+$@", $value))
+ $input_errors[] = "Do not use special characters on description";
+ if (substr($key, 0, 8) == "fullfile" && !preg_match("@^[a-zA-Z0-9_/.-]+$@", $value))
+ $input_errors[] = "Do not use special characters on filename";
+
+ }
+}
+
/* Uses XMLRPC to synchronize the changes to a remote node */
function filer_sync_on_changes() {
global $config, $g;
diff --git a/config/filer/filer.xml b/config/filer/filer.xml
index f772feb2..9196f889 100644
--- a/config/filer/filer.xml
+++ b/config/filer/filer.xml
@@ -10,6 +10,7 @@
part of pfSense (http://www.pfSense.com)
Copyright (C) 2010 Scott Ullrich <sullrich@gmail.com>
Copyright (C) 2011 Brian Scholer
+ Copyright (C) 2012 Marcello Coutinho
All rights reserved.
*/
/* ========================================================================== */
@@ -70,7 +71,6 @@
<tab>
<text>XMLRPC Sync</text>
<url>/pkg_edit.php?xml=filer_sync.xml</url>
- <active/>
</tab>
</tabs>
@@ -90,39 +90,74 @@
</adddeleteeditpagefields>
<fields>
<field>
- <fielddescr>Full path to the file</fielddescr>
+ <type>listtopic</type>
+ <fieldname>temp</fieldname>
+ <name>File configuration</name>
+ </field>
+ <field>
+ <fielddescr>File</fielddescr>
<fieldname>fullfile</fieldname>
<type>input</type>
+ <size>60</size>
+ <description>Enter Full file path</description>
<required/>
</field>
<field>
- <fielddescr>Permissions</fielddescr>
- <fieldname>mod</fieldname>
- <type>input</type>
- <description>Blank leaves the permissions alone.</description>
- </field>
- <field>
<fielddescr>Description</fielddescr>
<fieldname>description</fieldname>
<description>Enter a description for this file.</description>
<type>input</type>
+ <size>60</size>
+ </field>
+ <field>
+ <fielddescr>Permissions</fielddescr>
+ <fieldname>mod</fieldname>
+ <type>input</type>
+ <size>10</size>
+ <description><![CDATA[Enter file permission you want on this file<br>Blank leaves the permissions alone.]]></description>
</field>
<field>
<fielddescr>File Contents</fielddescr>
<fieldname>filedata</fieldname>
- <description>Paste the files contents here.</description>
+ <description>Leave blank to load an existing file from file system or paste the file content you want to save.</description>
<type>textarea</type>
<encoding>base64</encoding>
- <cols>60</cols>
- <rows>30</rows>
+ <cols>75</cols>
+ <rows>25</rows>
<required/>
</field>
+ <field>
+ <type>listtopic</type>
+ <fieldname>temp</fieldname>
+ <name>cmd to run after file save/sync</name>
+ </field>
+ <field>
+ <fielddescr>script</fielddescr>
+ <fieldname>cmd</fieldname>
+ <description>Enter script or cmd to run after file save/sync</description>
+ <type>input</type>
+ <size>60</size>
+ </field>
+ <field>
+ <fielddescr>execute mode</fielddescr>
+ <fieldname>background</fieldname>
+ <type>select</type>
+ <options>
+ <option><name>Background (default)</name><value>background</value></option>
+ <option><name>Foreground</name><value>foreground</value></option>
+ <option><name>Do not run this script</name><value>disabled</value></option>
+ </options>
+ <description>Choose the way script will run.</description>
+ </field>
</fields>
<custom_php_install_command>
filer_install();
</custom_php_install_command>
<custom_php_command_before_form>
</custom_php_command_before_form>
+ <custom_php_validation_command>
+ filer_validate_input($_POST, &amp;$input_errors);
+ </custom_php_validation_command>
<custom_delete_php_command>
sync_package_filer();
</custom_delete_php_command>
diff --git a/config/filer/filer_sync.xml b/config/filer/filer_sync.xml
index ae8e48ba..c51bae86 100644
--- a/config/filer/filer_sync.xml
+++ b/config/filer/filer_sync.xml
@@ -9,8 +9,8 @@
filer_sync.xml
part of pfSense (http://www.pfSense.com)
Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
- Copyright (C) 2011 Marcello Coutinho
Copyright (C) 2011 Brian Scholer
+ Copyright (C) 2012 Marcello Coutinho
All rights reserved.
*/
/* ========================================================================== */
@@ -50,7 +50,6 @@
<tab>
<text>Files</text>
<url>/pkg.php?xml=filer.xml</url>
- <active/>
</tab>
<tab>
<text>XMLRPC Sync</text>