I exploited the last days, but I wasn't able to find a real useful tutorial to intigrate LDAP Authentication into a vTiger CRM 6 (running on a Linux CentOS 6.5 distribution).
Any one experienced out here or some people who might share some useful manuals ?
Make directory into your crm destination:
/var/www/html/crm/modules/Users/authTypes/
Then, Download the ldap file from :
http://downloads.sourceforge.net/project/adldap/adLDAP/adLDAP_4.0.4/adLDAP_4.0
Just open and customize the settings for your needs. The following settings match those needed for a 2012R2 Active Directory.
...
class adLDAP {
/**
* Define the different types of account in AD
*/
const ADLDAP_NORMAL_ACCOUNT = 805306368;
const ADLDAP_WORKSTATION_TRUST = 805306369;
const ADLDAP_INTERDOMAIN_TRUST = 805306370;
const ADLDAP_SECURITY_GLOBAL_GROUP = 268435456;
const ADLDAP_DISTRIBUTION_GROUP = 268435457;
const ADLDAP_SECURITY_LOCAL_GROUP = 536870912;
const ADLDAP_DISTRIBUTION_LOCAL_GROUP = 536870913;
const ADLDAP_FOLDER = 'OU';
const ADLDAP_CONTAINER = 'CN';
/**
* The default port for LDAP non-SSL connections
*/
const ADLDAP_LDAP_PORT = '389';
/**
* The default port for LDAPS SSL connections
*/
const ADLDAP_LDAPS_PORT = '636';
/**
* The account suffix for your domain, can be set when the class is invoked
*
* #var string
*/
protected $accountSuffix = "#cortoso.com";
/**
* The base dn for your domain
*
* If this is set to null then adLDAP will attempt to obtain this automatically from the rootDSE
*
* #var string
*/
protected $baseDn = "";
/**
* Port used to talk to the domain controllers.
*
* #var int
*/
protected $adPort = self::ADLDAP_LDAP_PORT;
/**
* Array of domain controllers. Specifiy multiple controllers if you
* would like the class to balance the LDAP queries amongst multiple servers
*
* #var array
*/
protected $domainControllers = array("dc01.cortoso.com", "dc02.cortoso.com");
/**
* Optional account with higher privileges for searching
* This should be set to a domain admin account
*
* #var string
* #var string
*/
protected $adminUsername = "ldap-binduser";
protected $adminPassword = "super-password";
/**
* AD does not return the primary group. http://support.microsoft.com/?kbid=321360
* This tweak will resolve the real primary group.
* Setting to false will fudge "Domain Users" and is much faster. Keep in mind though that if
* someone's primary group is NOT domain users, this is obviously going to mess up the results
*
* #var bool
*/
protected $realPrimaryGroup = false;
/**
* Use SSL (LDAPS), your server needs to be setup, please see
* http://adldap.sourceforge.net/wiki/doku.php?id=ldap_over_ssl
*
* #var bool
*/
protected $useSSL = false;
/**
* Use TLS
* If you wish to use TLS you should ensure that $useSSL is set to false and vice-versa
*
* #var bool
*/
protected $useTLS = true;
/**
* Use SSO
* To indicate to adLDAP to reuse password set by the brower through NTLM or Kerberos
*
* #var bool
*/
protected $useSSO = false;
/**
* When querying group memberships, do it recursively
* eg. User Fred is a member of Group A, which is a member of Group B, which is a member of Group C
* user_ingroup("Fred","C") will returns true with this option turned on, false if turned off
*
* #var bool
*/
protected $recursiveGroups = true;
...
?>
To be able to test adLDAP, it is much easier to write a small php sniplet than doing it directly with vTiger CRM. Just create a small adldap_test.php file, in the same directory where adLDAP.php resides, with following content:
<?php
require_once(dirname(FILE) . '/adLDAP.php');
try {
$adldap = new adLDAP();
}
catch (adLDAPException $e) {
echo $e;
exit();
}
$authUser = $adldap->authenticate('user-to-authenticate', 'users-password');
if ($authUser == true) {
echo "User authenticated successfully";
}
else {
// getLastError is not needed, but may be helpful for finding out why:
echo "\n";
echo $adldap->getLastError();
echo "\n";
echo "User authentication unsuccessful";
}
echo "\n";
$result=$adldap->user()->infoCollection('ldap', array("*"));
echo "User:\n";
echo $result->displayName;
echo "Mail:\n";
echo $result->mail;
?>
Related
I generated flag link
$flag_link = [
'#lazy_builder' => ['flag.link_builder:build', [
$product->getEntityTypeId(),
$product->id(),
'product_like',
]],
'#create_placeholder' => TRUE,
];
Flag link is generated successfully. But while I click flag link , I got error message as response
{message: "'csrf_token' URL query argument is invalid."}
message: "'csrf_token' URL query argument is invalid."
I found a temporary solution. Not sure if this is a bug in Flag that needs to be addressed by the module maintainers, or if this is working as intended, since this is a REST response, and not a typical Drupal call for a view or display mode.
In the ModuleRestResource.php file (In my case, the ModuleRestResource.php file is located at:
{{DRUPAL_ROOT}}/web/modules/custom/{{Module_Name}}/src/Plugin/rest/resource/{{Module_Name}}RestResource.php):
use Drupal\rest\ModifiedResourceResponse;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Entity\EntityInterface;
use Drupal\flag\FlagService;
use Drupal\Core\Render\RenderContext;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class ModuleRestResource extends ResourceBase {
/**
* A current user instance.
*
* #var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* #var $entityTypeManager \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* #var \Drupal\flag\FlagService
*/
protected $flagService;
/**
* #var Drupal\Core\Access\CsrfTokenGenerator
*/
protected $csrfService;
/**
* {#inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->logger = $container->get('logger.factory')->get('module');
$instance->currentUser = $container->get('current_user');
$instance->entityTypeManager = $container->get('entity_type.manager');
$instance->flagService = $container->get('flag');
$instance->csrfService = $container->get('csrf_token');
return $instance;
}
/**
* Responds to GET requests.
*
* #param string $payload
*
* #return \Drupal\rest\ResourceResponse
* The HTTP response object.
*
* #throws \Symfony\Component\HttpKernel\Exception\HttpException
* Throws exception expected.
*/
public function get($payload) {
// You must to implement the logic of your REST Resource here.
// Use current user after pass authentication to validate access.
if (!$this->currentUser->hasPermission('access content')) {
throw new AccessDeniedHttpException();
}
if (!is_numeric($payload)) {
throw new BadRequestHttpException();
}
/*
* This is the object that will be returned with the node details.
*/
$obj = new \stdClass();
// First load our node.
/**
* #var \Drupal\Core\Entity\EntityInterface
*/
$node = $this->entityTypeManager->getStorage('node')->load($payload);
/**
* FIX STARTS HERE !!!!!
*/
/**
* Because we are rending code early in the process, we need to wrap in executeInRenderContext
*/
$render_context = new RenderContext();
$fl = \Drupal::service('renderer')->executeInRenderContext($render_context, function() use ($node, $payload) {
/**
* Get the flag we need and check if the selected node has been flagged by the current user
*
* Set the path to create a token. This is the value that is missing by default that creates an
* invalid CSRF Token. Important to note that the leading slash should be left off for token generation
* and then added to to the links href attribute
*
*/
$flag = $this->flagService->getFlagById('bookmark');
$is_flagged = (bool) $this->flagService->getEntityFlaggings($flag, $node, \Drupal::currentUser() );
$path = 'flag/'. ($is_flagged ? 'un' : '') .'flag/bookmark/' . $node->id();
$token = $this->csrfService->get($path);
$flag_link = $flag->getLinkTypePlugin()->getAsFlagLink($flag, $node);
$flag_link['#attributes']['href'] = '/' . $path . '?destination&token=' . $token;
/**
* Render the link into HTML
*/
return \Drupal::service('renderer')->render($flag_link);
});
/**
* This is required to bubble metadata
*/
if (!$render_context->isEmpty()) {
$bubbleable_metadata = $render_context->pop();
\Drupal\Core\Render\BubbleableMetadata::createFromObject($fl)
->merge($bubbleable_metadata);
}
/*
* !!!!! FIX ENDS HERE !!!!!
*/
$obj->flag_link = $fl;
return new ResourceResponse((array)$obj, 200);
}
}
Anyone who can get module maintainers to address this would be nice.
I've created successfully a BE user in an own extension for TYPO3 CMS 8.7.0.
Repository Injection:
/**
* beUserRepository
*
* #var \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository
* #inject
*/
protected $beUserRepository = null;
Part of the ActionController:
$beuser = new \TYPO3\CMS\Extbase\Domain\Model\BackendUser();
$beuser->setUserName($username);
$beuser->setEmail($email);
$beuser->setRealName($realname);
$this->beUserRepository->add($beuser);
This works fine but I can't add a password like for FE users with setPassword(). Is there any way to get there or is it restricted for security reasons to set/change a BE user password?
Create your own BackendUser model in your extension
<?php
namespace YourVendor\YourExtKey\Domain\Model;
class BackendUser extends \TYPO3\CMS\Extbase\Domain\Model\BackendUser
{
/**
* #var string
*/
protected $password = '';
/**
* Returns the password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Sets the password
*
* #param string $password
* #return void
*/
public function setPassword($password)
{
$this->password = (string)$password;
}
}
Create your own Repository
<?php
namespace YourVendor\YourExtKey\Domain\Repository;
class BackendUserRepository extends \TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository
{
}
Then map your new domain model to be_users table:
plugin.tx_yourExtKey {
persistence {
classes {
YourVendor\YourExtKey\Domain\Model\BackendUser {
mapping {
tableName = be_users
}
}
}
}
}
Update your controller to use your new Repository
/**
* beUserRepository
*
* #var \YourVendor\YourExtKey\Domain\Repository\BackendUserRepository
* #inject
*/
protected $beUserRepository;
Back in your action
$beUser = new \YourVendor\YourExtKey\Domain\Model\BackendUser();
$saltFactory = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance('', 'BE');
$beUser->setPassword($saltFactory->getHashedPassword($newPassword));
TYPO3\CMS\Extbase\Domain\Model\BackendUser does not have a password property, so you can not set a password without extending the model. The easiest way would be if you create an own BackendUser model in your extension that extends the TYPO3\CMS\Extbase\Domain\Model\BackendUser and configure the mapping in TS. It just needs to have the $password property with getters/setters and a repository.
Can somebody please provide PHP examples for ordering the following security products using SoftLayer API:
SSL certificate
Hardware Firewall ( to devices and to VLANS)
FortiGate Seucirty Applicace ( to VLANs)
Security Software
To order Security Software on device, the customer portal checks if there's any eligible device. What kind of devices are eligible for Security Software ? What SoftLayer API I can use to find those eligible devices ?
Thank you.
I hope these php scripts can help you:
Order SSL Certificates
<?php
/**
* Order SSL certificate
*
* This script orders a SSL Certificate
*
* Important manual pages:
* #see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
* #see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order
* #see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Security_Certificate
*
* #license <http://sldn.softlayer.com/wiki/index.php/license>
* #author SoftLayer Technologies, Inc. <sldn#softlayer.com>
*/
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/XmlrpcClient.class.php";
/**
* Your SoftLayer API username
* #var string
*/
$username = "set me";
/**
* Your SoftLayer API key
* Generate one at: https://control.softlayer.com/account/users
* #var string
*/
$apiKey = "set me";
// Create a SoftLayer API client object for "SoftLayer_Product_Order" services
$productService = Softlayer_XmlrpcClient::getClient("SoftLayer_Product_Order", null, $username, $apiKey);
/**
* Define SSL Certificates Properties
* #var int $quantity
* #var int $packageId
* #var int $serverCount
* #var int $validityMonths
* #var string $orderApproverEmailAddress
* #var string $serverType
*/
$quantity = 1;
$packageId = 210;
$serverCount = 1;
$validityMonths = 24;
$serverType = "apache2";
$orderApproverEmailAddress = "admin#rubtest.com";
/**
* Build a skeleton SoftLayer_Container_Product_Order_Attribute_Contact object for administrativeContact,
* billingContact, technicalContact and organizationInformation properties. You can use the same information
* for all of these properties, or you can create this object for each one.
* #var string addressLine1
* #var string city
* #var string countryCode
* #var string postalCode
* #var string state
* #var string email
* #var string firstName
* #var string lastName
* #var string organizationName
* #var string phoneNumber
* #var string title
*/
$addressInfo = new stdClass();
$addressInfo -> address = new stdClass();
$addressInfo -> address -> addressLine1 = "Simon Lopez Av.";
$addressInfo -> address -> city = "Cochabamba";
$addressInfo -> address -> countryCode = "BO";
$addressInfo -> address -> postalCode = "0591";
$addressInfo -> address -> state = "OT";
$addressInfo -> emailAddress = "noreply#softlayer.com";
$addressInfo -> firstName = "Ruber";
$addressInfo -> lastName = "Cuellar";
$addressInfo -> organizationName = "TestCompany";
$addressInfo -> phoneNumber = "7036659886";
$addressInfo -> title = "TitleTest";
/**
* Define a collection of SoftLayer_Product_Item_Price objects. You can verify the item available for a given package using
* SoftLayer_Product_Package::getItemPrices method
* #see http://sldn.softlayer.com/reference/services/SoftLayer_Product_Package/getItemPrices
*/
$price = new stdClass();
$price->id = 1836;
/**
* Declare the CSR
* #var string
*/
$certificateSigningRequest = "-----BEGIN CERTIFICATE REQUEST-----
MIIC8TCCAdkCAQAwgasxCzAJBgNVBAYTAkNaMR8wHQYDVQQIExZDemVjaCBSZXB1
YmxpYywgRXVyb3BlMRQwEgYDVQQHEwtQcmFndWUgQ2l0eTEWMBQGA1UEChMNTXkg
VW5saW1pbnRlZDEMMAoGA1UECxMDVlBOMRQwEgYDVQQDEwtydWJ0ZXN0LmNvbTEp
MCcGCSqGSIb3DQEJARYacnViZXIuY3VlbGxhckBqYWxhc29mdC5jb20wggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDnusRc9LDjfm21A/fz1UhuMoUqkeji
BX/oTXsD/GmRaraOb0QnzjGoaM2K07nMENpQiJRpmEj3tEKwAXNitlapLwlXFvB7
rVd9lkvGmCIEkkDp5nbsdejS7BqJ8ikgEI+HATmdoyi9jxWrM/i6c9pnhF4j9ejI
XQnxd3yvpuxgybF3tN+HOOpXwVH4FQC7x/FRRai8jNxd2f+VzW7EgtIYxgl3L8gr
4DPPAAiX07lEAccEEUhQ3/LbTlSPiT0hiGh8tMcImYFDDyGOIRJKXSptuvYgwHRC
67D6fzT4ITtG2XMkzo5kgyZtwemRiikAzVbmtEFKwht0j0Q+3nf1Yv2BAgMBAAGg
ADANBgkqhkiG9w0BAQUFAAOCAQEAJCRjsdmVhcM+mKbG8NE4YdDyBfKvC03g/mCn
wWZWca1uRbYeJUNH2/LFy9tQ/8J07Cx0KcPmRnHbXkZaSMHsorv4sg6M3XDRaIiu
D/ltOZYlGYC1zFVM+pgiQd84krO0lTf/NiJxyyL3e3owO91h07jPuGGFygSOeKZa
cMMNdLQlPfZIS+hwZUuJSgormGhr+dfPkHbjP3l3X+uO59VNE+1zHTctCqooyCRa
HrHFjNbVD4Ou7Ff6B0LUiw9I54jH69MrtxdrsF+kvOaa44fN1NjqlM1sI4ZQs0O1
15B5NKrFMxG+5BrZYL7n8qEzra7WYFVrebjKexQqSBi4B6XU+g==
-----END CERTIFICATE REQUEST-----";
/*
* Build a skeleton SoftLayer_Container_Product_Order object with details required to order
*/
$container = new stdClass();
$container -> complexType = "SoftLayer_Container_Product_Order_Security_Certificate";
$container -> packageId = $packageId;
$container -> quantity = $quantity;
$container -> serverCount = $serverCount;
$container -> serverType = $serverType;
$container -> prices = array($price);
$container -> certificateSigningRequest = $certificateSigningRequest;
$container -> validityMonths = $validityMonths;
$container -> orderApproverEmailAddress = $orderApproverEmailAddress;
// technicalContact, administrativeContact, organizationInformation and billingContact
$container -> technicalContact = $addressInfo;
$container -> administrativeContact = $addressInfo;
$container -> organizationInformation = $addressInfo;
$container -> billingContact = $addressInfo;
$order = new stdClass();
$order->orderContainers = array();
$order->orderContainers[0] = $container;
try {
/*
* SoftLayer_Product_Order::verifyOrder() method will check your order for errors. Replace this with a call
* to placeOrder() when you're ready to order. Both calls return a receipt object that you can use for your
* records.
*/
$result = $productService -> verifyOrder($order);
print_r($result);
} catch(Exception $e) {
echo "Unable to order SSL Certificates: " . $e -> getMessage();
}
Order Firewall Device
<?php
/**
* Order dedicated Firewall for a Device (Virtual Guest)
* Important manual pages:
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
*
* License <http://sldn.softlayer.com/article/License>
* Author SoftLayer Technologies, Inc. <sldn#softlayer.com>
*/
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/SoapClient.class.php";
/**
* Your SoftLayer API username
* #var string
*/
$username = "set me";
/**
* Your SoftLayer API key
* Generate one at: https://control.softlayer.com/account/users
* #var string
*/
$apiKey = "set me";
// Define the virtual guest Id that you wish to add the firewall
$virtualGuestId = 5074554;
// Creating a SoftLayer API client object
$softLayerProductOrder = SoftLayer_SoapClient::getClient('SoftLayer_Product_Order', null, $username, $apiKey);
/**
* Building a skeleton SoftLayer_Product_Item_Price objects. These objects contain
* much more than ids, but SoftLayer's ordering system only needs the price's id
* to know what you want to order.
* to get the list of valid prices for the package
* use the SoftLayer_Product_Package:getItems method
*/
$prices = array
(
409, # Price to 100Mbps Hardware Firewall
);
/**
* Convert our item list into an array of skeleton
* SoftLayer_Product_Item_Price objects.
*/
$orderPrices = array();
foreach ($prices as $priceId){
$price = new stdClass();
$price->id = $priceId;
$orderPrices[] = $price;
}
// Define location, packageId and quantity
$location = "AMSTERDAM";
$packageId = 0; // The package Id for order monitoring packages is 0
$quantity = 1;
// Build a skeleton SoftLayer_Virtual_Guest object to model the id
// of the virtual guest where you want add the monitoring package
$virtualGuests = new stdClass();
$virtualGuests->id = $virtualGuestId;
$orderVirtualGuest = array
(
$virtualGuests
);
// Build a SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated object containing
// the order you wish to place.
$orderContainer = new stdClass();
$orderContainer->location = $location;
$orderContainer->packageId = $packageId;
$orderContainer->prices = $orderPrices;
$orderContainer->quantity = $quantity;
$orderContainer->virtualGuests = $orderVirtualGuest;
try {
// Re-declare the order template as a SOAP variable, so the SoftLayer
// ordering system knows what type of order you're placing.
$orderTemplate = new SoapVar
(
$orderContainer,
SOAP_ENC_OBJECT,
'SoftLayer_Container_Product_Order_Network_Protection_Firewall',
'http://api.service.softlayer.com/soap/v3.1/'
);
/*
* SoftLayer_Product_Order::verifyOrder() method will check your order for errors. Replace this with a call
* to placeOrder() when you're ready to order. Both calls return a receipt object that you can use for your
* records.
*/
$receipt = $softLayerProductOrder->verifyOrder($orderTemplate);
print_r($receipt);
} catch (Exception $e) {
echo 'Unable to order the firewall for device: ' . $e->getMessage();
}
Firewall for VLAN
<?php
/**
* Order Firewall for a VLAN
* Important manual pages:
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated
* http://sldn.softlayer.com/reference/datatypes/SoftLayer_Product_Item_Price
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/verifyOrder
* http://sldn.softlayer.com/reference/services/SoftLayer_Product_Order/placeOrder
*
* License <http://sldn.softlayer.com/article/License>
* Author SoftLayer Technologies, Inc. <sldn#softlayer.com>
*/
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/SoapClient.class.php";
/**
* Your SoftLayer API username
* #var string
*/
$username = "set me";
/**
* Your SoftLayer API key
* Generate one at: https://control.softlayer.com/account/users
* #var string
*/
$apiKey = "set me";
// Create a SoftLayer API client object for "SoftLayer_Product_Order" services
$softLayerProductOrder = Softlayer_SoapClient::getClient("SoftLayer_Product_Order", null, $username, $apiKey);
// Declare the vlan id that you wish to add the firewall
$vlanId = 765032;
/**
* Building a skeleton SoftLayer_Product_Item_Price objects. These objects contain
* much more than ids, but SoftLayer's ordering system only needs the price's id
* to know what you want to order.
* to get the list of valid prices for the package
* use the SoftLayer_Product_Package:getItemPrices method
*/
$prices = array
(
2390, // Hardware Firewall (Dedicated)
//21514, FortiGate Security Appliance
);
/**
* Convert our item list into an array of skeleton
* SoftLayer_Product_Item_Price objects.
*/
$orderPrices = array();
foreach ($prices as $priceId){
$price = new stdClass();
$price->id = $priceId;
$orderPrices[] = $price;
}
// Declare the location, packageId and quantity
$location = "AMSTERDAM";
$packageId = 0; // The package Id for order Firewalls
$quantity = 1;
// Build a SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated object containing
// the order you wish to place.
$orderContainer = new stdClass();
$orderContainer->location = $location;
$orderContainer->packageId = $packageId;
$orderContainer->prices = $orderPrices;
$orderContainer->quantity = $quantity;
$orderContainer-> vlanId = $vlanId;
try {
// Re-declare the order template as a SOAP variable, so the SoftLayer
// ordering system knows what type of order you're placing.
$orderTemplate = new SoapVar
(
$orderContainer,
SOAP_ENC_OBJECT,
'SoftLayer_Container_Product_Order_Network_Protection_Firewall_Dedicated',
'http://api.service.softlayer.com/soap/v3/'
);
/*
* SoftLayer_Product_Order::verifyOrder() method will check your order for errors. Replace this with a call
* to placeOrder() when you're ready to order. Both calls return a receipt object that you can use for your
* records.
*/
$receipt = $softLayerProductOrder->verifyOrder($orderTemplate);
print_r($receipt);
} catch (Exception $e) {
echo 'Unable to place the order: ' . $e->getMessage();
}
Order Security Software (Anti Virus)
<?php
/**
* Purchase an Anti-virus for a server
*
* Important manual pages:
* #see http://sldn.softlayer.com/reference/services/SoftLayer_Ticket
* #see http://sldn.softlayer.com/reference/services/SoftLayer_Ticket/createUpgradeTicket
*
* #license <http://sldn.softlayer.com/wiki/index.php/license>
* #author SoftLayer Technologies, Inc. <sldn#softlayer.com>
*/
require_once "C:/PhpSoftLayer/SoftLayer/SoftLayer/SoapClient.class.php";
/**
* Your SoftLayer API username
* #var string
*/
$username = "set me";
/**
* Your SoftLayer API key
* Generate one at: https://control.softlayer.com/account/users
* #var string
*/
$apiKey = "set me";
/**
* Define the hardware id where you wish to add the McAfee ANtivirus
* #var int $attachmentId
*/
$attachmentId = 251708;
// Define a brief description of what you wish to upgrade
$genericUpgrade = "Add / Upgrade Software";
//
$upgradeMaintenanceWindow = "9.30.2015 (Wed) 01:00(GMT-0600) - 04:00(GMT-0600)";
// Declare a detailed description of the server or account upgrade you wish to perform
$details ="I would like additional information on adding McAfee AntiVirus (5$.00 monthly) to my account.";
// Declare the attachmentType e.g. HARDWARE - VIRTUAL_GUEST - NONE
$attachmentType = "HARDWARE";
// Create a SoftLayer API client object for "SoftLayer_Ticket" service
$ticketService = SoftLayer_SoapClient::getClient("SoftLayer_Ticket", null, $username, $apiKey);
try {
$result = $ticketService -> createUpgradeTicket($attachmentId, $genericUpgrade, $upgradeMaintenanceWindow, $details, $attachmentType);
print_r($result);
} catch(Exception $e) {
echo "Unable to create the ticket: " . $e -> getMessage();
}
I created some examples for you, hopefully they are helpful :)
https://softlayer.github.io/php/orderSSLCert/
https://softlayer.github.io/php/orderFirewalls/
https://softlayer.github.io/php/orderFirewalls/
https://softlayer.github.io/php/orderBareMetal/
To add any security product to a server order, you just have to add the proper price ID to the order.
Anti-Virus is available on RedHat and Windows operating systems, while anti-malware and host IPS is only available on Windows. There are not really any programmatic ways of finding that out, other than trying to place an order and it being rejected.
I'm trying to setup single sign on for MediaWiki with ExtAuthDB extension. The purpose is to authenticate user from external user system automatically when user logins in the main website: www.mysite.com. Mediawiki is located on subdomain: www.wiki.mysite.com.
I have installed the extension as it said in the guide. All priviliges are correct. But it doesn't work.
ExtAuthDB.php is:
<?php
/**
* Authentication plugin interface. Instantiate a subclass of AuthPlugin
* and set $wgAuth to it to authenticate against some external tool.
*
* The default behavior is not to do anything, and use the local user
* database for all authentication. A subclass can require that all
* accounts authenticate externally, or use it only as a fallback; also
* you can transparently create internal wiki accounts the first time
* someone logs in who can be authenticated externally.
*
* This interface is a derivation of AuthJoomla and might change a bit before 1.4.0 final is done...
*
*/
$wgExtensionCredits['parserhook'][] = array (
'name' => 'ExtAuthDB',
'author' => 'Alessandra Bilardi',
'description' => 'Authenticate users about external MySQL database',
'url' => 'https://www.mediawiki.org/wiki/Extension:ExtAuthDB',
'version' => '0.1',
);
require_once ( "$IP/includes/AuthPlugin.php" );
class ExtAuthDB extends AuthPlugin
{
/**
* Add into LocalSettings.php the following code:
*
* MySQL Host Name.
* $wgExtAuthDB_MySQL_Host = '';
* MySQL Username.
* $wgExtAuthDB_MySQL_Username = '';
* MySQL Password.
* $wgExtAuthDB_MySQL_Password = '';
* MySQL Database Name.
* $wgExtAuthDB_MySQL_Database = '';
* MySQL Database Table of users data.
* $wgExtAuthDB_MySQL_Table = '';
* MySQL Database username column label.
* $wgExtAuthDB_MySQL_Login = '';
* MySQL Database login password column label
* $wgExtAuthDB_MySQL_Pswrd = '';
* MySQL Database email column label
* $wgExtAuthDB_MySQL_Email = '';
* MySQL Database user real name column label
* $wgExtAuthDB_MySQL_RealN = '';
* require_once("$IP/extensions/ExtAuthDB/ExtAuthDB.php");
* $wgAuth = new ExtAuthDB();
*
* #return Object Database
*/
private function connectToDB()
{
$db = & Database :: newFromParams(
$GLOBALS['wgExtAuthDB_MySQL_Host'],
$GLOBALS['wgExtAuthDB_MySQL_Username'],
$GLOBALS['wgExtAuthDB_MySQL_Password'],
$GLOBALS['wgExtAuthDB_MySQL_Database']);
$this->userTable = $GLOBALS['wgExtAuthDB_MySQL_Table'];
$this->userLogin = $GLOBALS['wgExtAuthDB_MySQL_Login'];
$this->userPswrd = $GLOBALS['wgExtAuthDB_MySQL_Pswrd'];//.$GLOBALS['$wgExtAuthDB_MySQL_Salt'];
$this->userEmail = $GLOBALS['wgExtAuthDB_MySQL_Email'];
$this->userRealN = $GLOBALS['wgExtAuthDB_MySQL_RealN'];
wfDebug("ExtAuthDB::connectToDB() : DB failed to open\n");
return $db;
}
/**
* Check whether there exists a user account with the given name.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* #param $username String: username.
* #return bool
* #public
*/
function userExists( $username ) {
# Override this!
return true;
}
/**
* Check if a username+password pair is a valid login.
* The name will be normalized to MediaWiki's requirements, so
* you might need to munge it (for instance, for lowercase initial
* letters).
*
* #param $username String: username.
* #param $password String: user password.
* #return bool
* #public
*/
function authenticate( $username, $password )
{
$db = $this->connectToDB();
$hash_password = $db->selectRow($this->userTable,array ($this->userPswrd), array ($this->userLogin => $username ), __METHOD__ );
if ($password == $hash_password->{$this->userPswrd}) {
return true;
}
return false;
}
/**
* Set the domain this plugin is supposed to use when authenticating.
*
* #param $domain String: authentication domain.
* #public
*/
function setDomain( $domain ) {
$this->domain = $domain;
}
/**
* Check to see if the specific domain is a valid domain.
*
* #param $domain String: authentication domain.
* #return bool
* #public
*/
function validDomain( $domain ) {
# Override this!
return true;
}
/**
* When a user logs in, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* #param User $user
* #public
*/
function updateUser( &$user )
{
$db = $this->connectToDB();
$euser = $db->selectRow($this->userTable,array ( '*' ), array ($this->userLogin => $user->mName ), __METHOD__ );
$user->setRealName($euser->{$this->userRealN});
$user->setEmail($euser->{$this->userEmail});
$user->mEmailAuthenticated = wfTimestampNow();
$user->saveSettings();
//exit;
# Override this and do something
return true;
}
function disallowPrefsEditByUser() {
return array (
'wpRealName' => true,
'wpUserEmail' => true,
'wpNick' => true
);
}
/**
* Return true if the wiki should create a new local account automatically
* when asked to login a user who doesn't exist locally but does in the
* external auth database.
*
* If you don't automatically create accounts, you must still create
* accounts in some way. It's not possible to authenticate without
* a local account.
*
* This is just a question, and shouldn't perform any actions.
*
* #return bool
* #public
*/
function autoCreate() {
return true;
}
/**
* Can users change their passwords?
*
* #return bool
*/
function allowPasswordChange() {
return false;
}
/**
* Set the given password in the authentication database.
* As a special case, the password may be set to null to request
* locking the password to an unusable value, with the expectation
* that it will be set later through a mail reset or other method.
*
* Return true if successful.
*
* #param $user User object.
* #param $password String: password.
* #return bool
* #public
*/
function setPassword( $user, $password ) {
return true;
}
/**
* Update user information in the external authentication database.
* Return true if successful.
*
* #param $user User object.
* #return bool
* #public
*/
function updateExternalDB( $user ) {
$db = $this->connectToDB();
$euser = $db->selectRow($this->userTable,array ( '*' ), array ($this->userLogin => $user->mName ), __METHOD__ );
$user->setRealName($euser->{$this->userRealN});
$user->setEmail($euser->{$this->userEmail});
$user->mEmailAuthenticated = wfTimestampNow();
$user->saveSettings();
return true;
}
/**
* Check to see if external accounts can be created.
* Return true if external accounts can be created.
* #return bool
* #public
*/
function canCreateAccounts() {
return false;
}
/**
* Add a user to the external authentication database.
* Return true if successful.
*
* #param User $user - only the name should be assumed valid at this point
* #param string $password
* #param string $email
* #param string $realname
* #return bool
* #public
*/
function addUser( $user, $password, $email='', $realname='' ) {
return false;
}
/**
* Return true to prevent logins that don't authenticate here from being
* checked against the local database's password fields.
*
* This is just a question, and shouldn't perform any actions.
*
* #return bool
* #public
*/
function strict() {
return true;
}
/**
* When creating a user account, optionally fill in preferences and such.
* For instance, you might pull the email address or real name from the
* external user database.
*
* The User object is passed by reference so it can be modified; don't
* forget the & on your function declaration.
*
* #param $user User object.
* #param $autocreate bool True if user is being autocreated on login
* #public
*/
function initUser( $user, $autocreate=false ) {
# Override this to do something.
}
/**
* If you want to munge the case of an account name before the final
* check, now is your chance.
*/
function getCanonicalName( $username ) {
return $username;
}
}
And in LocalSettings.php, I should add this code:
// add ExtAuthDB
// MySQL Host Name.
$wgExtAuthDB_MySQL_Host = 'localhost';
// MySQL Username.
$wgExtAuthDB_MySQL_Username = 'dbuser';
// MySQL Password.
$wgExtAuthDB_MySQL_Password = 'dbpassword';
// MySQL Database Name.
$wgExtAuthDB_MySQL_Database = 'base';
// MySQL Database Table of users data.
$wgExtAuthDB_MySQL_Table = 'members';
// MySQL Database username column label.
$wgExtAuthDB_MySQL_Login = 'username';
// MySQL Database login password column label
$wgExtAuthDB_MySQL_Pswrd = 'password';
$wgExtAuthDB_MySQL_Salt='salt';
// MySQL Database email column label
$wgExtAuthDB_MySQL_Email = 'email';
// MySQL Database user real name column label
$wgExtAuthDB_MySQL_RealN = 'real_name';
require_once("$IP/extensions/ExtAuthDB/ExtAuthDB.php");
$wgAuth = new ExtAuthDB();
Sorry, I had to copy full script, because I don't know where is the exact fault. And my question is: Why doesn't it work? Where is the mistake?
EDIT:
My external user table consists of id, username, password, salt, email, real_name. I thought it could be because of seperate password and salt fields, so I tried to implement salt in ExtAuthDB.php file manually. Unfortunately, it didn't work either. Then I commented this line.
I was able to setup SSO (Single sign-on) from WordPress to media wiki using OAuth 2.0 server, I have posted my solution on this post
Or you can follow these steps:
First you need an OAuth 2.0 server, you could implement it your self see details here Run your own OAuth 2.0 Server or the easiest way is to use the WordPress plugin WP Oauth 2.0 server you don't have to buy the pro, you can also implement SSO by using the Grant type Authorization codes which comes free.
You need OAuth 2.0 client extension installed on your media wiki, the extension can be found here, follow the installation instructions there.
Go to WordPress plugin page and activate OAuth server, then navigate to OAuth Server and add a new client, give your client a name and in Redirect URI add the link mention on the media wiki extension page i.e http://your.wiki.domain/path/to/wiki/Special:OAuth2Client/callback, then go to OAuth>clients page where you can see your newly created client, click edit and here you can see clientID and Client secret add this ID and secret in the localSettings.php of your media wiki.
Create a page on WordPress and put the following button with your client id in it
< a href="https://your-Domain-Where-OAuth-server-is-running.de/oauth/authorize?response_type=code&client_id=YOURCLIENTID&state=RANDOM-STRING&scope=basic">
go to wiki</a>
don't forget to put scope otherwise you will get a media wiki internal error.
If everything worked fine then you should automatically go to the media wiki main page after clicking this button from your WordPress. media wiki will show you as logged in. It took me some time to figure it out I hope this helps anyone who comes here.
You need to run the MediaWiki update script for this extension.
Many extensions need an update with update.php script!
From the browser
If you do not have access to the command line of your server, then use the web updater to run the update script.
From the command line
From the command line, or an SSH shell or similar:
Change to the maintenance directory!
Run the update script with php update.php command!
How can i get the SQL query of this?
$product = Mage::getModel('catalog/product')->load(4329)->getCategoryIds();
To enable the sql debugging in magento , open the file lib/Varien/Db/Adapter/Pdo/Mysql.php in your favorite text editor. Down around line 86, you’ll see the following class variables:
/*
* Write SQL debug data to file
*
* #var bool
*/
protected $_debug = false;
/**
* Minimum query duration time to be logged
*
* #var unknown_type
*/
protected $_logQueryTime = 0.05;
/**
* Log all queries (ignored minimum query duration time)
*
* #var bool
*/
protected $_logAllQueries = false;
/**
* Add to log call stack data (backtrace)
*
* #var bool
*/
protected $_logCallStack = false;
/**
* Path to SQL debug data log
*
* #var string
*/
protected $_debugFile = 'var/debug/sql.txt';
Change the following variables :
protected $_debug = true; //false;
And
protected $_logAllQueries = true; //false;.
This is all.After running app goto sql.txt you will see all the queries .
echo Mage::getModel('catalog/product')->load(4329)->getCategoryIds()->getSelect();
should work
On Objects of Type Zend_Db_Select (eg Varien_DB_Select) you can call the Method assemble() to get the SQL-Query String.