vTiger: "Permission to perform the operation is denied for name" - php

I found some cases where the error was the same, but the situation was not.
This is intended as custom workflow function in vTiger, code is the following:
function perform_query($entity) {
/*$entityArray = get_object_vars($entity); //array
echo "<pre>";
print_r($entityArray);
echo "</pre>";
break;*/
include_once 'include/Webservices/Query.php';
include_once 'modules/Users/Users.php';
$user = new Users();
$current_user = $user->retrieveCurrentUserInfoFromFile(Users::getActiveAdminId());
try {
$q = "SELECT * FROM vtiger_seactivityrel WHERE crmid = ".substr($entity->id, strpos($entity->id, "x") + 1);
$q = $q . ';';
$records = vtws_query($q, $current_user);
print_r($records);
} catch (WebServiceException $ex) {
echo $ex->getMessage();
}
break;
}
?>
This should give me the results: if there are, i want to take further actions. This gives me the following error:
Permission to perform the operation is denied for name.
I don't know what's happening, does anyone have any idea? Thank you.

I solved this myself. The fact is that vtws_query does NOT query the database directly. It has some kind of abstraction, so if you put database table and columns it just denies access. Although strange, right form is this one:
SELECT * FROM <ModuleName> WHERE <Property> = '<your_search>'
To list the modules, you should use vtws_listtypes; to know which properties you could search, use vtws_describe. More info here.

Related

Nested LDAP search for an attribute

In an AD server we have an attribute called directreports. I want to be able to go top to bottom in the chain. CEO his direct reports are A,B,C. As direct reports are D,E,F while Bs direct report is G,H,I. Then Ds direct reports are X,Y,Z, etc all the way down.
I've looked at this as a nested group kind of thing, but it's not. I'm lost as how to tackle this all together. I'm trying to do this in PHP. My php code right now just searches a user and gives me the direct reports.
<?php
function aduserlookup ($UserName)
{
include_once 'config.php';
$ldapconn = ldap_connect("ldap://<IP>:389") or die("Could not connect to the ldap server");
if($ldapconn) {
$r = #ldap_bind($ldapconn, $ldapuser."#test.com", $ldappass);
$sr=ldap_search($ldapconn, "OU=Employees,OU=Users,DC=test,DC=com",
"cn=" . $UserName);
$info = ldap_get_entries($ldapconn, $sr);
ldap_close($ldapconn);
return $info;
} else {
echo "<h4>Unable to connect to LDAP server</h4>";
}
}
$user = aduserlookup('test');
$directreports = $user[0]['directreports'];
echo '<pre>';
var_dump($directreports);
echo '</pre>';
foreach ($directreports as $key => $value)
{
$directreports = substr($value, 0, strpos($value, ","));
$directreports = strstr($directreports, '=');
$directreports = str_replace('=', '', $directreports);
$directreports1 = aduserlookup('\'' . $directreports . '\'');
echo $directreports1 . "<br>";
}
?>
IF you are using Microsoft Active Directory and If I understood what you are looking for,
You can Query All users that report to a department manager or their subordinates by using this query
(manager:1.2.840.113556.1.4.1941:=CN=manager,OU=users,DC=willeke,DC=com)
DirectReports is a server generated list of users that directly report to the "manager". The users that are listed as reports are those that have the property manager property set to this user. Each item in the list is a Linked Attribute to the object that represents the user.

PHP file upload error conditions

