FileZilla Server and XML-files. Any simpleXML help?

Discussion in 'PHP' started by navbeacon, Oct 10, 2008.

  1. #1
    I use FileZilla server as the FTP solution for my users. I have a script which runs a simplexml function and creates a user in the XML file.

    The XML structure:
    
    <?xml version="1.0"?>
    <FileZillaServer>
    <Settings>
    <Item name="Serverports" type="string">21</Item>
    <Item name="Number of Threads" type="numeric">4</Item>
    
    ... lots of other <Item>-tags with settings here ...
    
    <Item name="Admin port" type="numeric">****</Item>
    <SpeedLimits>
    <Download/>
    <Upload/>
    </SpeedLimits>
    </Settings>
    <Groups/>
    <Users>
    <User Name="user1">
    <Option Name="Pass">3196a536138f736a0f9cbeefa8b5a2e9</Option>
    <Option Name="Group"/>
    <Option Name="Bypass server userlimit">0</Option>
    <Option Name="User Limit">0</Option>
    <Option Name="IP Limit">0</Option>
    <Option Name="Enabled">1</Option>
    <Option Name="Comments"/>
    <Option Name="ForceSsl">0</Option>
    <IpFilter>
    <Disallowed/>
    <Allowed/>
    </IpFilter>
    <Permissions>
    <Permission Dir="C:\path">
    <Option Name="FileRead">1</Option>
    <Option Name="FileWrite">1</Option>
    <Option Name="FileDelete">1</Option>
    <Option Name="FileAppend">1</Option>
    <Option Name="DirCreate">1</Option>
    <Option Name="DirDelete">1</Option>
    <Option Name="DirList">1</Option>
    <Option Name="DirSubdirs">1</Option>
    <Option Name="IsHome">1</Option>
    <Option Name="AutoCreate">0</Option>
    </Permission>
    </Permissions>
    <SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10" ServerUlLimitBypass="0">
    <Download/>
    <Upload/>
    </SpeedLimits>
    </User>
    
    ... more users here if any ...
    
    </Users>
    </FileZillaServer>
    
    Code (markup):
    As you can see there is an <option>-tag with the users password encrypted in MD5. Keeping in mind that there are several <User>-tags, how do I change this password with a PHP script?

    This is the script I use to add users:

    
    $userXMLString ='
    <User Name="'.$user.'">
    <Option Name="Pass">'.$md5pass.'</Option>
    <Option Name="Group"/>
    <Option Name="Bypass server userlimit">0</Option>
    <Option Name="User Limit">0</Option>
    <Option Name="IP Limit">0</Option>
    <Option Name="Enabled">1</Option>
    <Option Name="Comments"/>
    <Option Name="ForceSsl">0</Option>
    <IpFilter>
    <Disallowed/>
    <Allowed/>
    </IpFilter>
    <Permissions>
    <Permission Dir="N:\hosted\\'.$user.'">
    <Option Name="FileRead">1</Option>
    <Option Name="FileWrite">1</Option>
    <Option Name="FileDelete">1</Option>
    <Option Name="FileAppend">1</Option>
    <Option Name="DirCreate">1</Option>
    <Option Name="DirDelete">1</Option>
    <Option Name="DirList">1</Option>
    <Option Name="DirSubdirs">1</Option>
    <Option Name="IsHome">1</Option>
    <Option Name="AutoCreate">0</Option>
    </Permission>
    </Permissions>
    <SpeedLimits DlType="0" DlLimit="10" ServerDlLimitBypass="0" UlType="0" UlLimit="10" ServerUlLimitBypass="0">
    <Download/>
    <Upload/>
    </SpeedLimits>
    </User>';
    	   
    	    //Funksjon fra php.net
    	    function simplexml_append(SimpleXMLElement $parent, SimpleXMLElement $new_child){
    	       $node1 = dom_import_simplexml($parent);
    	       $dom_sxe = dom_import_simplexml($new_child);
    	       $node2 = $node1->ownerDocument->importNode($dom_sxe, true);
    	       $node1->appendChild($node2);
    	    }
    	    //xml
    	    $xml = simplexml_load_file('C:\ftp\FileZilla Server.xml');
    	
    	    if($xml === false){
    	      exit('xml file could not be loaded');
    	    }
    	
    	    try{
    	      //$userXML inneholder XML for den nye brukeren som en string   
    	      $userXML = new SimpleXMLElement($userXMLString);  
    	    } catch(Exception $e){
    	      exit('Invalid XML given for user');
    	    }
    	    simplexml_append($xml->Users,$userXML);
    	    $printxml =  $xml->asXML();
    
    $filezillaxml = 'C:\ftp\FileZilla Server.xml';
    
    // Opening XML file... ( Task 9 )
        if ($handle2 = fopen($filezillaxml, 'w')) {
        echo'Task 9 complete!<br />'; } else {die('Task 9 FAIL'); }
        
    // Write user information to XML ( Task 10 )
        if (fwrite($handle2, $printxml)) {
            echo 'Task 10 complete!<br /><br />';
            } else {die('Task 10 FAIL');}
    
    
    Code (markup):
    So I am looking for a script to find and change the correct password for a given username inside this XML file. I find it very hard to achieve.

    Hope someone can help.
     
    navbeacon, Oct 10, 2008 IP
  2. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    [--(eek)--]
    scrap that, you have more users in the same file....
     
    juust, Oct 10, 2008 IP