My bootstrap.php file looks like this, and all code is embed in welcome controller->action_index.
Kohana::init(array(
'base_url' => '/kohana/',
'index' => 'index.php'
));
Okay if I put the following in in action_index
form::open('test');
the action is /kohana/index.php/test.
So links appear to be absolute to your root install location, accept when I embed links in action_index index.php!!!
html::anchor('controller');
the href is /kohana/controller not /kohana/index.php/controller.
Now if I put
url::site('controller');
the returned value is /kohana/index.php/controller.
So I figured I would just use
html::anchor(url::site('controller'));
But href is now equal to http://localhost/kohana/kohana/index.php/controller.
What in the world is going on, and how do I fix it?
Kohana url system seems well unintuitive and wrong.
Seems like it is some kind of bug in HTML::anchor implementation.
This happens because of 127th line of html.php (v3.1.2)
$uri = URL::site($uri, $protocol, $index);
In this line $index value is FALSE according to the default anchor function value:
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = FALSE)
So all you can do now is - to pass manually 5th argument as true like:
html::anchor('controller', null, null, null, true);
or extend Kohana_HTML with custom class like:
class HTML extends Kohana_HTML
{
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = TRUE)
{
return parent::anchor($uri, $title, $attributes, $protocol, $index);
}
}
or to fill a bug on kohana bugtracker so ko devteam decide what to do.
Related
Consider the following Silverstripe page class
<?php
class Page extends SiteTree{
static $has_many = array('OtherDataObjects' => 'DataObjectClass');
public function getSearchContext() {
$fields = new FieldSet(
new TextField('Title', 'Tour'),
new DropdownField('OtherDataObjects', 'Other Data Object', array('data', 'value')
);
$filters = array(
'Title' => new PartialMatchFilter('Title'),
'OtherDataObjects' => new PartialMatchFilter('OtherDataObjects.Title')
);
return new SearchContext(
'Page',
$fields,
$filters
);
}
}
Adding this search form to a front-end form and posting a search form always results in a [User Error] with a SQL error containing something like this at the end.
AND ("DataObjectClass_Live"."DataObjectClass_Live" LIKE 'title') ORDER BY "Sort" LIMIT 25 OFFSET 0 Table 'database DataObjectClass_Live' doesn't exist
My searchcontext search throws up an error each time I try to run a search on a has_many relationship. The versioned extension seems to be the culprit because it adds _live to all tables regardless whether the baseclass has the versioned extension or not I get the same error in SilverStripe versions 2.4.x and the latest 3.0.x versions.
Any help or pointers will be appreciated.
maybe try using an sqlQuery. something like
function SearchResults() {
$select = array('*');
$from = array('OtherDataObjects');
$where = array('OtherDataObjects:PartialMatch' => '%' . $data['Title'] . '%');
$sqlQuery = new SQLQuery($select, $from, $where);
$results = $sqlQuery->execute();
return $results;
}
$data['Title'] is to be the value from the search textbox
partial match reference: http://doc.silverstripe.org/framework/en/topics/datamodel
sql query reference: http://doc.silverstripe.org/framework/en/reference/sqlquery
When i scanned my site with "Acunetix Web Vulnerability Scanner" i was very surprised. Programm show a lot of xss vulnerabilities on page when i use get parameters with xss filtration.
For example:
URL encoded GET input state was set to " onmouseover=prompt(967567) bad="
The input is reflected inside a tag parameter between double quotes.
I think its because i don`t show 404 error when result is empty (it should be). I show message like "the request is empty"
My controller:
$this->pagination->initialize($config);
$this->load->model('aircraft_model');
$data['type'] = $this->input->get('type', TRUE);
$data['year'] = $this->input->get('year', TRUE);
$data['state'] = $this->input->get('state', TRUE);
$type_param = array (
'type' => $this->input->get('type', TRUE),
);
$parameters = array(
'year' => $this->input->get('year', TRUE),
'state_id' => $this->input->get('state', TRUE),
);
foreach ($parameters as $key=>$val)
{
if(!$parameters[$key])
{
unset($parameters[$key]);
}
}
$data['aircraft'] = $this->aircraft_model->get_aircraft($config['per_page'], $this->uri->segment(3, 1),$parameters, $type_param);
$data['title'] = 'Самолеты | ';
$data['error'] = '';
if (empty($data['aircraft']))
{
$data['error'] = '<br /><div class="alert alert-info"><b>По таким критериям не найдено ниодного самолета</b></div>';
}
$name = 'aircraft';
$this->template->index_view($data, $name);
even when i turn on global xss filtering program find xss vulnerabilities.
Maybe Message for possible xss is false?
Also i have one SQL injection.
Attack details:
Path Fragment input / was set to \
Error message found:
You have an error in your SQL syntax
SQL error:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10, 10' at line 3
SELECT * FROM (`db_cyclopedia`) LIMIT -10, 10
Controller:
$this->load->model('cyclopedia_model');
$this->load->library('pagination');
$config['use_page_numbers'] = TRUE;
[pagination config]
$config['suffix'] = '/?'.http_build_query(array('type' => $this->input->get('type', TRUE)), '', "&");
$config['base_url'] = base_url().'cyclopedia/page/';
$count_all = $this->cyclopedia_model->count_all($this->input->get('type', TRUE));
if (!empty($count_all)){
$config['total_rows'] = $count_all;
}
else
{
$config['total_rows'] = $this->db->count_all('cyclopedia');
}
$config['per_page'] = 10;
$config['first_url'] = base_url().'cyclopedia/page/1'.'/?'.http_build_query(array('type' => $this->input->get('type', TRUE)), '', "&");
$this->pagination->initialize($config);
$parameters = array(
'cyclopedia_cat_id' => $this->input->get('type', TRUE),
);
foreach ($parameters as $key=>$val)
{
if(!$parameters[$key])
{
unset($parameters[$key]);
}
}
$data['type'] = $this->input->get('type', TRUE);
$data['cyclopedia'] = $this->cyclopedia_model->get_cyclopedia($config['per_page'], $this->uri->segment(3, 1),$parameters);
$data['title'] = 'Энциклопедия | ';
if (empty($data['cyclopedia']))
{
show_404();
}
$name = 'cyclopedia';
$this->template->index_view($data, $name);
And one some problems with HTTP Parameter Pollution (get parameters).
Attack details
URL encoded GET input state was set to &n954725=v953060
Parameter precedence: last occurrence
Affected link: /aircraft/grid/?type=&year=&state=&n954725=v953060
Affected parameter: type=
Sorry for a lot of code, but its my first experience with codeigniter / framework and safety first.
UPDATE:
When site url like this site.com/1 codeigniter show:
An Error Was Encountered
Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.
how to make a show 404 instead of this message?
This takes input from the user:
$config['first_url'] = base_url().'cyclopedia/page/1'.'/?'.http_build_query(array('type' => $this->input->get('type', TRUE)), '', "&");
Then this line in the Pagination.php library spits it into the output page without proper HTML-escaping:
$output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
Although automated scanning tools do generate a lot of false positives in general, this one is a genuine HTML-injection vulnerability leading to a real risk of cross-site scripting attacks.
To fix, wrap all output being injected into HTML context (eg $first_url) with htmlspecialchars(). Unfortunately as this is library code you would have to start your own fork of Pagination. Might be better to use some other library.
Don't rely on xss_clean as it can't reliably protect you. It is attempting to deal with output problems at the input layer, which is never going to work right - it'll miss attacks as well as mangling perfectly valid input. The whole idea betrays a basic, rookie misunderstanding of what the XSS problem actually is.
There are more places in Pagination that need the same fix, but I don't want to spend any more time reading CodeIgniter's painfully poor-quality code than I have to.
I do not understand how CodeIgniter has attained this degree of popularity.
How does $_GET Variable works with Concrete5? Can I use that on regular page?
I know I can do this with single page via url segment, I'm just wondering if it is possible with regular page.
Example is :http://www.domain_name.com/about-us/?name=test...
Get-parameters are available via the controllers. In the view of a page or block use:
$this->controller->get("parameterName");
A cleaner way for custom parameters would be to define them in the function view() of the page controller. If at http://www.domain_name.com/about-us is your page and you define the view function of it's pagetype controller like this:
function view($name) {
$this->set("name", $name);
}
... and call the URL http://www.domain_name.com/about-us/test – then "test" will be passed under $name to your page view.
Note that controllers for page types must be in controllers/page_types/ and called BlablaPageTypeController ... with "PageType" literally being in there.
You can use it in a template. For instance, you can grab a variable...
$sort_by = $_GET['sort'];
And then use that variable in a PageList lookup, similar to:
$pl = new PageList();
$ctHandle = "teaching";
// Available Filters
$pl->filterByCollectionTypeHandle($ctHandle); //Filters by page type handles.
// Sorting Options
if ($sort_by == "name") {
$pl->sortByName();
} else {
$pl->sortBy('teaching_date', 'desc'); // Order by a page attribute
}
// Get the page List Results
$pages = $pl->getPage(); //Get all pages that match filter/sort criteria.
$pages = $pl->get($itemsToGet = 100, $offset = 0);
Then you can iterate over that array to print stuff out...eg
if ($pages) {
foreach ($pages as $page){
echo ''.$page->getCollectionName() . '<br />';
}
}
Props to the C5 Cheatsheet for the PageList code.
In trying to implement a filterToolbar search in jquery, but when I write in the textbox it doesnt send the value, the search field nor the operator: I used an example, here is the code in html file
jQuery(document).ready(function () {
var grid = $("#list");
$("#list").jqGrid({
url:'grid.php',
datatype: 'xml',
mtype: 'GET',
deepempty:true ,
colNames:['Id','Buscar','Desccripcion'],
colModel:[
{name:'id',index:'id', width:65, sorttype: 'int', hidden:true, search:false},
{name:'examen',index:'nombre', width:500, align:'left', search:true},
{name:'descripcion',index:'descripcion', width:100, sortable:false, hidden:true, search:false}
],
pager: jQuery('#pager'),
rowNum:25,
sortname: 'nombre',
sortorder: 'asc',
viewrecords: true,
gridview: true,
height: 'auto',
caption: 'Examenes',
height: "100%",
loadComplete: function() {
var ids = grid.jqGrid('getDataIDs');
for (var i=0;i<ids.length;i++) {
var id=ids[i];
$("#"+id+ " td:eq(1)", grid[0]).tooltip({
content: function(response) {
var rowData = grid.jqGrid('getRowData',this.parentNode.id);
return rowData.descripcion;
},
open: function() {
$(this).tooltip("widget").stop(false, true).hide().slideDown("fast");
},
close: function() {
$(this).tooltip("widget").stop(false, true).show().slideUp("fast");
}
}).tooltip("widget").addClass("ui-state-highlight");
}
}
});
$("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false});
$("#list").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false,
defaultSearch: 'cn', ignoreCase: true});
});
and in the php file
$ops = array(
'eq'=>'=', //equal
'ne'=>'<>',//not equal
'lt'=>'<', //less than
'le'=>'<=',//less than or equal
'gt'=>'>', //greater than
'ge'=>'>=',//greater than or equal
'bw'=>'LIKE', //begins with
'bn'=>'NOT LIKE', //doesn't begin with
'in'=>'LIKE', //is in
'ni'=>'NOT LIKE', //is not in
'ew'=>'LIKE', //ends with
'en'=>'NOT LIKE', //doesn't end with
'cn'=>'LIKE', // contains
'nc'=>'NOT LIKE' //doesn't contain
);
function getWhereClause($col, $oper, $val){
global $ops;
if($oper == 'bw' || $oper == 'bn') $val .= '%';
if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;
if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';
return " WHERE $col {$ops[$oper]} '$val' ";
}
$where = ""; //if there is no search request sent by jqgrid, $where should be empty
$searchField = isset($_GET['searchField']) ? $_GET['searchField'] : false;
$searchOper = isset($_GET['searchOper']) ? $_GET['searchOper']: false;
$searchString = isset($_GET['searchString']) ? $_GET['searchString'] : false;
if ($_GET['_search'] == 'true') {
$where = getWhereClause($searchField,$searchOper,$searchString);
}
I saw the query, and $searchField,$searchOper,$searchString have no value
But when I use the button search on the navigation bar it works! I dont konw what is happening with the toolbarfilter
Thank You
You use the option stringResult: true of the toolbarfilter. In the case the full filter will be encoded in filters option (see here). Additionally there are no ignoreCase option of toolbarfilter method. There are ignoreCase option of jqGrid, but it works only in case of local searching.
So you have to change the server code to use filters parameter or to remove stringResult: true option. The removing of stringResult: true could be probably the best way in your case because you have only one searchable column. In the case you will get one additional parameter on the server side: examen. For example if the user would type physic in the only searching field the parameter examen=physic will be send without of any information about the searching operation. If you would need to implement filter searching in more as one column and if you would use different searching operation in different columns you will have to implement searching by filters parameter.
UPDATED: I wanted to include some general remarks to the code which you posted. You will have bad performance because of the usage
$("#"+id+ " td:eq(1)", grid[0])
The problem is that the web browser create internally index of elements by id. So the code $("#"+id+ " td:eq(1)") can use the id index and will work quickly. On the other side if you use grid[0] as the context of jQuery operation the web browser will be unable to use the index in the case and the finding of the corresponding <td> element will be much more slowly in case of large number rows.
To write the most effective code you should remind, that jQuery is the wrapper of the DOM which represent the page elements. jQuery is designed to support common DOM interface. On the other side there are many helpful specific DOM method for different HTML elements. For example DOM of the <table> element contain very helpful rows property which is supported by all (even very old) web browsers. In the same way DOM of <tr> contains property cells which you can use directly. You can find more information about the subject here. In your case the only thing which you need to know is that jqGrid create additional hidden row as the first row only to have fixed width of the grid columns. So you can either just start the enumeration of the rows from the index 1 (skipping the index 0) or verify whether the class of every row is jqgrow. If you don't use subgrids or grouping you can use the following simple code which is equivalent your original code
loadComplete: function() {
var i, rows = this.rows, l = rows.length;
for (i = 1; i < l; i++) { // we skip the first dummy hidden row
$(rows[i].cells(1)).tooltip({
content: function(response) {
var rowData = grid.jqGrid('getRowData',this.parentNode.id);
return rowData.descripcion;
},
open: function() {
$(this).tooltip("widget").stop(false, true).hide().slideDown("fast");
},
close: function() {
$(this).tooltip("widget").stop(false, true).show().slideUp("fast");
}
}).tooltip("widget").addClass("ui-state-highlight");
}
}
I want to add some additional formatting to my menu. I've been looking at menu.inc and am unsure which method would i override to do something like the following.
if content type = "fund"
print " some additional formatting "
That's not really something you would want to do in the hook_menu, actually.
I'm not sure what you're doing for sure, but it sounds like what you want to do is to use the hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) hook, something like this:
function example_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op == 'view' && $node->type == 'fund') {
$node->content['my_fund_data'] = array(
'#value' => 'Some additional formatting',
'#weight' => 10,
);
}
}
Now, if what you want to do is change the content instead of just add something below it, you'll want to investigate what the rendered node looks like - I suggest installing the devel module, which will give you a link to view the rendered node data easily.