I am trying to create a profile editing setup. It seems as though the information is edited only when an image is being uploaded. I found out that allowing the error message to be a condition allows for some more manipulation so I attempted it now my condition statement is not working as it should.
if($_FILES['files']['error']==0) {
print_r($_FILES['files']['error']);
echo "if";
foreach($_FILES['files']['name'] as $file => $name) {
$filename = $name;
try{
if(move_uploaded_file($_FILES['files']['tmp_name'][$file],'uploads/'.$filename)) {
$updateInfo = $db->prepare("UPDATE users SET image = :image, aboutme = :aboutme WHERE id = :id");
$updateInfo->bindParam(":image", $filename);
$updateInfo->bindParam(":id", $_SESSION['user']['id']);
$updateInfo->bindParam(':aboutme', $aboutme);
$updateInfo->execute();
}
} catch(Exception $e) {
echo $e;
}
}
} elseif($_FILES['files']['error'] == 4) {
print_r($_FILES['files']['error']);
echo "Elseif";
try{
$updateInfo = $db->prepare("
UPDATE users
SET
aboutme = :aboutme
WHERE id = :id
");
$updateInfo->bindParam(':id', $_SESSION['user']['id']);
$updateInfo->bindParam(':aboutme', $aboutme);
$updateInfo->execute();
} catch(Exception $e) {
echo $e;
}
} else{
print_r($_FILES['files']['error']);
echo "else";
}
}
When I check what array is being sent, its the correct one but the wrong condition, ie: it would run the else statement no matter the file check.
My question:
Is there something wrong with my code, with the exception of any security or efficiency flaws?
$_FILES['files']['error'] returns error code along with the file array. There are different type of error codes, all codes are mentioned in following link with details:
Please check by
print_r($_FILES['files'])
and see what are you getting in response.
As you posted your array response, you can get error code by $_FILES['files']['error'][0] or use switch case as mentioned in following link.
See here for more details:
http://php.net/manual/en/features.file-upload.errors.php
Also regarding debugging, always debug code step by step from top to bottom. Check $_POST, $_FILES, $_SERVER etc details if you get some problem particular related to data process.

Call to undefined function sccp_get_model_data()

