I've a little problem with my console. When I use choice method from Laravel Console, the output totally breaks down. I wanted to google this but I can't find any solution. It's really annoying.
Anyone know how to fix this?
I'm using Git Bash provided by Git for Windows.
That Git bash is an emultion of unix console and it makes me able to use unix like commands. I don't want to stop using this.
Here is the console output
Give your group a name:
Something
Give your group a description (blank for skip):
>
Do you want to assign scopes to your new group? (y/n):
y
Select existing scope name: [0] Random [1] Exit (It's not a
scope)
0 0?[K
?[32mSelect existing scope name?[39m: [?[33m0?[39m] Random
[?[33m1?[39m] Exit (It's not a scope)
>
And the php code as below.
$name = $this->ask('Give your group a name');
$description = $this->ask('Give your group a description (blank for skip)');
$groups = app()->make(ScopeGroupRepository::class);
/** #var ScopeGroup $group */
$group = $groups->perform(new Create($name, $description));
$willCreateScopes = $this->answerToBoolean(
$this->ask('Do you want to assign scopes to your new group? (y/n)')
);
if(!$willCreateScopes) {
return $this->displayCreatedGroupInfo($group);
}
$scopes = app()->make(ScopeRepository::class);
/** #var Collection $unassigned */
$unassigned = $scopes->perform((new ShowAllUnassignedToGroup())->setGroupId($group->id));
if($willCreateScopes) {
do {
$scopes = $unassigned->map(function (Scope $scope){
return $scope->id;
})->toArray();
array_push($scopes, 'Exit (It\'s not a scope)');
// Here it breaks down
$selected = $this->choice('Select existing scope name', $scopes);
} while($selected !== 'Exit (It\'s not a scope)');
}
Thanks for help.
Related
I need to schedule a few tasks on an application built using Laravel and I would like to send a slack notification after those tasks are finished with the output.
Laravel provides an "after" hook (https://laravel.com/docs/5.8/scheduling#task-hooks) so I can do something like this:
$schedule->command('mycommand')
->daily()
->after(function () {
// How can I access the command's name and output from here?
});
I've tried with $this->output but $this points to App\Console\Kernel and it says Undefined property: App\Console\Kernel::$output. I've also tried to pass a parameter to the closure, but I think I need to specify a type, but I have no idea and the documentation is not very clear.
Anyone has any idea on how to do this?
Thanks in advance!
Assuming you have this in your command
$this->info('hello');
In your kernel, you can send the output to a temporary file and then read the file and send it
/** #var \Illuminate\Console\Scheduling\Event $command */
$command = $schedule->command('mycommand')
->daily()
->sendOutputTo('storage/app/logs.txt');
$command->after(function () use ($command) {
\Log::debug([$command->command, $command->output]);
\Log::debug(file_get_contents($command->output));
});
You will get
[2019-10-11 13:03:38] local.DEBUG: array (
0 => '\'/usr/bin/php7.3\' \'artisan\' command:name',
1 => 'storage/app/logs.txt',
)
[2019-10-11 13:03:38] local.DEBUG: hello
Maybe it would be the time to re-open this proposal https://github.com/laravel/ideas/issues/122#issuecomment-228215251
What kind of output does your command generate? is it command line or is just a variable you're trying to pass to the after()?
Alternativly in your handle() method of the command you can call the desired command after all the code has been excuted, you can even pass a parameter to the command.
You can do that by using Artisan
Artisan::call('*command_name_here*');
I'm currently working on some automation things in WHMCS. I've several custom products available in WHMCS:
Linux product 1
Linux product 2
Windows product 1
Windows product 2
I want to execute a bash script when an order accept and when the service terminate from the WHMCS. The script require an argument (IP address) which is a custom field for the above products. The script should fetch this custom field data containing IP address, and compare the products whether it is Linux or Windows and then pass it to the script as follows:
If the product is a Linux one, then the script pass would be like "autoaccept.sh linux [IP]"
If the product is Windows one, then the script call would be like "autoaccept.sh windows [IP]"
Similar way, when the package terminate on WHMCS we have to call the script again with "autoterminate.sh [IP]"
The WHMCS AcceptOrder and AfterModuleTerminate hook can be used I guess. But not sure how we can fetch these custom field data and compare the products within hook PHP code there. Can anyone shed some light on this or help our me to code this correctly.
Any responses would be much appreciated!
Created the Bash scripts already, and is working perfectly. I'm new to WHMCS hook and PHP things, so stucked here.
Use Product Modules: Product Module and implement the method _CreateAccount($params), You can find 'CustomFields' in $params Variable.
Here is example to executes python script:
<?php
function my_proc_execute($cmd)
{
$output='';
try
{
$descriptorspec = array(
0 => array("pipe", "r"), //STDIN
1 => array("pipe", "w"), //STDOUT
2 => array("pipe", "w"), //STDERR
);
$cwd = getcwd(); $env = null; $proc = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
$buffer=array();
if(is_resource($proc))
{
fclose($pipes[0]);
stream_set_blocking($pipes[1], 1);
stream_set_blocking($pipes[2], 1);
stream_set_timeout($pipes[1],500);
stream_set_timeout($pipes[2],500);
while (!feof($pipes[1]))
{
$line = fread($pipes[1], 1024);
if(!strlen($line))continue;
$buffer[]=$line;
}
while(!feof($pipes[2]))
{
$line=fread($pipes[2], 1024);
if(!strlen($line))continue;
$buffer[]=$line;
}
$output=implode($buffer);
fclose($pipes[1]);fclose($pipes[2]);
$return_value = proc_close($proc);
}
else $output = "no resource; cannot open proc...";
}catch(Exception $e){$output = $e->getMessage();}
return $output;
}
function mymodule_CreateAccount($params)
{
$myData=$params['customfields']['the_name_of_field'];
$to_send_arr=array();
$to_send_arr['is_new']='0';
$to_send_arr['id']='xyz';
$to_send_arr['url']='my';
$to_send_arr['display_name']=$myData;
$exewin="c:/Python27/python.exe C:/xampp_my/htdocs/my/modules/servers/xxx/pyscripts/create_data.py";
$exelinux="/var/www/html/modules/servers/xxx/pyscripts/create_data.py";
$command=$exewin . ' ' . escapeshellcmd(base64_encode(json_encode($to_send_arr)));
$output=my_proc_execute($command);
$arr=json_decode($output,true);
}
?>
Python
import sys
import json
import time
import base64
if len(sys.argv) != 2:
print 'Error in the passed parameters for Python script.', '<br>'
sys.exit()
json_data = json.loads(base64.b64decode(sys.argv[1]))
id= json_data['id']
here is a part of my perl cgi script (which is working..):
use Net::LDAP;
use Net::LDAP::Entry;
...
$edn = "DC=xyz,DC=com";
$quser ="(&(objectClass=user)(cn=$username))";
$ad = Net::LDAP->new("ip_address...");
$ldap_msg=$ad->bind("$username\#xyz.com", password=>$password);
my $result = $ad->search( base=>$edn,
scope=>"sub",
filter=>$quser);
my $entry;
my $myname;
my $emailad;
my #entries = $result->entries;
foreach $entry (#entries) {
$myname = $entry->get_value("givenName");
$emailad = $entry->get_value("mail");
}
So basically, there is no admin/manager account for AD, users credentials are used for binding. I need to implement the same thing in grails..
+Is there a way to configure the plugin to search several ADs, I know I can add more ldap IPs in context.server but for each server I need a different search base...
++ I dont wanna use my DB, just AD. User logins through ldap > I get his email, and use the email for another ldap query but that will probably be another topic :)
Anyway the code so far is:
grails.plugin.springsecurity.ldap.context.managerDn = ''
grails.plugin.springsecurity.ldap.context.managerPassword = ''
grails.plugin.springsecurity.ldap.context.server = 'ldap://address:389'
grails.plugin.springsecurity.ldap.authorities.ignorePartialResultException = true
grails.plugin.springsecurity.ldap.search.base = 'DC=xyz,DC=com'
grails.plugin.springsecurity.ldap.authenticator.useBind=true
grails.plugin.springsecurity.ldap.authorities.retrieveDatabaseRoles = false
grails.plugin.springsecurity.ldap.search.filter="sAMAccountName={0}"
grails.plugin.springsecurity.ldap.search.searchSubtree = true
grails.plugin.springsecurity.ldap.auth.hideUserNotFoundExceptions = false
grails.plugin.springsecurity.ldap.search.attributesToReturn =
['mail', 'givenName']
grails.plugin.springsecurity.providerNames=
['ldapAuthProvider',anonymousAuthenticationProvider']
grails.plugin.springsecurity.ldap.useRememberMe = false
grails.plugin.springsecurity.ldap.authorities.retrieveGroupRoles = false
grails.plugin.springsecurity.ldap.authorities.groupSearchBase ='DC=xyz,DC=com'
grails.plugin.springsecurity.ldap.authorities.groupSearchFilter = 'member={0}'
And the error code is: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1
And it's the same code for any user/pass I try :/
Heeeeelp! :)
The most important thing with grails and AD is to use ActiveDirectoryLdapAuthenticationProvider rather than LdapAuthenticationProvider as it will save a world of pain. To do this, just make the following changes:
In resources.groovy:
// Domain 1
ldapAuthProvider1(ActiveDirectoryLdapAuthenticationProvider,
"mydomain.com",
"ldap://mydomain.com/"
)
// Domain 2
ldapAuthProvider2(ActiveDirectoryLdapAuthenticationProvider,
"mydomain2.com",
"ldap://mydomain2.com/"
)
In Config.groovy:
grails.plugin.springsecurity.providerNames = ['ldapAuthProvider1', 'ldapAuthProvider2']
This is all the code you need. You can pretty much remove all other grails.plugin.springsecurity.ldap.* settings in Config.groovy as they don't apply to this AD setup.
Documentation:
http://docs.spring.io/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ldap-active-directory
I have a client who needs a website urgently, but I have no access to information such as the control panel.
PHP Version is 4.4 Which is a pain as I'm used to 5.
The first problem is I keep getting:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ')' in D:\hshome\*******\********\includes\functions.php on line 37
This is the function in question:
function read_rss($display=0,$url='') {
$doc = new DOMDocument();
$doc->load($url);
$itemArr = array();
foreach ($doc->getElementsByTagName('item') as $node) {
if ($display == 0) {
break;
}
$itemRSS = array(
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
'description'=>$node->getElementsByTagName('description')->item(0)->nodeValue,
'link'=>$node->getElementsByTagName('link')->item(0)->nodeValue);
array_push($itemArr, $itemRSS);
$display--;
}
return $itemArr;
}
And the line in question:
'title'=>$node->getElementsByTagName('title')->item(0)->nodeValue,
PHP4 does not support object dereferencing. So $obj->something()->something will not work. You need to do $tmp = $obj->something(); $tmp->something...
You can't do that in PHP 4.
Have to do something like
$nodes = $node->getElementsByTagName('title');
$item = $nodes->item(0);
$value = $item->nodeValue,
Try it and it will work.
You can't chain object calls in PHP 4. You're going to have to make each call separately to a variable and store it all.
$titleobj = $node->getElementsByTagName('title');
$itemobj = $titleobj->item(0);
$value = $itemobj->nodeValue;
...
'title'=>$value,
you'll have to do it on all those chained calls
As for .htaccess ... you need to talk to someone who controls the actual server. It sounds like .htaccess isn't allowed to change the setting you're trying to change.
You need to break down that line into individual variables. PHP 4 does not like -> following parentheses. Do this instead:
$title = $node->getElementsByTagName('title');
$title = $title->item(0);
$description = $node->getElementsByTagName('description');
$description = $description->item(0);
$link = $node->getElementsByTagName('link');
$link = $link->item(0);
$itemRSS = array(
'title'=>$title->nodeValue,
'description'=>$description->nodeValue,
'link'=>$link->nodeValue);
The two variable declarations for each may be redundant and condensed, I'm not sure how PHP4 will respond. You can try to condense them if you want.
DOMDocument is php 5 function.You cant use it.
you may need to use DOM XML (PHP 4) Functions
I am struggling to get control of an IE preview control which is 'Internet Explorer_Server' class on an external windows application with perl.
Internet Explorer_Server is the class name of the window, I've found it with Spy++. and here’s my assertion code of it
$className = Win32::GUI::GetClassName($window);
if ($className eq "Internet Explorer_Server") {
...
}
I can get a handle of that 'Internet Explorer_Server' with Win32::GUI::GetWindow, but have no idea what to do next.
Updated: You are going down the wrong path. What you need is Win32::OLE.
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE;
$Win32::OLE::Warn = 3;
my $shell = get_shell();
my $windows = $shell->Windows;
my $count = $windows->{Count};
for my $item ( 1 .. $count ) {
my $window = $windows->Item( $item );
my $doc = $window->{Document};
next unless $doc;
print $doc->{body}->innerHTML;
}
sub get_shell {
my $shell;
eval {
$shell = Win32::OLE->GetActiveObject('Shell.Application');
};
die "$#\n" if $#;
return $shell if defined $shell;
$shell = Win32::OLE->new('Shell.Application')
or die "Cannot get Shell.Application: ",
Win32::OLE->LastError, "\n";
}
__END__
So, this code finds a window with a Document property and prints the HTML. You will have to decide on what criteria you want to use to find the window you are interested in.
ShellWindows documentation.
You may want to have a look at Win32::IE::Mechanize. I am not sure whether you can control an existing IE window with this module, but accessing a single URL should be possible in about five lines of code.
Have you looked at Samie http://samie.sourceforge.net/ as this is a perl module to control IE