Pkg.php with up and down function - almost there



  • Hi all,

    I could include some prototypes functions to pkg.php that is used to list acls, rules on packages like squidguard,dansguardian,imspector-dev, sshdcond, etc.

    The only thing missing is a way to call sync package function after changing rule options.

    If somebody can help me on finishing it, I can try to pull this request to pfsense.

    Backup your pkg.php file and download pkg.php modified from here

    Thanks for any help






  • I think you need to add the top bar with the button APPLY, as in the firewall rules when exists the changes.
    Such changes must be considered independently for each xml package ( If I understand correctly )

    Resunc function possible take from the 'custom_php_resync_config_command' section of current xml file ( as ?xml=squid_nac.xml )



  • @dvserg:

    Resunc function possible take from the 'custom_php_resync_config_command' section of current xml file ( as ?xml=squid_nac.xml )

    Yes, i saw that.
    The part I could not get is how read it or call it on pkg.php

    Thanks for your help.



  • This is XML already imported to the $pkg value

    $xml = $_REQUEST['xml'];
    
    if($xml == "") {
    	print_info_box_np(gettext("ERROR: No package defined."));
    	exit;
    } else {
    	if(file_exists("/usr/local/pkg/" . $xml))
    		$pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui");
    	else {
    		echo "File not found " . htmlspecialchars($xml);
    		exit;
    	}
    }
    

    And all sources from this package must be already included

    if ($pkg['include_file'] != "") {
    	require_once($pkg['include_file']);
    }
    

    You can call resync function probable as

    
    if ($pkg['custom_php_resync_config_command']) eval ("{$pkg['custom_php_resync_config_command']}");
    
    

    This information is suitable to this topic?



  • @dvserg:

    This information is suitable to this topic?

    If helps me finishing it, yes  :)

    I'll try it.

    thanks a lot.



  • If this will work and is then automatically available for every package I love it!
    This is really really usefull for freeradius package because you sometimes have to rearrange the entries in users file.

    Greate job marcello and thank you very much for the help dvserg ! :)

    That is one of many points because I love pfsense and the community!



  • I think it is useful to introduce it as an 'order' option in the xml for pkg tables.



  • @dvserg:

    I think it is useful to introduce it as an 'order' option in the xml for pkg tables.

    Second great idea  :)



  • @dvserg:

    I think it is useful to introduce it as an 'order' option in the xml for pkg tables.

    Included on this version  :)

    To use it, set one of them on  <adddeleteeditpagefields>xml part
    <movable>arrow</movable> to show arrow characters
    or
    <movable>text</movable> to show text

    sample:

    	 <adddeleteeditpagefields><columnitem><fielddescr>Status</fielddescr>
    			<fieldname>enable</fieldname></columnitem> 
    		 <columnitem><fielddescr>action</fielddescr>
    			<fieldname>action</fieldname></columnitem> 
    		 <columnitem><fielddescr>local ID</fielddescr>
    			<fieldname>localid</fieldname></columnitem> 
    		 <columnitem><fielddescr>Description</fielddescr>
    			<fieldname>description</fieldname></columnitem> 
    		<movable>arrow</movable>
    
    Still missing the save part.</adddeleteeditpagefields> 
    ```</adddeleteeditpagefields>


  • save part included  :)

    Backup your pkg.php file and download pkg.php modified from here(renamed to pkg.txt)

    the xml new args for adddeleteeditpagefields

    are <movable>arrow</movable> or <movable>text</movable>

    inside <columnitem>, you can include <encoding>base64</encoding> to show base64 fields.

    All test are wellcome</columnitem>



  • Hi Marcello,

    I tried with your new pkg.php file and modified some of my .xml in freeradius.
    The GUI is working, moving the lines is working, too - but - how can I save it !?!

    Thank you. :)




  • Hi Marcello..

    I tested this in others browser too… And all working!

    • Chromium 18.0.1025.151

    • Firefox 12.0

    • IE 9.0.8112.16421

    • Nokia BrowserNG/1.1.4

    • Chrome 19.0.1084.46

    att,




  • @Nachtfalke:

    Hi Marcello,

    I tried with your new pkg.php file and modified some of my .xml in freeradius.
    The GUI is working, moving the lines is working, too - but - how can I save it !?!

    Thank you. :)

    Nachtfalke,

    Its  attached the image with save button detail :)




  • @ccesario:

    (…)
    Nachtfalke,

    Its  attached the image with save button detail :)

    Ooops  ::)
    Now I got it! And it is working as it should. Really nice to see that feature working :-)

    Some questions: ;)
    I know, it depends on the number of entries but is there a plan to improve this feature so that I am able to move a line faster to the top than just always one line after another ? I think about something like it is done in firewall rules ?

    Is it possible to implement a feature that allows us to sort the entries (descending, ascending by name, or by IP or something else ?) Just sorting on the GUI - not re-arrange them it the config-files ?



  • The sort feature is already on original pkg.PHP code.
    The movable feature is different from rules code. I will need some rewrites and time



  • @marcelloc:

    The sort feature is already on original pkg.PHP code.

    It's not working for me. Do I have to add some XML code to use it ?
    For example on freeradius users I want to click on "username" and then get all the usernames sorted ascending. Same with VLAN ID and so on.

    @marcelloc:

    The movable feature is different from rules code. I will need some rewrites and time

    Great. The most important and most helpful thing for me is the possibility to move items up and down.
    The rest is just for better handling :-)



  • @Nachtfalke:

    It's not working for me. Do I have to add some XML code to use it ?

    Include this field on your xml

     <field><fielddescr>sortable</fielddescr>
    		<fieldname>sortable</fieldname>
    		<display_maximum_rows>10</display_maximum_rows>
    		<type>sorting</type>
    		 <include_filtering_inputbox><sortablefields><name>Local id</name>
    				<fieldname>localid</fieldname> 
    			 <name>Action</name>
    				<fieldname>action</fieldname></sortablefields></include_filtering_inputbox></field> 
    

    In this example, I'm filtering localid and action fields.

    Update the pkg.php again, I`ve pushed a fix to avoid movable and sortable enabled on the same xml until I find a way to use both together .

    EDIT:

    All features are working together :)
    I've include the to adddeleteeditpagefields as well domtt tittles.

    I think it's done!

    att,
    Marcello Coutinho



  • I think we got it!  :D

    latest code using template images.

    **<adddeleteeditpagefields></adddeleteeditpagefields>**new features on this code:

    • To enable movable table and buttons, just add <movable>on</movable>

    • To add a ? button besides + button with a description for this list, include <description>My list description</description>

    new features on this code:

    • To customize checkbox display info on list, use <listmodeon>enable or selected text here</listmodeon> and <listmodeoff>disable or off text here</listmodeoff>

    • To show base64 fields on list, use <encoding>base64</encoding>






  • Great job, marcelloc !
    Do you think it might be better to increase the interval between e/x, and arrows?



  • @dvserg:

    Great job, marcelloc !
    Do you think it might be better to increase the interval between e/x, and arrows?

    Thanks, you've helped a lot explaining the code  :)

    I've included all buttons on a single < td > to leave more space to fields.
    The remove button has an alert to prevent mistakes.

    what do you think? Did you had time to test it on squidguard?



  • @marcelloc:

    Thanks, you've helped a lot explaining the code  :)
    I've included all buttons on a single < td > to leave more space to fields.
    The remove button has an alert to prevent mistakes.
    what do you think? Did you had time to test it on squidguard?

    I want to do it in the next few days as soon as I find free time


  • Rebel Alliance Developer Netgate

    When you make these changes and submit them, please do this on the master branch and not RELENG_2_0

    RELENG_2_0 is for bug fixes only, it's not meant as a target for new features.

    As it is, someone would have to manually pull that change into master, assuming it applies cleanly, and if nobody does, it'll be missing from 2.1.

    The proper procedure is to add things into master first, and if it's deemed minor enough or an important fix, then things can be merged back from master to the other branches.



  • Ok jimp.

    I'll merge this code on 2.1 and test before submit to master.

    I've pushed to releng 2 because all tests where done on 2.0.1

    Thanks.


  • Rebel Alliance Developer Netgate

    Any sign of this for 2.1? I don't recall seeing a new pull request or commit.



  • @jimp:

    Any sign of this for 2.1? I don't recall seeing a new pull request or commit.

    I'll pull this week.  :)



  • Jimp,

    2.1 is almost based on jquery and the movable I did with ccesarios is based on prototype.

    Do you mind if ccesario and me try to migrate it to jquery with drag and drop before the pull request?

    att,
    Marcello Coutinho


  • Rebel Alliance Developer Netgate

    Yes it should be jquery on 2.1.



  • First release for 2.1-devel using jquery.

    drag the line and drop to any position you want  :)

    source code for this pkg.php

    I'll wait some feedback and do more tests before pull request.

    att,
    Marcello Coutinho




  • After some tests and some fixes I think it's done.

    source code for this pkg.php

    Jimp,

    Do you what to check before pull request?


  • Rebel Alliance Developer Netgate

    Just submit it as a pull request and I can use the system patches package to pull it in and try it from there before actually committing it.



  • Thanks Jimp, the code is now part of pfsense  :)

    I've also finished some pkg_edit.php improvements including the end of the "for($x=0; $x<99; $x++)" rowhelper loop.

    using for:

    if($fields['type'] == "rowhelper") {
    				// save rowhelper items.
    				for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form.
    				                         // XXX: this really is not helping embedded platforms.
    					foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
    						if($firstfield == "")  {
    						  $firstfield = $rowhelperfield['fieldname'];
    						} else {
    						  if($firstfield == $rowhelperfield['fieldname']) $rows++;
    						}
    						$fieldname = str_replace("\\", "", $rowhelperfield['fieldname']);
    						$comd = "\$value = \$_POST['" . $fieldname . $x . "'];";
    						eval($comd);
    						if($value <> "") {
    							$comd = "\$pkgarr['row'][" . $x . "]['" . $fieldname . "'] = \"" . $value . "\";";
    							//echo($comd . "
    ");
    							eval($comd);
    						}
    					}
    				}
    

    using a loop between rowhelper and post:

    case "rowhelper":
    	// save rowhelper items. 
    	foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield)
    		foreach($_POST as $key => $value){
    			if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/",$key,$matches))
    				$pkgarr['row'][$matches[1]][$rowhelperfield['fieldname']]=$value;
    		}
    	 break;
    

    link to full code:
    http://e-sac.siteseguro.ws/packages/pkg_edit.21.txt

    I'll start again more tests before the pull request.

    att,
    Marcello Coutinho


  • Rebel Alliance Developer Netgate

    GeekGod approved it right away before I had a chance to look at it and test, he must have thought it looked OK. :-)



  • Hi again,

    probably I missed something in this thread but is this feature implemented in actual pfsense 2.1 snapshots ?
    I tried with

            <adddeleteeditpagefields><columnitem><fielddescr>Username</fielddescr>
                            <fieldname>varusersusername</fieldname></columnitem> 
                    <columnitem><fielddescr>Use One Time Password</fielddescr>
                            <fieldname>varusersmotpenable</fieldname></columnitem> 
                    <columnitem><fielddescr>Simult. Connections</fielddescr>
                            <fieldname>varuserssimultaneousconnect</fieldname></columnitem> 
                    <columnitem><fielddescr>IP Address</fielddescr>
                            <fieldname>varusersframedipaddress</fieldname></columnitem> 
                    <columnitem><fielddescr>Expiration Date</fielddescr>
                            <fielddescr>Simult. Connections</fielddescr>
                            <fieldname>varuserssimultaneousconnect</fieldname></columnitem> 
                    <columnitem><fielddescr>IP Address</fielddescr>
                            <fieldname>varusersframedipaddress</fieldname></columnitem> 
                    <columnitem><fielddescr>Expiration Date</fielddescr>
                            <fieldname>varusersexpiration</fieldname></columnitem> 
                    <columnitem><fielddescr>Session Timeout</fielddescr>
                            <fieldname>varuserssessiontimeout</fieldname></columnitem> 
                    <columnitem><fielddescr>Possible Login Times</fielddescr>
                            <fieldname>varuserslogintime</fieldname></columnitem> 
                    <columnitem><fielddescr>VLAN ID</fielddescr>
                            <fieldname>varusersvlanid</fieldname></columnitem> 
                    <columnitem><fielddescr>Description</fielddescr>
                            <fieldname>description</fieldname></columnitem> 
                    <movable>text</movable></adddeleteeditpagefields> 
    
    

    but had no luck.

    Further I would like to sort this fields - how to implement the sorting featur - if possible !?
    Thank you :-)



  • @Nachtfalke:

    probably I missed something in this thread but is this feature implemented in actual pfsense 2.1 snapshots ?
    but had no luck.

    On 2.1 it's drag and drop. :)

    @Nachtfalke:

    Further I would like to sort this fields - how to implement the sorting featur - if possible !?

    There is a sorting field on pkg.php, but it's used to filter records.




  • @marcelloc:

    @Nachtfalke:

    probably I missed something in this thread but is this feature implemented in actual pfsense 2.1 snapshots ?
    but had no luck.

    On 2.1 it's drag and drop. :)

    Much better  ;D

    @marcelloc:

    @Nachtfalke:

    Further I would like to sort this fields - how to implement the sorting featur - if possible !?

    There is a sorting field on pkg.php, but it's used to filter records.

    Hmm - any examples of this - GUI and code ? I cannot really imagine if this would help me or not ;-)
    I would like - if I have 200 freeradius user entries - to sort them all by name ascending or by VLAN-ID and so on.
    Could this be done by this filter option ?

    Thank you!  :)



  • Nachtfalke,

    Install IpGuard package, I think that this help you.

    See the /usr/local/pkg/ipguard.xml file.

    ;)



  • @ccesario:

    Nachtfalke,

    Install IpGuard package, I think that this help you.

    See the /usr/local/pkg/ipguard.xml file.

    ;)

    Hmm, that's probably not what I want but nice to know that it will work  :P



  • @Nachtfalke:

    Hmm, that's probably not what I want but nice to know that it will work  :P

    It's usefull to find/filter fields in a large list. maybe I'll change dansguardian user tab to this.



  • Ok, ok, ok!
    You got me. I added this to freeradius2 package  ;)

    It is not exactly what I want - it is more (complex) - but I think it will be helpful as bigger as the user file is  :P


Log in to reply