LDAP_add with PHP: Operations Error - php

I am quite a noob in using LDAP (this is actually my first project) and I can't find an answer on google that can help me...
So my problem is: I'm trying to add a contact with php to an active directory on a windows 2003 server. I can connect to the server, and neither I have problems with ldap_bind.
But when I run the program I always get the Error:
Warning: ldap_add() [function.ldap-add]: Add: Operations error in (Blabla) on line bla
and the ldap_error also only says "Operations error"
which is pretty vague, so I don't even know if it's a problem with the server or with my code.
I saw some threads with similar problems where servers didn't allow anonymous access, but I even bind with an admin account and it still does not work.
My code looks a lot like this:
$ldapcon=ldap_connect("servername");
if($ldapcon) {
$bind=ldap_bind($ldapcon,"Admin#domain.com", "somePassword");
if($bind) {
// create data...
$info=array();
$info["cn"][0] = "Hans Mustermann";
$info["sn"][0] = "Mustermann";
$info["givenName"][0] = "Hans";
$info["mail"][0] = "MustermannH#firma.de";
$info["objectclass"][0] = "top";
$info["objectclass"][1] = "person";
$info["objectclass"][2] = "organizationalPerson";
$info["objectclass"][3] = "contact";
$info["ou"][0] = "Users";
$info["ou"][1] = "contact";
// add Data...
$r=ldap_add($ldapcon, "cn=Hans Mustermann, sn=Mustermann", $info)
or die(ldap_error($ldapcon)); //error: operations error
}
}
Are there some infos missing? is the code wrong? do i need some changes on the ad-settings? is it a problem with "remote-rights-setting" or whatever?
Am I just too stupid and blind to see the problem or is it a bigger thing that is not easy to fix?
Does someone of you have an idea?
Thanks a lot
Chillikarli

Instead of the or die() condition you might try this
// add Data...
if(!(ldap_add($ldapcon, "cn=Hans Mustermann, sn=Mustermann", $info))) {
echo "There is a problem to create the account\n";
echo "Please contact your administrator !\n";
echo "LDAP Error: ".ldap_error($ldapcon)."\n";
exit;
}
ldap_unbind($ldapcon);

Related

Admin restrinction fails from an irrelevant function

I have this piece of code in PHP web app.
if (isset($require_admin) && $require_admin) {
if(!check_admin()) {
$toolContent_ErrorExists = $langCheckAdmin;
$errorMessagePath = "../../";
}
}
The normal behavior is that if the variable $require_admin is set and true,the code will check if the visit is by the admin.
I try to add a similar piece of code some lines below so as to make other things like checking for cross-origin(especially CSRF) requests.
if (isset($require_token) && $require_token) {
if( !checkToken( $mycsrf_token, $myform)) {
$toolContent_ErrorExists = $langCheckToken;
$errorMessagePath = "../../";
}
}
I had in mind that in this way i will have a check that the posted forms I get are valid and if no,there would be an error message.
However,when $require_token is set and true,and the condition is verified i have a very strange result.Not only nothing happens for the csrf validation,but the above function stops working properly and admin restriction stops to work.
I know the question maybe is ambiguous but I cannot get what's going on there.I'm not so experienced on web programming and totally new in PHP so maybe someone could have a better idea!

PHP Onvif - GetSnapshotUri

I am using an opensource PHP library to communicate to a Onvif capable IP camera.
There was one function missing in the library, GetSnapshotUri which returns an URL where one can get a snapshot of the main stream.
Here is the source: http://pastebin.com/ekJa4D2h
Here is main page:
<?php
require 'class.ponvif.php';
$onvif = new Ponvif();
$onvif->setUsername('admin');
$onvif->setPassword('admin');
$onvif->setIPAddress('192.168.1.100');
try
{
$onvif->initialize();
$sources = $onvif->getSources();
$profileToken = $sources[0][0]['profiletoken'];
$uri = $onvif->media_GetSnapshotUri($profileToken);
}
catch(Exception $e)
{
print $e;
}
?>
For some reason, the isFault function is true and i have no clue why.
The XML is valid, i checked it with Wireshark.
Does anybody have another camera to this if this works?
I have tried with 2 different camera's, Grandstream and Hikvision.
Also with ONVIF Device Manager v2.2.250 everything works as it should.
I know this is a long shot, but i have absolutely no clue.
fix is here: http://pastebin.com/ryqxFjdR
mediaurl instead of getsnapshoturl in the function.

