wsadmin: jacl: AdminApp list <scope?> WebSphere 5.x - scripting

I am trying to list applications installed on particular server below command works fine on WAS 6.x and 7 however I cannot make the same on WAS 5.x
wsadmin> $AdminApp list /WebSphere:cell=cell01,node=node01,server=server1/
Also, $AdminApp help list does not show optional scope parameter.
Could you please advise ?
Thanks

I don't have access to v5 right now to test, but something like this might work:
proc listAppsByTarget {target} {
global AdminApp
set result []
regsub -all / $target "" target
foreach app [$AdminApp list] {
foreach line [split [$AdminApp view $app -MapModulesToServers] "\r\n"] {
if [regexp "^Server: ${target}($|,)" $line] {
lappend result $app
break
}
}
}
return $result
}
This will print any application that has a module targetted to the specified server. Used like this:
wsadmin>listAppsByServerTarget /WebSphere:cell=cell,node=node,server=server1/
DefaultApplication

I found the way, however it's not the same output, it needs to be parsed to get the details.
wsadmin > $AdminControl queryName type=Application,node=node01,process=server1
In case there is another way please let me know.

Related

Spring shell 2.0 how to read inputs with mask

Is there any way to mask user inputs in Spring Shell 2.0.x ?
I need to collect password from user.. did not find any shell api to do that.
Thanks!!
Found that LineReader#readLine(msg,mask) provides that option.
All you have to do is inject the LineReader bean.
If you don't want to rely on third party libraries, you can always do a standard Java console input, something like:
private String inputPassword() {
Console console = System.console();
return new String(console.readPassword());
}
Note though that when running this in an IDE, the System.console() might be null. So you should probably handle that if running in an IDE is something you want to support (for testing for example..) something like:
private String inputPassword() {
Console console = System.console();
// Console can be null when running in an IDE
if (console == null) {
System.out.println("WARNING - CAN'T HIDE PASSWORD");
return new Scanner(System.in).next();
}
return new String(console.readPassword());
}

vanilla php ldap query works. Symfony 3 ldap query fails. Why?

I'm trying to figure out how to use the Ldap class in Symfony3. I've successfully created and bound a connection but I can't get any results on a query. To make sure that the query actually works, I ran a bare php version:
if($lconn = ldap_connect('ds.mydomain.ca')){
ldap_set_option($lconn, LDAP_OPT_REFERRALS, 0);
ldap_set_option($lconn, LDAP_OPT_PROTOCOL_VERSION, 3);
if($lbind = ldap_bind($lconn,'webuser','password')){
$filter ="(&(sn=Smith)(givenname=J*))";
if(!$result = ldap_search($lconn, "dc=ds, dc=mydomain, dc=ca", $filter)) throw \Exception("Error in search query: ".ldap_error($lconn));
$output = ldap_get_entries($lconn, $result);
}else{
$output='bind failed';
}
} else {
$output= 'connection failed';
}
It returns the expected number of results.
On the other hand, this query done with Symfony 3's Ldap component returns 0 results:
//use Symfony\Component\Ldap\Ldap
$ldap = Ldap::create('ext_ldap', array(
'host' => 'ds.mydomain.ca',
'version' => 3,
'debug' => true,
'referrals' => false,
));
$ldap->bind('webuser', 'password');
$q = $ldap->query("dc=ds, dc=nrc, dc=ca", "(&(sn=Smith)(givenname=J*))");
$output = $q->execute();
Any idea why the Symfony ldap query fails when all its options should be identical to those I used for the bare php query?
I reposted this question on the Symfony github. #ChadSikorra was there too. And he made it clear what my issue was. Here's his explanation:
If you look at the collection class, nothing is done with the result
resource until initialize() is called in the class. If you do
return array('output' => array('bare' => $bare, 'symfony' =>
$symf->toArray())); it will call initialize and you'll see the
entries populated in the class. Unless there's something else going
on.
Do you still experience this issue with the latest 3.1+ versions?
Sorry but I don't go very often on Stack Overflow and spend most of my time on Github so I didn't see your question before.
As #ChadSikorra said, you should be using the toArray() method of the resulting Collection class, or you should iterate on the results directly.
The implementation is made so that the results are traversed in a memory-efficient manner, without storing all the results in an array by default, but the toArray() method can do this for you. Behind the scenes,it actually converts the resulting itératif to an array using the appropriate PHP function (iterator_to_array).
By the way, there used to be some inconsistency between the iterator and the toArray() function call, but that has been fixed in recent versions.
Cheers!

how to print query in CakePHP

Actually,
I have written this code in AppController.php in CakePHP 2.2.2
class AppModel extends Model
{
function getLastQuery()
{
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
return $lastLog['query'];
}
}
I tried following code to print output query
echo $this->AssetModel->getLastQuery();
$this->render('sql');
Is any body know to the point solution for that....?
I use this in CakePHP 2.6.11 to print Queries from Model in browser
debug($this->YOURMODEL->getDataSource()->getLog(false, false)); exit;
Hi you can use the below line to put into your layout file
<?php echo $this->element('sql_dump'); ?>
this will print all running query running in current action.
You can also use cakephp debugkit plugin.

How to check if a YII app is running from a console or from browser?

