I want to use getResources to get the content from a document, and its child documents. I believe I can used &depth to do this but I cannot seem to get it working.
I have tried 2 approaches:
echo "[[!getResources? $parents=`15` &includeTVs=`1` &resources=`" . $resid . "` &depth=`1` &tpl=`tendertmp`]]";
and:
echo "[[!getResources? $parents=`" . $resid . "` &depth=`1` &includeTVs=`1` &tpl=`tendertmp`]]";
$resid is just a number generated by a snippet - the first example works fine without depth.
Would anyone know the correct way of using depth or a way to get the reources content along with its child resources content?
Why you do not use http://rtfm.modx.com/display/revolution20/modX.runSnippet ?
$output = $modx->runSnippet('getResources',array(
'parents' => $resid,
'depth' => '1',
'includeTVs' => '1',
'tpl' => 'tendertmp'
));
echo $output;
and your second mistake in $parents instead &parents.
I actually do not understand why you are attempting to run getResources from within a PHP Snippet. There is very little reason to do so.
You could simple do a $modx->getCollection('modResource, $someCriteriaHere); or
Call getResources directly from your pages:
[[!getResources?parents=`15`&includeTVs=`1`&depth=`1`&tpl=`tendertmp`]]
Related
I am unfamiliar with perl, and I have a need to modify a Nagios check. I'd appreciate any advice on how to proceed. The check I'm using is check_smart, found here:
https://www.claudiokuenzler.com/nagios-plugins/check_smart.php
This script lets you check SMART values from hard drives and present the results in a simple form for monitoring. As it stands, the script can take a regex in the form /dev/sd[a-c] for one of the options; I believe that this is the section which allows this:
# list of devices for a loop
my(#dev);
if ( $opt_d ){
# normal mode - push opt_d on the list of devices
push(#dev,$opt_d);
} else {
# glob all devices - try '?' first
#dev =glob($opt_g);
}
foreach my $opt_dl (#dev){
warn "Found $opt_dl\n" if $opt_debug;
if (-b $opt_dl || -c $opt_dl){
$device .= $opt_dl.":";
} else {
warn "$opt_dl is not a valid block/character special device!\n\n" if $opt_debug;
}
}
I don't quite understand why the variable is $opt_dl when earlier it seems to be $opt_d. The result, however, is that the script returns something like:
OK: [/dev/sda] - Device is clean --- [/dev/sdb] - Device is clean --- [/dev/sdc] - Device is clean
EDIT: Here's the code where $opt_d is set; on further thought it seems like $opt_dl is just $opt_d while it's in a loop or something?
use vars qw($opt_b $opt_d $opt_g $opt_debug $opt_h $opt_i $opt_v);
Getopt::Long::Configure('bundling');
GetOptions(
"debug" => \$opt_debug,
"b=i" => \$opt_b, "bad=i" => \$opt_b,
"d=s" => \$opt_d, "device=s" => \$opt_d,
"g=s" => \$opt_g, "global=s" => \$opt_g,
"h" => \$opt_h, "help" => \$opt_h,
"i=s" => \$opt_i, "interface=s" => \$opt_i,
"v" => \$opt_v, "version" => \$opt_v,
);
The part of the code I'd like to change in a similar fashion is:
# Allow all device types currently supported by smartctl
# See http://www.smartmontools.org/wiki/Supported_RAID-Controllers
if ($opt_i =~ m/(ata|scsi|3ware|areca|hpt|cciss|megaraid|sat)/) {
$interface = $opt_i;
} else {
print "invalid interface $opt_i for $opt_d!\n\n";
print_help();
exit $ERRORS{'UNKNOWN'};
}
Specifically, I'd like to be able to pass the script something like "megaraid,[5-8]" and let it run for each. In this case, I would not be passing the regex for the device, it would just be /dev/sda.
If anyone could give me advice on this I'd appreciate it!
$opt_dl is probably poorly named and has nothing to do with your $opt_d, those are two separate variables.
From the if statement, if $opt_d is not set (that is the script was not given any device name to act upon), then glob is called with the value of $opt_g and it is glob in fact that finds out all filenames based on the regex given inside $opt_g.
After this if statement, the #dev array is filed with the names of devices to handle.
And then you have a foreach statement which means a loop on each item inside the #dev array. And during the loop, each item is in the $opt_dl variable, due to its use on the foreach statement.
However I was not able to understand what you wanted to do in your last paragraph.
I'm the maintainer of check_smart and it's funny I accidentally stumbled on that question now.
I don't quite understand why the variable is $opt_dl when earlier it seems to be $opt_d. The result, however, is that the script returns something like: OK: [/dev/sda] - Device is clean --- [/dev/sdb] - Device is clean --- [/dev/sdc] - Device is clean
So basically when you use the -g parameter, you tell the check_smart plugin to use glob (https://perldoc.perl.org/functions/glob.html) - this is not the same as regular expression. The drives matching the glob expression (e.g. -d '/dev/sd[a-z]) will create a list ($opt_dl) and the plugin will run through each drive in a for loop.
Specifically, I'd like to be able to pass the script something like "megaraid,[5-8]" and let it run for each. In this case, I would not be passing the regex for the device, it would just be /dev/sda.
This is already possible since release 5.0 (which was released in April 2014, way before your question ;-) ). You just need to change the syntax. Instead of using the glob expression on -d, you use it on the interface parameter (-i). Practical example: -i 'megaraid,[5-8]'.
Since the newest release (6.6, released a couple of days ago), the output for multiple drive checks (using -g) and hardware storage/raid controllers has slightly changed and now indicates the interface's device id rather than the logical drive path:
# ./check_smart.pl -g /dev/sda -i 'megaraid,[1-3]'
OK: [megaraid,1] - Device is clean --- [megaraid,2] - Device is clean --- [megaraid,3] - Device is clean|
This is all described in the official documentation, too.
More info:
https://www.claudiokuenzler.com/monitoring-plugins/check_smart.php
https://www.claudiokuenzler.com/blog/914/check_smart-6.6-multiple-drives-check-megaraid-3ware-cciss-controllers
I hope this answers your question, although I am probably 2 years late.
I've got an SQL query that spits out a group of IDs. I feed these IDs to a getResources call as such:
[[getResources?
&parents=`4`
&resources=`' . $ids . '`
&limit=`0`
&showHidden=`1`
&tpl=`PropItemTPL`
&sortby=`menuindex ASC, id`
&sortdir=`ASC`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&showUnpublished=`0`
]]
Problem is this shows all IDs, even if they're unpublished.
I've included &showUnpublished='0' but this makes no difference.
Would anyone know if there's a way to have this work with getResources? Or do I need to re-write my PHP and MySQL?
The resources parameter is separate from the rest of the selection logic. If you include a resource's id in the resources property, it will be included regardless of any other selection properties.
Try pdoResources and I don't think you'll have this problem. It's also much quicker than getResources.
You can add "where" clause as one of your parameters, narrowing result set to only published documents:
[[getResources?
&parents=`4`
&resources=`' . $ids . '`
&limit=`0`
&showHidden=`1`
&tpl=`PropItemTPL`
&sortby=`menuindex ASC, id`
&sortdir=`ASC`
&includeContent=`1`
&includeTVs=`1`
&processTVs=`1`
&where=`{"published" : true}`
]]
I am trying to use this code that was provided to me for a penetration test exercise. According to the author that created this you enter this code and it will get the users hashes from a machine we are trying to compromise. When I enter the code it does not return anything from the database. All I get is a ":" on the screen. Something does not seem right with this code can you please help. My job is not to fix the code but to just query the information from the database to get the hashes for the users. I am just going based up on the instructions of the LAMPSecurity CTF8 pdf that was provided to me.
<?php
$res = db_query('select name,pass from users');
while ($rec = db_fetch_object($res)) {
print $rec→name . ":" . $rec→pass . "<br/>";
}
?>
Somewhere during the parsing of your PDF, the characters -> have been turned into the UTF8 equivalent of →.
However, → is not a valid operator in PHP.
Replace → with -> and try again.
Also, your code doesn't connect to the DB anywhere, so that may cause further issues.
I am trying to achieve a very simple goal, however it does not seem to be working. I wish to use Kohana's ORM and conditionally add certain parameters.
For instance:
$query = ORM::factory('user')
->where('foo', '=', 'bar');
if (isset($some_var))
$query->where('field', '=', $some_var);
$query->find_all();
One would think this should work, but all I get from $query is a big fat nothing. Any suggestions I would greatly appreciate! Thanks.
EDIT:
The simple example on this Kohana page even shows a similar query:
http://kohanaframework.org/3.1/guide/orm/examples/simple
...But even when I create a 'user' model instance and then try to find_all() in a separate statement, I get nothing.
This works:
$query = ORM::factory('user')->find_all();
This doesn't work:
$query = ORM::factory('user');
$query->find_all();
Possible bug??
In your example that works, you are assigning the value returned from find_all() to $query. While in the example that is not working, you are not assigning the value returned by find_all() at all.
kohana framework
$query = ORM::factory('user');
$result = $query->find_all();
// you may now loop over $result
When you look over the api, you will see that find() and find_all() work differently.
Your code is perfectly fine, as ORM::where method returns ORM object, so there is no problem with method chaining. You should look for the errors in other place (perhaps your $some_var is set but may be empty, therefore your condition may look different then expected). I'd try with this small change:
if (!empty($some_var))
$query->where('field', '=', $some_var);
I have override a node.tpl and need some results from db using a query generated by views.
Here is the code which i used:
<?php $res = db_query("SELECT node.nid AS nid, node.title AS node_title FROM node node LEFT JOIN content_field_is_popular node_data_field_is_popular ON node.vid
= node_data_field_is_popular.vid WHERE (node.type in ('article_thisweekend')) AND (UPPER(node_data_field_is_popular.field_is_popular_value)
= UPPER('yes'));");
foreach($res as $reco){
print ($reco->nid);
}
?>
But I am not getting any results.
What I am missing?
Thanks
Matt V. has good advice in that you should try to separate the view templates from the sql query logic.
For this specific example though, you need to use db_fetch_object since $res just contains the
database query result resource
Instead of
foreach($res as $reco){
print ($reco->nid);
}
Do
while ($reco = db_fetch_object($res)){
print ($reco->nid);
}
It's generally best to avoid putting queries directly in your template files. It's best to separate logic and presentation.
Instead, use a module to generate the content you need and pass that along to the theme layer. In this case, if you're already using the Views module to generate the query, let Views run it for you and pass off the data to a page or block display.
Otherwise, to debug the query, try running the query independent of the code, through something like phpMyAdmin or "drush sqlq".