SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    parasing xml file

    Hi,

    I am trying to update user A's password in the xml file. The password is in md5 hash format.

    <FileZillaServer>
    <Settings>
    <Item name="Admin port" type="numeric">14147</Item>
    </Settings>
    <Groups/>
    <Users>
    <User Name="anonymous">
    <Option Name="Pass"/>
    <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:\asp">
    <Option Name="FileRead">1</Option>
    <Option Name="FileWrite">0</Option>
    <Option Name="FileDelete">0</Option>
    <Option Name="FileAppend">0</Option>
    <Option Name="DirCreate">0</Option>
    <Option Name="DirDelete">0</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>
    <User Name="A">
    <Option Name="Pass">7fc56270e7a70fa81a5935b72eacbe29</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:\asp">
    <Option Name="FileRead">1</Option>
    <Option Name="FileWrite">1</Option>
    <Option Name="FileDelete">1</Option>
    <Option Name="FileAppend">0</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>
    <User Name="B">
    <Option Name="Pass">9d5ed678fe57bcca610140957afab571</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:\asp">
    <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>
    <User Name="C">
    <Option Name="Pass">0d61f8370cad1d412f80b84d143e1257</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:\asp">
    <Option Name="FileRead">1</Option>
    <Option Name="FileWrite">1</Option>
    <Option Name="FileDelete">1</Option>
    <Option Name="FileAppend">0</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>
    </Users>
    </FileZillaServer>

    $new_password = md5($_POST['new_password']);


    $sx = simplexml_load_file('check.xml');

    print_r($sx);


    Can someone tell me how to navigate to the user A's password and update the new password.




    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Sep 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's one way:
    PHP Code:
     
    $sx 
    simplexml_load_file('check.xml');
    $pass $sx->xpath("/FileZillaServer/Users/User[@Name='A']/Option[@Name='Pass']");
    $pass[0][0] = $new_password;
    file_put_contents('check.xml'$sx->asXML()); 

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Another way, although I'd go with xpath.
    PHP Code:
    foreach ($xml->Users->User as $User) {
        if (
    $User->attributes()->Name == 'A') {
            foreach (
    $User->Option as $Option) {
                if (
    $Option->attributes()->Name == 'Pass') {
                    
    $Option[0] = 'new md5';
                    break 
    2;
                }
            }
        }

    Using a for loop instead of foreach for the outer loop could save significant memory if this file is large.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •