How to Modify behavior of the Search Button

Posted:
Mon Jun 27, 2011 5:50 am
by rleyba
Hi Steve,
I have created a table as attached composed of IP addresses and other related fields. Basically I want to create another "Search button" such that if the user types in an IP address the table would show ALL interfaces where that IP is within the Lower IP and Upper IP range of the firewall interfaces in the list. I show only 4 in my attached example, but there are literally hundreds of rows in the real table.
For simplicity, let's use decimal numbers first (the decimal equivalent of the IP addresses). If the user would type in 167838722 in the "Search IP" box and click on "Submit IP" button, then the resulting query would show only ONE record (in this case), which would be Firewall C --- eth-s3p1c0 --- 20 -- test e -- on -- Up etc. In other words, I want this search button to be some kind of Select where target IP >= Lower_Dec and target IP <= Upper decimal.
Would appreciate if you could point me to how this could be accomplished (i.e. which templates or forms or PHP sections to modify?)
thanks Steve
P.S. In the attached photo, the Submit IP button has no function...it's there only as an illustration. Thanks...
Re: How to Modify behavior of the Search Button

Posted:
Mon Jun 27, 2011 9:21 am
by shannah
The key to this is to understand the Xataface URL conventions. What you are looking for is the list view (-action=list) for the ip_addresses table (-table=ip_addresses) filtered to only show records with target_ip between $lowerdec and $upperdec (target_ip=$lowerdec..$upperdec).
E.g.
index.php?-action=list&-table=ip_addresses&target_ip=23456789..9876543
(for example).
This can be expressed as a form with:
- Code: Select all
<form action="index.php" method="get">
Search: <input type="text" name="target_ip" />
<input type="hidden" name="-action" value="-list"/>
<input type="hidden" name="-table" value="ip_addresses"/>
<input type="submit"/>
</form>
For more on URL conventions in Xataface see
http://xataface.com/wiki/URL_Conventions-Steve
Re: How to Modify behavior of the Search Button

Posted:
Tue Jun 28, 2011 5:58 am
by rleyba
Hi Steve,
Thanks for that. I was trying to build the code like so:
- Code: Select all
<?
class tables_FIREWALL_INTERFACES {
function block__before_body() {
echo "This is some text test<p>";
}
function block__after_search_form_submit() {
echo "<form action='index.php' method='get'>";
echo " Search: <input type='text' name='target_ip' />";
echo " <input type='hidden' name='-action' value='-list'/>";
echo "<input type='hidden' name='-table' value='FIREWALL_INTERFACES'/>";
echo "<input type='hidden' name='-target_ip' value='$Lower_Dec..$Upper_Dec'/>";
echo "<input type='submit'/>";
echo "</form>";
}
}
?>
When I enter a value like 167837954 and click submit, I get the error messages below.
- Code: Select all
Fatal error: No template found for action '-list'.On line 48 of file /var/www/html/xataface-1.2.6/actions/default.php in function printStackTrace()
On line 1131 of file /var/www/html/xataface-1.2.6/Dataface/Application.php in function handle(array(array(-list,-list)))
On line 1611 of file /var/www/html/xataface-1.2.6/Dataface/Application.php in function handleRequest()
On line 19 of file /var/www/html/xataface-1.2.6/Integra-test/index.php in function display()
in /var/www/html/xataface-1.2.6/actions/default.php on line 48
the actual URL that appears on the URL bar is the one below. It just looks odd but I'm not sure how I am to modify it. Your tips on the syntax would be appreciated.
- Code: Select all
http://192.168.1.102/xataface-1.2.6/Integra-test/index.php?-table=FIREWALL_INTERFACES&-search=&-action=search_index&target_ip=167837954&-action=-list&-table=FIREWALL_INTERFACES&-target_ip=..
Re: How to Modify behavior of the Search Button

Posted:
Tue Jun 28, 2011 8:22 am
by shannah
It should be action = list. Not action = -list
-STeve
Re: How to Modify behavior of the Search Button

Posted:
Wed Jun 29, 2011 4:11 am
by rleyba
Thanks Steve,
I followed that but still getting some errors:
The final snippet it now:
- Code: Select all
<?
class tables_FIREWALL_INTERFACES {
function block__before_body() {
echo "This is some text test<p>";
}
function block__after_search_form_submit() {
echo "<form action='index.php' method='get'>";
echo " Search: <input type='text' name='target_ip' />";
echo " <input type='hidden' name='-action' value='list'/>";
echo "<input type='hidden' name='-table' value='FIREWALL_INTERFACES'/>";
echo "<input type='hidden' name='-target_ip' value='$Lower_Dec..$Upper_Dec'/>";
echo "<input type='submit'/>";
echo "</form>";
}
}
?>
Pressing submit shows the whole dataset even though I keyed in some unreasonable value (like 1 and 100 as shown below). I also tried to remove the "$" signs as they seem to be messing up the query but I still got the full dataset instead of the match. Here are the resulting URLs that the snippet above yielded (the 2nd one was when I removed the $sign in Lower_Dec and $Upper_Dec.
What else might be going wrong?
Thanks Steve.
- Code: Select all
http://192.168.1.102/xataface-1.2.6/Integra-test/index.php?-table=FIREWALL_INTERFACES&-search=&-action=list&target_ip=1&-action=list&-table=FIREWALL_INTERFACES&-target_ip=..
http://192.168.1.102/xataface-1.2.6/Integra-test/index.php?-table=FIREWALL_INTERFACES&-search=&-action=list&target_ip=100&-action=list&-table=FIREWALL_INTERFACES&-target_ip=Lower_Dec..Upper_Dec
Re: How to Modify behavior of the Search Button

Posted:
Wed Jun 29, 2011 5:14 am
by rleyba
It also seems that the resulting URL merges the original search in the form and appends the php template search parameters in the same form like so:
- Code: Select all
http://192.168.1.102/xataface-1.2.6/Integra-test/index.php?-table=FIREWALL_INTERFACES&-search=&-action=list&-submit=Submit&target_ip=23&-action=list&-table=FIREWALL_INTERFACES&-target_ip=..
At any rate, I tried to simplify the URL by pasting only the search form parameters for what I wanted to test but I still got the whole dataset even though, from the forced URL below, it should show no data.
- Code: Select all
http://192.168.1.102/xataface-1.2.6/Integra-test/index.php?-table=FIREWALL_INTERFACES&-submit=Submit&target_ip=100&-action=list&-target_ip=Lower_Dec..Upper_Dec
Thanks very much.
Re: How to Modify behavior of the Search Button

Posted:
Wed Jun 29, 2011 9:53 am
by shannah
A couple of things here:
1. You don't need this
- Code: Select all
echo "<input type='hidden' name='-target_ip' value='$Lower_Dec..$Upper_Dec'/>";
$Lower_Dec..$Upper_Dec was just a placeholder example for the target_ip field range search.
E.g. to search for ip addresses between 100 and 200 (if there were such addresses) you would have target_ip=100..200
2. Your placement in the after_search_form_submit block means that it probably already ends up inside the search's <form> tag. You can't have nested form tag or things work funny. Either just add fields to the existing <form> or put it in a different block.
-Steve
Re: How to Modify behavior of the Search Button

Posted:
Mon Jul 04, 2011 7:21 am
by rleyba
Hi Steve,
Yes I put it in another block and the query is working now. All Good....thanks.