露天“管理”当我多次调用同一个网页脚本时,密码不断被删除

发布于 2024-10-21 23:41:09 字数 11603 浏览 4 评论 0原文

我有一个奇怪的问题。我在 PHP 中创建了一个执行以下操作的过程:

  1. 从 MySQL 表中读取数据(9.000 行)
  2. 将一行写入另一个表
  3. 根据行中的字段在 Alfresco 中创建一个文件夹

我遇到了这个奇怪的问题(仅在一个 Alfresco 安装上,在其他安装上我没有问题),在前 2-3 行之后,管理员用户的密码将从 Alfresco 中删除(如果您查看数据库,则找不到它),所以程序停止。我正在使用 Alfresco Community 3.2。

以下是该过程的 PHP 代码:

   require_once("../components/com_astra/libs/AlfrescoConnect.php");
require_once("../components/com_astra/libs/FirePHPCore/fb.php");
$username = "***";
$password = "****;";
$hostname = "localhost"; 
ob_start();
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$selected = mysql_select_db("lbs_8",$dbhandle)
  or die("Could not select examples");
$result = mysql_query("SELECT count(*) as quanti FROM ast_tabellaTemporaneaNdg");
if (!$result) {
    die('ERRORE: ' . mysql_error());
}
$totaleTabella = mysql_result($result, 0);
echo("La tabella ast_tabellaTemporaneaNdg contiene [$totaleTabella] records<br>");
echo("Conto il numero di record della vista di transcodifica<br>");
$result = mysql_query("SELECT count(*) as quanti FROM vista_ndg_normalizzati");
if (!$result) {
    die('ERRORE: ' . mysql_error());
}
$totaleVista = mysql_result($result, 0);
echo("La vista vista_ndg_normalizzati contiene [$totaleVista] records<br>");
if ($totaleTabella == $totaleVista){
    echo("Tutte le righe della tabella ast_tabellaTemporaneaNdg sono transcodificate correttamente<br>");
    echo("Saranno quindi importati [$totaleTabella] records<br>");
}else{
    echo("Non tutte le righe della tabella ast_tabellaTemporaneaNdg sono transcodificate correttamente<br>");
    echo("nella tabella ast_tabellaTemporaneaNdg sono presenti [$totaleTabella] records, di questi solo [$totaleVista] transcodificano correttamente<br>");
    $handle = fopen("ndgNonImportabili.txt", "w");
    $result = mysql_query("SELECT ndg FROM ast_tabellaTemporaneaNdg WHERE ndg NOT IN (SELECT ndg from vista_ndg_normalizzati)");
    if (!$result) {
        die('ERRORE: ' . mysql_error());
    }
    while ($row = mysql_fetch_assoc($result)){
        $ndg = "NDG: ".$row["ndg"]."\n";
        fwrite ($handle, $ndg);

    }
    fclose($handle);
    echo("Gli NDG non importabili sono stati loggati nel file ndgNonImportabili.txt<br>");
    //die("L'importazione avra' inizio solo quando tutti gli NDG saranno importabili. I motivi per cui un ndg non è importabile possono essere: incorenza fra Natura Giuridica 1 e natura giuridica 2, Incoerenza fra comune, Provincia e Regione<br>");
}
$result = mysql_query("SELECT * FROM vista_ndg_normalizzati");
//fb($result, 'risultati');
$handle = fopen("logImportazione.txt", "w");
while ($row = mysql_fetch_assoc($result)) {
    $user = "admin";
    $ndg = $row['ndg'];
    $response = AlfrescoConnect::createNDG($ndg, $user);
    $status = $response['esito'];
    if($status == "OK"){
        $ragioneSociale = mysql_real_escape_string($row['ragioneSociale']);
        $query = "SET FOREIGN_KEY_CHECKS=0";
        $resultSetKeys = mysql_query($query);
        $query = "INSERT INTO ast_Cliente (idUtente, idNaturaGiuridica,  idTipoSegmento, idRegione, idProvincia, idComune,  ragioneSociale, ndg, idNaturaGiuridica2) VALUES ";
        $query .= " (1, ".$row['idNaturaGiuridica'].", 2 , ".$row['idRegione'].", ".$row['idProvincia'].", ".$row['idComune'].", '".$ragioneSociale."', '".$ndg."', ".$row['idNaturaGiuridica2'].")";
        //fb($query);
        $resultInsert = mysql_query($query);
        if (!$resultInsert) {
            $messaggio = "Si è verificato un errore nell'importazione dell'ndg [$ndg]: [".mysql_error()."]\n";
        }else{
            $messaggio = "[$ndg] importato con successo\n";
        }
        fwrite ($handle, $messaggio);
    }else{
        $messaggio = "Si è verificato un errore nella creazione della cartella per l'ndg [$ndg] su alfresco. ERRORE: [".$response['motivazione']."]\n";
        fwrite ($handle, $messaggio);

    }
   }
