Results 1 to 4 of 4

Thread: Help - Creating signatures via SOAP

  1. #1
    Join Date
    Jun 2011
    Posts
    68
    Rep Power
    4

    Default [SOLVED] Help - Creating signatures via SOAP

    Howdy All,

    I have a "create user" script for zimbra, to be able to create new users, add them to a range of distribution lists, create aliases for them, and assign them to a COS all via the command line.

    Im looking for a way to add a signature to the user's account after we create it (or during if its possible).
    We have folks who use both Thunderbird and Zimbra Web, and they all have a default thunderbird.sig with their user details created when their user account is created on the system (before email account is created)

    Ive come up with the following snippet of xml that kinda works - but theres two problems...

    First, a global admin user (who is running the script) creates and auth token

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
    <context xmlns="urn:zimbra"/>
    </soap:Header>
    <soap:Body>
    <AuthRequest xmlns="urn:zimbraAdmin">
    <name>$USER@domain.com</name>
    <password>$PASS</password>
    </AuthRequest>
    </soap:Body>
    </soap:Envelope>

    (where $USER and $PASS are the global admin's username and password)

    Upon a valid return result, we strip the token ID out from the response

    cat /tmp/authtoken.out | sed -e 's/>/ /g' -e 's/</ /g' | awk '{print $14}'

    Which leaves us with the $AUTHTOKEN string which is used to perform other functions.

    We then Create the user using the AUTHTOKEN, and assign them a COS

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
    <context xmlns="urn:zimbra">
    <authToken>$AUTHTOKEN</authToken>
    </context>
    </soap:Header>
    <soap:Body>
    <CreateAccountRequest xmlns="urn:zimbraAdmin">
    <name>$USERNAME@domain.com</name>
    <password></password>
    <a xmlns="" n="givenName">$FIRSTNAME</a>
    <a xmlns="" n="sn">$LASTNAME</a>
    <a xmlns="" n="displayName">$FIRSTNAME $LASTNAME</a>
    <a xmlns="" n="zimbraCOSId">e00428a1-0c00-11d9-836a-000d93afea2a</a>
    </CreateAccountRequest>
    </soap:Body>
    </soap:Envelope>

    once the user is created, we query the server for the user's zimbraID that was created - where $USERNAME is the user's zimbra login name

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
    <context xmlns="urn:zimbra">
    <authToken>$AUTHTOKEN</authToken>
    </context>
    </soap:Header>
    <soap:Body>
    <GetAccountRequest xmlns="urn:zimbraAdmin" applyCos="0" attrs="zimbraId">
    <account by="name">$USERNAME</account>
    </GetAccountRequest>
    </soap:Body>
    </soap:Envelope>

    We then manipulate the output of the response to get the zimbraID for the user and this is used as $ID below

    cat /tmp/id.out | awk -F\" '{print $10}'


    So, once we have $ID, $USERNAME, $AUTHTOKEN - we use the following xml to create a sig.

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
    <context xmlns="urn:zimbra">
    <authToken>$AUTHTOKEN</authToken>
    </context>
    </soap:Header>
    <soap:Body>
    <CreateSignatureRequest xmlns="urn:zimbraAccount">
    <signature name="SIG" id="$ID">
    <content type="text/plain">"`cat /home/$USERNAME/.thunderbird/$USERNAME.default/$USERNAME.sig`"</content>
    </signature>
    </CreateSignatureRequest>
    <CreateSignatureResponse>
    <signature id="$ID" name="SIG"/>
    </CreateSignatureResponse>
    </soap:Body>
    </soap:Envelope>

    The two problems are:

    a) The sig is created... BUT - the sig was created for the admin user running the script - i think i have since worked out that $ID referred to in the <signature> tags, refers to an ID number you want to set the signature name to - and not "apply the sig to the user ID" captured above.

    2) the 2nd part, when we populate the <content> by doing a cat of the user's pre-made sig, it ignores new line and all the text is generated on one line. The format of the sig file is:

    --
    Firstname Lastname
    Job Role | Comany Name
    Company Address
    Company Ph. | Mobile No.

    Is someone able to help here? - a) make the sig be created for the user we've created, not the user running the script, b) how can i preserve the format of the sig, so it doesnt add the content all on one line

    Cheers
    Last edited by PhD; 10-24-2011 at 12:36 AM.

  2. #2
    Join Date
    Dec 2006
    Location
    Minneapolis MN
    Posts
    777
    Rep Power
    9

    Default

    Hello,

    You will need to use DelegateAuthRequest to change the SOAP session to the user you created.

    Your text signature may be missing newline characters, so you may want to play around with that.
    01 Networks, LLC / Cybernetik.net
    Zimbra NE and OSS Cloud Hosting
    Shared Web Hosting
    Consulting Services

  3. #3
    Join Date
    Jun 2011
    Posts
    68
    Rep Power
    4

    Default

    nice! thanks for the tip..
    that works perfectly

    so, i use the admin AUTHTOKEN to create a DELEGEATEDAUTHTOKEN using this

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
    <soap:Header>
    <context xmlns="urn:zimbra">
    <authToken>$AUTHTOKEN</authToken>
    </context>
    </soap:Header>
    <soap:Body>
    <DelegateAuthRequest xmlns="urn:zimbraAdmin">
    <account by="id">$ID</account>
    </DelegateAuthRequest>
    </soap:Body>
    </soap:Envelope>

    Strip the new delegated auth token out of the response
    DELEGATEDAUTHTOKEN=`cat /tmp/delegatedAuth.out | sed -e 's/>/ /g' -e 's/</ /g' | awk '{print $14}'`

    and formulate a new reguest using that token to generate the sig

    same as my previous post - but replace AUTHTOKEN with this..
    <authToken>$DELEGATEDAUTHTOKEN</authToken>

    Im now trying to work out what the new line ending are for the sig - ive tried \n - but that just adds the text as

    Firstname Lastname\nJob Role | Comany Name\nCompany Address\nCompany Ph. | Mobile No

  4. #4
    Join Date
    Jun 2011
    Posts
    68
    Rep Power
    4

    Default

    i think ive solved it...

    if i use the following for the content line

    <content type="text/html"><![CDATA[`cat /path/to/$USERNAME.sig`]]></content>


    and re-format the sig file to have <br> at the end of each line

    then i successfully get the sig imported into zimbra for the user

    WIN

Similar Threads

  1. Random Jabber disconnects
    By jsilence in forum Administrators
    Replies: 3
    Last Post: 08-16-2011, 01:34 PM
  2. zmzimletctl deploy zimbra_posixaccount.zip - ERROR -
    By todd_dsm in forum Administrators
    Replies: 0
    Last Post: 04-02-2009, 02:41 PM
  3. 4.0.4 to 4.5.6 upgrade failed in network edition
    By chenthil in forum Administrators
    Replies: 1
    Last Post: 08-27-2007, 10:36 AM
  4. [SOLVED] Simple backup question...
    By dameron in forum Administrators
    Replies: 3
    Last Post: 08-25-2007, 10:36 PM
  5. Creating user accounts with SOAP
    By Andreas in forum Administrators
    Replies: 2
    Last Post: 01-19-2006, 01:17 AM

Posting Permissions

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