Hoping someone can help me with a Call to undefined function error I am getting in the following code:
$query = \FreePBX::Database()->query('SELECT model, dns, buttons, loadimage
FROM sccpdevmodel
WHERE dns > 0
ORDER BY model');
$res = $query->fetchAll();
foreach ($res as $row) {
$modelData['model'][] = $row[0];
$modelData['dns'][] = $row[1];
$modelData['buttons'][] = $row[2];
$modelData['loadimage'][] = $row[3];
}
return $modelData;
This first part seems to be ok then I get the error $modelData = sccp_get_model_data(); in this line.
<?php
$modelData = sccp_get_model_data();
$numModels = count($modelData['model']);
$addonData = sccp_get_addon_data();
$numAddons = count($addonData['model']);
?>
Any advice?
Here is a link to the source file if anyone can help please?
https://github.com/Cynjut/SCCP_Manager/tree/master
Make sure you are using an include or require statement to load your functions. I found what seems to be the full code base for this on github and didn't see where it loads in the functions you use.
Not sure if you want them conditionally loaded, but if not, you can include 'functions.inc.php'; at the top of the file that needs to use them.

PHP Function produces empty Results no errors

A little help if possible. I have a Page that pulls from two data tables (MySQL) and one function is providing empty results.
function ShowClient() {
global $agent;
$sql = 'SELECT * FROM nuke_bulletins WHERE user=\'' . $agent . '\' AND isActive="Y" ORDER BY id';
$client = mysql_query($sql) or die('ERROR: OOPS Something went wrong' . mysql_error());
echo '<center><p><b>Current Campaigns</b></p>';
// Pull the loop and display the data
while($row = mysql_fetch_array($client)) {
$agent = stripslashes($row['user']);
$campaign = stripslashes($row['id']);
$title = stripslashes($row['title']);
echo '<p><b>' . $title . '</b></p>';
}
echo '<p>Click the Campaign Title to get the Bulletin Code</p><p> </p>';
echo '<p align="center"><b>Return to All Client\'s</p>';
}
The $agent variable is pulled from a main function that creates a url based on the user ($agent).
What am I doing wrong here?
$agent is a global variable. Using global variables is generally considered bad practice, as this could be getting set or unset somewhere before this function is called.
Have you checked the PHP Error Log to see if you are getting any errors?
If no errors in log I would look to see if $agent conatins a value either by echoing to screen (if dev environment) or dumping the value in the error log file to see if it actually contains anything. http://www.php.net/manual/en/function.error-log.php
Then I would look at the SQL itself; do the Column headings in your table nuke_bulletins match the $row array keys exactly for instance are they the same case?
$row['title']
or
$row['Title']
Here we go...
Don't use the mysql extension. It is unmaintained and officially deprecated
Don't use globals. Relying on external state makes for smelly code
You're overwriting said global variable ($agent) in a loop. Terrible idea.
or die must die ~ http://www.phpfreaks.com/blog/or-die-must-die
I wouldn't recommend using echo within a function. Makes for spaghetti code
Your HTML is a bit of a mess
Here's my suggestion using the mysqli extension
function getCampaigns(mysqli $con, $agent) {
if (!$stmt = $con->prepare("SELECT id, title FROM nuke_bulletins WHERE user = ? AND isActive = 'Y' ORDER BY id")) {
throw new Exception($con->error, $con->errno);
}
$stmt->bind_param('s', $agent); // if the user column is a integer, use 'i' instead
if (!$stmt->execute()) {
throw new Exception($stmt->error, $stmt->errno);
}
$stmt->bind_result($id, $title);
$campaigns = []; // or array() if you're on PHP < 5.4
while ($stmt->fetch()) {
$campaigns[$id] = $title;
}
return $campaigns;
}
Now you can call this function like this...
<?php
// assuming you have a mysqli instance in a $con variable, eg $con = new mysqli(...)
// and an $agent variable
$campaigns = getCampaigns($con, $agent);
?>
<p><strong>Current Campaigns</strong></p>
<?php foreach ($campaigns as $id => $title) : ?>
<p>
<a href="bullies2.php?op=ShowCampaign&id=<?= $id ?>">
<strong><?= htmlspecialchars($title) ?></strong>
</a>
</p>
<?php endforeach ?>
<p>Click the Campaign Title to get the Bulletin Code</p>
<p> </p>
<p align="center"><strong>Return to All Client's</strong></p>
And, as always, your development environment should have the following properties set in your php.ini file
display_errors = On
error_reporting = E_ALL

INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session

Similar issues -
INVALID_SESSION_ID using partner/enterprise wsdl for two different SF users - Tried solution but didn't work.
I was trying to use Salesforce PHP toolkit with ZF 2. I have added namespace to php files in salesforce soap client and used it in zend controller.
Added follwing line to all php files in Salesforce SOAP client library.
namespace Salesforce\Soapclient;
Then included it in ZF controller.
use Salesforce\Soapclient;
Here is the connetion code -
$empid = 'e1234567';
$sf_WSDL = 'C:\wamp\www\myapp\app\vendor\salesforce\wsdl\enterprise.wsdl.xml';
$sf_username = $config['salesforce']['username'];
$sf_password = $config['salesforce']['password'];
$sf_token = $config['salesforce']['token'];
/***********/
try {
// Create SOAP client instance
$sfSoapClient = new Soapclient\SforceEnterpriseClient();
// Create connection
$sfSoapClient->createConnection($sf_WSDL);
var_dump($_SESSION['enterpriseSessionId']);
if (isset($_SESSION['enterpriseSessionId'])) {
$location = $_SESSION['enterpriseLocation'];
$sessionId = $_SESSION['enterpriseSessionId'];
$sfSoapClient->setEndpoint($location);
$sfSoapClient->setSessionHeader($sessionId);
} else {
// Login to SF
$sfSoapClient->login($sf_username,$sf_password . $sf_token);
$_SESSION['enterpriseLocation'] = $sfSoapClient->getLocation();
$_SESSION['enterpriseSessionId'] = $sfSoapClient->getSessionId();
}
var_dump($_SESSION['enterpriseSessionId']);
// Get candidate profile by employee id
$candidate_profile = $this->getCandidateTable()->getCandidateByEmpId($empid);
$ids = array();
array_push($ids, $empid);
// If no profile for logged internal employee
if (!$candidate_profile){
$query = "SELECT Id, First_Name__c from Employee__c";
$response = $sfSoapClient->query($query);
echo "Results of query '$query'<br/><br/>\n";
foreach ($response->records as $record) {
echo $record->Id . ": " . $record->First_Name__c . "<br/>\n";
}
}
} catch (Exception $exc) {
//TODO Handle error login exception
die('Connection could not established.');
}
But I'm getting following error -
INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal
Session
Note that "Lock sessions to the IP address from which they originated" setting is turned off.

Categories