Using isset to display page content

I am having an issue using isset to display content on a page.
My PHP file is called messages.php
I am directing my users with links to this URL: messages.php?inbox using if(isset($_GET['inbox']))
{ } to display the users inbox. Same principle with the other users options such as compose message is: messages.php?compose again using isset
The only problem I have is that I cannot stop people from manually typing stuff like domain.com/messages.php or domain.com/messages.php?somethingrandom.
Is there a way to direct users to messages.php?inbox when they type in the address bar something that isnt assigned to isset?
I did try to use switch but couldnt seem to get it to work properly with how ive laid out my HTML.
An example of the whole file is here http://pastebin.com/SfqN2L7g
I am fairly new to PHP and think I may have gone down the complicated route.
Any advice would be appreciated.
Thanks
The answer you added already would work, but I usually like having an array of valid options which I could maybe check against later on.
$validPages = array('inbox', 'compose');
$pageFound = false;
foreach ($validPages as $validPage) {
if (isset($_GET[$validPage])) {
$pageFound = true;
break;
}
}
if (! $pageFound) {
header('Location: /messages.php?inbox');
}
Thanks to the help of Marcos Pérez Gude, the answer is as follows:
if(isset($_GET['inbox']) || isset($_GET['compose'])){
//Then do below
}else{
header("Location: messages.php?inbox");
exit;
}

Possible MySQL sudden error

Hello friends from SO!
Alright, this time I have a little bit more complex problem. We have a web crawler running and functioning normally during most of the day and time.
However, from time to time, it just stops: the link which is supposed to be analyzed next, never change it's state (from pending to scanning), and of course this stops the whole cycle.
We're logging all PHP errors using:
//errores producción
#ini_set('error_reporting', -1);
#ini_set('log_errors','On');
#ini_set('display_errors','Off');
#ini_set('error_log','/var/www/vhosts/xxx.com/xxx.com/xxx');
There's no evidence of anything that could cause the problem described. 0 anomalies.
Therefore, I believe the problem might be related to some kind of MySQL issues?
Every single MySQL query we do, is done using MySQLi by custome made functions, so my question here is:
Is there any simple approach to record every single MySQL error on the same file where we are storing the PHP errors?
Here are some of the functions used to query the MySQL:
Function db_ob($db_link, $ask) {
$feedback = mysqli_fetch_object(mysqli_query($db_link, $ask));
return $feedback;
}
and:
Function db_ob_all($db_link, $ask) {
$feedback = mysqli_query($db_link, $ask);
while ($row = mysqli_fetch_object($feedback)) { $value[] = $row; }
return $value;
}
So what I'm looking for, is a one or two lines solution, that I could add into these functions, in order to store and track any issue or error in the same file where I'm currently storing the PHP errors.
Thanks in advance!
Chris;
Solved:
1) make a function to track the errors into the PHP error_log:
Function informar_error_db($db_link) {
error_log("Dreadful SQL error: ". mysqli_error($db_link)." in ".$_SERVER["SCRIPT_FILENAME"]);
}
2) If there's MySQLi issues, save em:
Function db_ask($db_link, $ask) {
$feedback = mysqli_query($db_link, $ask);
if (mysqli_error($db_link)) { informar_error_db($db_link); }
return $feedback;
}
Here:
if (mysqli_error($db_link)) { informar_error_db($db_link); }

Chrome : No data received, Safari : Can't open the page

I have a web page which allow users to compose news articles. It has a rich text editor too. So someone can copy and paste text from the web. When I put some copied content from wiki to that and once I POST, it throws "No Data Received" error on Chrome. When I check this with Safari it says "Can't open the page". Firefox displays empty page.
But when I stop the execution of the mysql insert query it works fine. The issue is there is n issue with the mysql statement too. I extracted the generated sql statement and executed it separately with mysql tool. It works fine. No issue with the queries.
I am really stuck here. Could you please help me on this.
Thank you.
Prasad.
Here is the action code:
public function articlenewAction() {
$form = new Backoffice_Form_ArticleDraft();
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$postData = $_POST;
$newArticleID = Classes_Article::createArticle($postData);
}
}
}
Finally we could go through this. We have upgraded the php version.
Let us know if you know any other way to fix this.
Prasad.

Categories