fclose($handle);
echo("importazione completata: i risultati dell'importazione sono stati salvati nel file logImportazione.txt");
?> 

该文件夹是通过调用 $response = AlfrescoConnect::createNDG($ndg, $user); 创建的,其中 $ndg 是名称文件夹的名称,$user 是创建它的用户

以下是 AlfrescoConnect.php 的代码:

class AlfrescoConnect
{

    static public $webscriptURL = "http://localhost:8080/alfresco/service";
    static public $login = "/api/login";
    static public $login_ticket = "/api/login/ticket";
    static public $alfrescoPath = "http://localhost:8080";

    static public $alfrescoContext = "/alfresco";

    static public $upload_file_script = "/astra/upload";
    static public $uploadFile = "/astra/uploaddoc";
    static public $search_document = "/astra/cercadocumenti";
    static public $createNDG = "/astra/creandg";
    static public $createPEFPerNDG = "/astra/creapef";
    static public $searchDocumentPerConfirm = "/astra/cercadocumentoperconferma";
    static public $confirmDocument = "/astra/confermadocumenti";
    static public $getPEF = "/astra/estraidatipef";
    static public $updatePEF = "/astra/aggiornapef";
    static public $documentCounter = "/astra/contadocumenti";
    static public $userLogin = "/astra/creautente";
    static public $cancella = "/astra/managedocumentversions";
    static public $alfUsername = "admin";
    static public $alfPassword = "admin";

    static public $ticket = "";
    static public $userTicket = ""; 

    static public function Authenticate($username='') {
        //fb($username);
        if(strcmp($username,'')==0){
            if (AlfrescoConnect::isAuthenticated()) return true;
            $link = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$login."?u=".AlfrescoConnect::$alfUsername."&pw=".AlfrescoConnect::$alfPassword . "&noCache=" .time();
            fb($link, "LINK");
        }else{
            AlfrescoConnect::$userTicket =  AlfrescoConnect::CustomAuthentication($username);
            return true;
        }
        try {

            //perform a http/get request to get tiket
            // Try to create a ticket
            // If the ticket fails, it means that the username and/or password are wrong
            $r= new HttpRequest($link, HttpRequest::METH_GET);
            $r->send() ;
            $http_response = $r->getResponseBody();fb($http_response, "RISPOSTA");
            $pos1 = stripos($http_response, "<ticket>");
            $pos2 = stripos($http_response, "</ticket>");
            //ceck if token is returned 
            if ($pos1<0 | !is_int($pos1) || $pos2<0 | !is_int($pos2)) {
                AlfrescoConnect::$ticket = "";
                $returnValue = false;
            } else {

                $pos1 += 8;
                $pos2 -= $pos1;
                // clean the xml info
                AlfrescoConnect::$ticket = substr($http_response, $pos1, $pos2);
                $returnValue = true;
            }
            //fb(AlfrescoConnect::$ticket);
            $_SESSION["ticket"] = AlfrescoConnect::$ticket;
            return true;

        }
        catch (Exception $e) {
            fb($e, "Eccezione");
            AlfrescoConnect::$ticket = "";
            $_SESSION["ticket"] = AlfrescoConnect::$ticket;
            return $returnValue;
        }

    }
    static public function isAuthenticated() {
        if (!isset($_SESSION["ticket"])) return false;
        $link = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$login_ticket."/".$_SESSION["ticket"]."?alf_ticket=".$_SESSION["ticket"]."&noCache=" .time();
        fb($link, 'link in isauth');
        try {

            //perform a http/get request to get tiket
            // Try to create a ticket
            // If the ticket fails, it means that the username and/or password are wrong
            $r= new HttpRequest($link, HttpRequest::METH_GET);
            $r->send() ;
            $http_response = $r->getResponseBody();

            $pos1 = stripos($http_response, "<ticket>");
            $pos2 = stripos($http_response, "</ticket>");
            //ceck if token is returned 
            if ($pos1<0 | !is_int($pos1) || $pos2<0 | !is_int($pos2)) {
                return false;
            } else {

                $pos1 += 8;
                $pos2 -= $pos1;
                // clean the xml info
                if ($_SESSION["ticket"] == substr($http_response, $pos1, $pos2)) {
                    AlfrescoConnect::$ticket = $_SESSION["ticket"];
                    return true;
                }
            }
        }
        catch (Exception $e) {
            return false;
        }
    }

    static public function CustomAuthentication($username=''){

        $url = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$userLogin;
        if ($auth) {
            if (!AlfrescoConnect::Authenticate()) return -1;
            $url .= "?alf_ticket=".AlfrescoConnect::$ticket;
        }
        $parameter = array('username' => $username);
//      
        $response = AlfrescoConnect::Query($url, $parameter,HttpRequest::METH_POST,1,0);fb($url);fb($parameter);
        fb($response,'custom authentication result');

        return $response;
    }

    * perform query on alfresco webscripts
    *
    * @param    string  $url  alfresco webscript url
    * @param    string  $params parameter for the query
    * @param    string  $meth metohod for http request HTTP_METH_POST/HTTP_METH_GET default HTTP_METH_POST
    * @param    boolean $auth set whether or not to need authentication
    * @return   mixed   -1 for authentication faliure, -2 for query faliure
    */
    static public function Query($url, $params, $meth = HTTP_METH_POST, $auth = 1, $decode = 1, $ticketUser='') {
        //Aggiunto per evitare il caching 
        //fb($url, "Query url");
        //fb($params, "Query params");
        //print_r(debug_backtrace());
        $nocache=time();
        $params['nocache']=$nocache;
        if ($auth) {
            if(strcmp($ticketUser,'')==0){

                if (!AlfrescoConnect::Authenticate()) return -1;
                $params['alf_ticket'] = AlfrescoConnect::$ticket;
            }
            else{

                $params['alf_ticket'] = $ticketUser;
            }

        }
        fb($params,'param');
        try {
            //fb("invio della richiesta");
            $url=$url."?nocache=$nocache";
            $r= new HttpRequest($url, $meth);
            $r->addQueryData($params);
            $r->send() ;
            fb($r);
            $http_response = $r->getResponseBody();
            fb($http_response);
            if (!$decode) return $http_response;


            $json = new Services_JSON();

            return object2array($json->decode($http_response));

            //return json_decode($http_response, true);
        }
        catch (Exception $e) {
            return -2;
        }
    }   

    /**
     * Azioni su Alfresco
     * 
     */

    static public function createNDG($ndg, $user){
        $url = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$createNDG;
        fb("Crea l'ndg,$url");
        if (strcmp($user,'')!=0) {
            $ticket = AlfrescoConnect::Authenticate($user);
            if (!$ticket) return -1;
        }
        $parameter = array(ModelParameter::$ndg => $ndg);

        $response = AlfrescoConnect::Query($url, $parameter,HTTP_METH_POST,1,1,AlfrescoConnect::$userTicket);

        return $response;

    }

}