I'm new to YII framework and i'd like to know if there's way to know/check if you are running from console or in a browser?
Thanks!
This reply is a bit late but there is a Yii-specific way to do this:
In Yii1 you can do:
if (Yii::app() instanceof CConsoleApplication)
In Yii2 that would be:
if (Yii::$app instanceof Yii\console\Application)
Hope that's useful to someone...
You should also be able to do:
echo get_class(Yii::app());
which will tell you what type of app you're in ...
Same way you would determine if a PHP application is being run in the console or not.
What is the canonical way to determine commandline vs. http execution of a PHP script?
check Yii::$app->id
when running from console Yii::$app->id = 'app-console'
when running from frontend (browser) Yii::$app->id = 'app-frontend'
The most efficient way seems to define in the root file index.php this line :
define ('WEBAPP', true)
Later you can check in any point the application
if (defined('WEBAPP')) {
echo "This is webapp";
} else {
echo "app was launched via console";
}
Checked in Yii 1.7
You can use
if(is_a(Yii::$app,'yii\console\Application'))
for console, and
if(is_a(Yii::$app,'yii\web\Application'))
for web.
https://stackoverflow.com/a/30635800/4916039
I am using Yii 1 and I use this function to check
public static function isWebRequest()
{
return Yii::app() instanceof CWebApplication;
}
public static function isConsoleRequest()
{
return Yii::app() instanceof CConsoleApplication; //!self::isWebRequest();
}
I put these functions in a helper(Componenet) Class and I use it as:
if(MyRandomHelper::isConsoleRequest())
{
Email::shoot();
}

Drupal module development question relating to cookies and redirects

help please? I wish to develop a module to do something very simple with PHP. I am challenged by the Drupal API. I am using version 6.
Goal:
1) Determine if user is viewing a particular node (role is irrelevant)
2) If yes, check to see if cookie is set
a) If cookie is set, do nothing
b) If cookie is not set, then set cookie and then redirect user to another node
That's it!
I have created a module and installed it, there is no error yet it also does nothing. No cookie is set. I am not sure how the Drupal system likes to redirect requests so insight there would be helpful, please. THANK YOU SO MUCH!
<?php
//$Id: offer_survey.module,v 1.0 2009/09/21 11:31:55 blah Exp $
function offer_survey_init() {
global $base_url;
$offer_survey = true;
$cookie_name = 'survey_offered';
if ($node->nid == 651) {
if ($_COOKIE[$cookie_name]) {
// do nothing
} else {
setcookie($cookie_name,1,time() + (86400 * 365));
//then do the redirect an internal webform URL
}
}
}
REVISED VERSION (THE LATEST)
<?php
//$Id: offer_survey.module,v 1.0 2009/09/21 11:31:55 durz Exp $
function offer_survey_init() {
global $base_url;
$offer_survey = true;
$cookie_name = 'survey_offered';
if (arg(0) === "testing") { // the path of the page
if (!$_COOKIE[$cookie_name]) {
setcookie($cookie_name,1,time() + (86400 * 365));
drupal_goto('new-destination'); // the path to be redirected to
}
}
}
There are some different ways to go about this.
One option would be to used hook_nodeapi like jeremy suggests. Doing that you will have the node being loaded/viewed ect available as the $node variable. The other option would be to in your hook_init look at the $_GET and from that see if the user is requesting the node in question. Hook_nodeapi is probably the easiest way to go here.
You can as Jeremy said save data on the user object, however this is only possible if you user is logged in, as the user object otherwise will be the anonymous user which is the same for all not logged in users. In that case using a cookie could be an option. You have to take care though, as you have to create an per site unique cookie name. Else if this module was installed on several sites, users would not get surveys after visiting just one of them.
also in your code instead of doing:
if ($_COOKIE[$cookie_name]) {
// do nothing
} else {
setcookie($cookie_name,1,time() + (86400 * 365));
//then do the redirect an internal webform URL
}
You should instead use the ! (not) operator:
if (!$_COOKIE[$cookie_name]) {
setcookie($cookie_name,1,time() + (86400 * 365));
//then do the redirect an internal webform URL
}
Is your module called offer_survey?
Is it turned on?
Your code looks like it can't work as it uses a $node variable which is not defined.
I think you may have better luck using hook_nodeapi op=load
Once you have sorted these things out you may find drupal_goto is useful to redirect, and you can use user_save for persistent data rather than using set cookie directly.
This is the working code. Note that it was necessary to use arg(1) for the if() statement as well as the node id (nid) rather than hook_nodeapi which didn't work.
Also it was necessary to set the cookie_domain, which is a drupal global.
<?php
//$Id: offer_survey.module,v 1.0 2009/09/21 11:31:55 Stoob Exp $
function offer_survey_init() {
global $base_url;
global $cookie_domain;
$offer_survey = true;
$cookie_name = 'survey_offered';
if (arg(1) == 2) { // the number of the node (nid) of the page
if (!isset($_COOKIE[$cookie_name])) {
setcookie($cookie_name,1,time() + (86400 * 365),null,$cookie_domain); //lasts a year
drupal_goto('new/destination'); // the path to be redirected to
}
}
}
Unless your cache is off, hook_init() only runs on uncached requests. As soon as the cache kicks in your anonymous users will not get this cookie.
You need to put this in hook_boot() but then you can't use drupal_goto since when _boot() runs,that hasn't loaded yet. But that's okay, you can just use header() to set the Location redirect header directly.
It's a good idea to stop execution after a redirect (although you might lose session info if you don't let drupal do some cleanup, take a peek inside what drupal_goto does if you really want to do this right).
<?php
//$Id: offer_survey.module,v 1.1 2010/10/21 11:31:55 tmcclure Exp $
function offer_survey_boot() {
global $base_url;
global $cookie_domain;
$offer_survey = true;
$cookie_name = 'survey_offered';
if (arg(1) == 2) { // the number of the node (nid) of the page
if (!isset($_COOKIE[$cookie_name])) {
setcookie($cookie_name,1,time() + (86400 * 365),null,$cookie_domain); //lasts a year
header('Location: '.$base_url.'/new/destination',TRUE,302); // the path to be redirected to
exit();
}
}
}