Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407

    Plesk e databases mysql

    ciao ragazzi, ho un problemino..

    io ho uno script dove creo dinamicamente da php vari database mysql, ci lavoro con backup e restore, ecc... e fin qui tutto bene..


    Il problema è che plesk non mi vede i dataase creati da script, e quindi non riesce a farne i backup.. tuttavia dal phpmyadmin lanciato dal plesk, e da script, i database si comportano cmq correttamente senza problemi, quindi credo che il problema sia 'solo' che plesk non 'vede' tutti i vari database (e non vede nemmeno gli utenti che creo da phpmyadmin o da codice)

    a qualcuno è già capitato?
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

  2. #2
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407
    Visto che nessuno mi ha risposto, posto i miei risultati se mai dovrebbero tornare utili a qualcuno nella mia stessa situazione:

    Elenco di API XML Plesk, gestibili tranquillamente da php tramite CURL:
    http://download1.parallels.com/Plesk...-rpc/index.htm

    Per chi non vuole usare il DOM per parsare i result delle varie richieste, questa funzione è molto comoda (anche se abbastaza lenta come esecuzione):
    http://www.bin-co.com/php/scripts/xml2array/


    e infine, questo è il codice che ho 'mixato' io:
    Codice PHP:
    class ApiRequestException extends Exception {}
    function 
    curlInit($host$login$password){
        
    $curl curl_init();
        
    curl_setopt($curlCURLOPT_URL"https://{$host}:8443/enterprise/control/agent.php");
        
    curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
        
    curl_setopt($curlCURLOPT_POSTtrue);
        
    curl_setopt($curlCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($curlCURLOPT_SSL_VERIFYHOSTfalse);
        
    curl_setopt($curlCURLOPT_HTTPHEADER, array("HTTP_AUTH_LOGIN: {$login}""HTTP_AUTH_PASSWD: {$password}""HTTP_PRETTY_PRINT: TRUE""Content-Type: text/xml"));
        return 
    $curl;
    }
    function 
    sendRequest($curl$packet){
        
    curl_setopt($curlCURLOPT_POSTFIELDS$packet);
        
    $result curl_exec($curl);
        if (
    curl_errno($curl)) {
            
    $errmsg curl_error($curl);
            
    $errcode curl_errno($curl);
            
    curl_close($curl);
            throw new 
    ApiRequestException($errmsg$errcode);
        }
        
    curl_close($curl);
        return 
    $result;
    }
    /**
     * xml2array() will convert the given XML text to an array in the XML structure.
     * Link: [url]http://www.bin-co.com/php/scripts/xml2array/[/url]
     * Arguments : $contents - The XML text
     *                $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the tag values - this results in a different array structure in the return value.
     * Return: The parsed XML in an array form.
     */
    function xml2array($contents$get_attributes=1){
        if(!
    $contents) return array();
        if(!
    function_exists('xml_parser_create')){
            print 
    "'xml_parser_create()' function not found!";
            return array();
        }
        
    //Get the XML parser of PHP - PHP must have this module for the parser to work
        
    $parser xml_parser_create();
        
    xml_parser_set_option$parserXML_OPTION_CASE_FOLDING);
        
    xml_parser_set_option$parserXML_OPTION_SKIP_WHITE);
        
    xml_parse_into_struct$parser$contents$xml_values );
        
    xml_parser_free$parser );
        if(!
    $xml_values) return;//Hmm...
        //Initializations
        
    $xml_array = array();
        
    $parents = array();
        
    $opened_tags = array();
        
    $arr = array();
        
    $current = &$xml_array;
        
    //Go through the tags.
        
    foreach($xml_values as $data){
            unset(
    $attributes,$value);//Remove existing values, or there will be trouble
            //This command will extract these variables into the foreach scope
            // tag(string), type(string), level(int), attributes(array).
            
    extract($data);//We could use the array by itself, but this cooler.
            
    $result '';
            if(
    $get_attributes){//The second argument of the function decides this.
                
    $result = array();
                if(isset(
    $value)) $result['value'] = $value;
                
    //Set the attributes too.
                
    if(isset($attributes)){
                    foreach(
    $attributes AS $attr => $val){
                        if(
    $get_attributes == 1$result['attr'][$attr] = $val//Set all the attributes in a array called 'attr'
                        /**  :TODO: should we change the key name to '_attr'? Someone may use the tagname 'attr'. Same goes for 'value' too */
                    
    }
                }
            }else if(isset(
    $value)){
                
    $result $value;
            }
            
    //See tag status and do the needed.
            
    if($type == "open"){//The starting of the tag '<tag>'
                
    $parent[$level-1] = &$current;
                if(!
    is_array($current) OR (!in_array($tagarray_keys($current)))){//Insert New tag
                    
    $current[$tag] = $result;
                    
    $current = &$current[$tag];
                }else{ 
    //There was another element with the same tag name
                    
    if(isset($current[$tag][0])){
                        
    array_push($current[$tag], $result);
                    }else{
                        
    $current[$tag] = array($current[$tag],$result);
                    }
                    
    $last count($current[$tag]) - 1;
                    
    $current = &$current[$tag][$last];
                }
            }else if(
    $type == "complete"){//Tags that ends in 1 line '<tag />'
                //See if the key is already taken.
                
    if(!isset($current[$tag])){//New Key
                    
    $current[$tag] = $result;
                }else{
    //If taken, put all things inside a list(array)
                    
    if((is_array($current[$tag]) and $get_attributes == 0)//If it is already an array...
                            
    or (isset($current[$tag][0]) and is_array($current[$tag][0]) and $get_attributes == 1)){
                        
    array_push($current[$tag],$result); // ...push the new element into that array.
                    
    }else{//If it is not an array...
                        
    $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
                    
    }
                }
            }else if(
    $type == 'close'){ //End of tag '</tag>'
                
    $current = &$parent[$level-1];
            }
        }
        return(
    $xml_array);
    }

    //funzione di esempio
    function createDatabaseByPlesk($dbName){
        
    $host 'xx.xx.xxx.xxx'//host del server
        
    $login 'xxxxx'//username plesk
        
    $password 'xxxxxxx'//password plesk
        
    $domainId xx//id del dominio
        
        //Richiesta, i tag variano in base alla richiesta che si desidera
        
    $creazioneDb "<packet version=\"1.4.2.0\">";
        
    $creazioneDb .= "<database>";
        
    $creazioneDb .= "<add-db>";
        
    $creazioneDb .= "<domain-id>$domainId</domain-id>";
        
    $creazioneDb .= "<name>$dbName</name>";
        
    $creazioneDb .= "<type>mysql</type>";
        
    $creazioneDb .= "</add-db>";
        
    $creazioneDb .= "</database>";
        
    $creazioneDb .= "</packet>";
        
    $curl curlInit($host$login$password);
        
    $responseDb sendRequest($curl$creazioneDb);
        
    $rayResponseDb xml2array($responseDb0);
        
    $resultDb $rayResponseDb['packet']['database']['result']['add-db']['status'];
        if(
    $resultDb == 'ok'){
            
    $idDb $rayResponseDb['packet']['database']['result']['add-db']['id'];
        }else{
            die(
    "database non creato, errore: ".$rayResponseDb['packet']['database']['result']['add-db']['errtext']);
        }
        return 
    $idDb;
    }

    $creazioneDB createDatabaseByPlesk('prova');
    echo 
    "database creato, id: $creazioneDB"
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

  3. #3
    Utente di HTML.it L'avatar di Fool
    Registrato dal
    May 2002
    Messaggi
    8,342
    Scusa se resuscito la discussione,
    con il tuo codice riesco a creare il db, tuttavia lo script mi da

    database non creato, errore:

    Anche se poi sul server effettivamente lo crea...

    sai aiutarmi?

    Grazie!

  4. #4
    Utente di HTML.it L'avatar di strae
    Registrato dal
    Apr 2008
    Messaggi
    407
    Originariamente inviato da Fool
    Scusa se resuscito la discussione,
    con il tuo codice riesco a creare il db, tuttavia lo script mi da

    database non creato, errore:

    Anche se poi sul server effettivamente lo crea...

    sai aiutarmi?

    Grazie!
    non saprei.. verifica che la tua versione di plesk corrisponda a quella che utilizzo nel codice di esempio, e altrimenti controlla che la richiesta xml sia corretta (nella documentazione che ho linkato, cerca per la tua versione)

    altrimenti.. magari ho sbagliato l'array dell'errore, nella riga con
    Codice PHP:
    die("database non creato, errore: ".$rayResponseDb['packet']['database']['result']['add-db']['errtext']); 
    lancia un print_r($rayResponseDb);

    e spulcia cosa ti tira fuori... vabbhè se no stmpa direttamente $responseDb prima di processarlo con xml2array()...
    You HAVE to assume your visitor is a maniac serial killer, out to destroy your application. And you have to prevent it.
    I can accept failure, everyone fails at something - But I can't accept not trying.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.