I've got a weird problem. I've created a procedure in PHP that does these things:

  1. Read data (9.000 rows) from a MySQL table
  2. Writes a row to another table
  3. Create a folder in Alfresco based on a field in the row

I've got this strange problem (only on one Alfresco installation, on others I don't have the problem), after the first 2-3 rows the password for the admin user gets deleted from Alfresco (if you look in the db, you can't find it) and so the procedure stops. I'm using Alfresco Community 3.2.

Here is the PHP code of the procedure:

   require_once("../components/com_astra/libs/AlfrescoConnect.php");
require_once("../components/com_astra/libs/FirePHPCore/fb.php");
$username = "***";
$password = "****;";
$hostname = "localhost"; 
ob_start();
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$selected = mysql_select_db("lbs_8",$dbhandle)
  or die("Could not select examples");
$result = mysql_query("SELECT count(*) as quanti FROM ast_tabellaTemporaneaNdg");
if (!$result) {
    die('ERRORE: ' . mysql_error());
}
$totaleTabella = mysql_result($result, 0);
echo("La tabella ast_tabellaTemporaneaNdg contiene [$totaleTabella] records<br>");
echo("Conto il numero di record della vista di transcodifica<br>");
$result = mysql_query("SELECT count(*) as quanti FROM vista_ndg_normalizzati");
if (!$result) {
    die('ERRORE: ' . mysql_error());
}
$totaleVista = mysql_result($result, 0);
echo("La vista vista_ndg_normalizzati contiene [$totaleVista] records<br>");
if ($totaleTabella == $totaleVista){
    echo("Tutte le righe della tabella ast_tabellaTemporaneaNdg sono transcodificate correttamente<br>");
    echo("Saranno quindi importati [$totaleTabella] records<br>");
}else{
    echo("Non tutte le righe della tabella ast_tabellaTemporaneaNdg sono transcodificate correttamente<br>");
    echo("nella tabella ast_tabellaTemporaneaNdg sono presenti [$totaleTabella] records, di questi solo [$totaleVista] transcodificano correttamente<br>");
    $handle = fopen("ndgNonImportabili.txt", "w");
    $result = mysql_query("SELECT ndg FROM ast_tabellaTemporaneaNdg WHERE ndg NOT IN (SELECT ndg from vista_ndg_normalizzati)");
    if (!$result) {
        die('ERRORE: ' . mysql_error());
    }
    while ($row = mysql_fetch_assoc($result)){
        $ndg = "NDG: ".$row["ndg"]."\n";
        fwrite ($handle, $ndg);

    }
    fclose($handle);
    echo("Gli NDG non importabili sono stati loggati nel file ndgNonImportabili.txt<br>");
    //die("L'importazione avra' inizio solo quando tutti gli NDG saranno importabili. I motivi per cui un ndg non è importabile possono essere: incorenza fra Natura Giuridica 1 e natura giuridica 2, Incoerenza fra comune, Provincia e Regione<br>");
}
$result = mysql_query("SELECT * FROM vista_ndg_normalizzati");
//fb($result, 'risultati');
$handle = fopen("logImportazione.txt", "w");
while ($row = mysql_fetch_assoc($result)) {
    $user = "admin";
    $ndg = $row['ndg'];
    $response = AlfrescoConnect::createNDG($ndg, $user);
    $status = $response['esito'];
    if($status == "OK"){
        $ragioneSociale = mysql_real_escape_string($row['ragioneSociale']);
        $query = "SET FOREIGN_KEY_CHECKS=0";
        $resultSetKeys = mysql_query($query);
        $query = "INSERT INTO ast_Cliente (idUtente, idNaturaGiuridica,  idTipoSegmento, idRegione, idProvincia, idComune,  ragioneSociale, ndg, idNaturaGiuridica2) VALUES ";
        $query .= " (1, ".$row['idNaturaGiuridica'].", 2 , ".$row['idRegione'].", ".$row['idProvincia'].", ".$row['idComune'].", '".$ragioneSociale."', '".$ndg."', ".$row['idNaturaGiuridica2'].")";
        //fb($query);
        $resultInsert = mysql_query($query);
        if (!$resultInsert) {
            $messaggio = "Si è verificato un errore nell'importazione dell'ndg [$ndg]: [".mysql_error()."]\n";
        }else{
            $messaggio = "[$ndg] importato con successo\n";
        }
        fwrite ($handle, $messaggio);
    }else{
        $messaggio = "Si è verificato un errore nella creazione della cartella per l'ndg [$ndg] su alfresco. ERRORE: [".$response['motivazione']."]\n";
        fwrite ($handle, $messaggio);

    }
   }
fclose($handle);
echo("importazione completata: i risultati dell'importazione sono stati salvati nel file logImportazione.txt");
?> 

The folder is created by calling $response = AlfrescoConnect::createNDG($ndg, $user); where $ndg is the name of the folder and $user is the user who created it

Here is the code of AlfrescoConnect.php:

class AlfrescoConnect
{

    static public $webscriptURL = "http://localhost:8080/alfresco/service";
    static public $login = "/api/login";
    static public $login_ticket = "/api/login/ticket";
    static public $alfrescoPath = "http://localhost:8080";

    static public $alfrescoContext = "/alfresco";

    static public $upload_file_script = "/astra/upload";
    static public $uploadFile = "/astra/uploaddoc";
    static public $search_document = "/astra/cercadocumenti";
    static public $createNDG = "/astra/creandg";
    static public $createPEFPerNDG = "/astra/creapef";
    static public $searchDocumentPerConfirm = "/astra/cercadocumentoperconferma";
    static public $confirmDocument = "/astra/confermadocumenti";
    static public $getPEF = "/astra/estraidatipef";
    static public $updatePEF = "/astra/aggiornapef";
    static public $documentCounter = "/astra/contadocumenti";
    static public $userLogin = "/astra/creautente";
    static public $cancella = "/astra/managedocumentversions";
    static public $alfUsername = "admin";
    static public $alfPassword = "admin";

    static public $ticket = "";
    static public $userTicket = ""; 

    static public function Authenticate($username='') {
        //fb($username);
        if(strcmp($username,'')==0){
            if (AlfrescoConnect::isAuthenticated()) return true;
            $link = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$login."?u=".AlfrescoConnect::$alfUsername."&pw=".AlfrescoConnect::$alfPassword . "&noCache=" .time();
            fb($link, "LINK");
        }else{
            AlfrescoConnect::$userTicket =  AlfrescoConnect::CustomAuthentication($username);
            return true;
        }
        try {

            //perform a http/get request to get tiket
            // Try to create a ticket
            // If the ticket fails, it means that the username and/or password are wrong
            $r= new HttpRequest($link, HttpRequest::METH_GET);
            $r->send() ;
            $http_response = $r->getResponseBody();fb($http_response, "RISPOSTA");
            $pos1 = stripos($http_response, "<ticket>");
            $pos2 = stripos($http_response, "</ticket>");
            //ceck if token is returned 
            if ($pos1<0 | !is_int($pos1) || $pos2<0 | !is_int($pos2)) {
                AlfrescoConnect::$ticket = "";
                $returnValue = false;
            } else {

                $pos1 += 8;
                $pos2 -= $pos1;
                // clean the xml info
                AlfrescoConnect::$ticket = substr($http_response, $pos1, $pos2);
                $returnValue = true;
            }
            //fb(AlfrescoConnect::$ticket);
            $_SESSION["ticket"] = AlfrescoConnect::$ticket;
            return true;

        }
        catch (Exception $e) {
            fb($e, "Eccezione");
            AlfrescoConnect::$ticket = "";
            $_SESSION["ticket"] = AlfrescoConnect::$ticket;
            return $returnValue;
        }

    }
    static public function isAuthenticated() {
        if (!isset($_SESSION["ticket"])) return false;
        $link = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$login_ticket."/".$_SESSION["ticket"]."?alf_ticket=".$_SESSION["ticket"]."&noCache=" .time();
        fb($link, 'link in isauth');
        try {

            //perform a http/get request to get tiket
            // Try to create a ticket
            // If the ticket fails, it means that the username and/or password are wrong
            $r= new HttpRequest($link, HttpRequest::METH_GET);
            $r->send() ;
            $http_response = $r->getResponseBody();

            $pos1 = stripos($http_response, "<ticket>");
            $pos2 = stripos($http_response, "</ticket>");
            //ceck if token is returned 
            if ($pos1<0 | !is_int($pos1) || $pos2<0 | !is_int($pos2)) {
                return false;
            } else {

                $pos1 += 8;
                $pos2 -= $pos1;
                // clean the xml info
                if ($_SESSION["ticket"] == substr($http_response, $pos1, $pos2)) {
                    AlfrescoConnect::$ticket = $_SESSION["ticket"];
                    return true;
                }
            }
        }
        catch (Exception $e) {
            return false;
        }
    }

    static public function CustomAuthentication($username=''){

        $url = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$userLogin;
        if ($auth) {
            if (!AlfrescoConnect::Authenticate()) return -1;
            $url .= "?alf_ticket=".AlfrescoConnect::$ticket;
        }
        $parameter = array('username' => $username);
//      
        $response = AlfrescoConnect::Query($url, $parameter,HttpRequest::METH_POST,1,0);fb($url);fb($parameter);
        fb($response,'custom authentication result');

        return $response;
    }

    * perform query on alfresco webscripts
    *
    * @param    string  $url  alfresco webscript url
    * @param    string  $params parameter for the query
    * @param    string  $meth metohod for http request HTTP_METH_POST/HTTP_METH_GET default HTTP_METH_POST
    * @param    boolean $auth set whether or not to need authentication
    * @return   mixed   -1 for authentication faliure, -2 for query faliure
    */
    static public function Query($url, $params, $meth = HTTP_METH_POST, $auth = 1, $decode = 1, $ticketUser='') {
        //Aggiunto per evitare il caching 
        //fb($url, "Query url");
        //fb($params, "Query params");
        //print_r(debug_backtrace());
        $nocache=time();
        $params['nocache']=$nocache;
        if ($auth) {
            if(strcmp($ticketUser,'')==0){

                if (!AlfrescoConnect::Authenticate()) return -1;
                $params['alf_ticket'] = AlfrescoConnect::$ticket;
            }
            else{

                $params['alf_ticket'] = $ticketUser;
            }

        }
        fb($params,'param');
        try {
            //fb("invio della richiesta");
            $url=$url."?nocache=$nocache";
            $r= new HttpRequest($url, $meth);
            $r->addQueryData($params);
            $r->send() ;
            fb($r);
            $http_response = $r->getResponseBody();
            fb($http_response);
            if (!$decode) return $http_response;


            $json = new Services_JSON();

            return object2array($json->decode($http_response));

            //return json_decode($http_response, true);
        }
        catch (Exception $e) {
            return -2;
        }
    }   

    /**
     * Azioni su Alfresco
     * 
     */

    static public function createNDG($ndg, $user){
        $url = AlfrescoConnect::$webscriptURL.AlfrescoConnect::$createNDG;
        fb("Crea l'ndg,$url");
        if (strcmp($user,'')!=0) {
            $ticket = AlfrescoConnect::Authenticate($user);
            if (!$ticket) return -1;
        }
        $parameter = array(ModelParameter::$ndg => $ndg);

        $response = AlfrescoConnect::Query($url, $parameter,HTTP_METH_POST,1,1,AlfrescoConnect::$userTicket);

        return $response;

    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

意犹 2024-10-28 23:41:09

这是一个记忆问题。永远不要尝试在只有 1GB 内存的机器上运行 Alfresco!

It was a memory problem. Never ever try to run Alfresco on a machine with only 1GB of memory!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文