Skip navigation
McAfee Secure sites help keep you safe from identity theft, credit card fraud, spyware, spam, viruses and online scams
2575 Views 15 Replies Latest reply: Jul 31, 2013 9:00 AM by mreco RSS 1 2 Previous Next
fwmonitor Newcomer 40 posts since
Dec 2, 2011
Currently Being Moderated

Mar 13, 2012 6:26 AM

Examples of REST scripting

Hello,

 

can somebody show some examples of using REST scripting, like add/delete list entries or modify rules?

 

best regards

  • asabban McAfee SME 1,354 posts since
    Nov 3, 2009
    Currently Being Moderated
    1. Mar 13, 2012 7:39 AM (in response to fwmonitor)
    Re: Examples of REST scripting

    Hello,

     

    the documentation is still being worked on, but it should be available soon.

     

    To use REST there are come examples with CURL available which you can try on the command line.

     

    1.) Write the REST URL into a variable (easier to read later):

     

    export REST=http://localhost:4711/Konfigurator/REST

     

    2.) You need to authenticate with valid credentials. MWG will return a Cookie which you need for further requests to be authenticated:

     

    curl -i -c cookies.txt  -H "Authorization: Basic YWRtaW46d2ViZ2F0ZXdheQ==" -X POST "$REST/login"

    curl -i -b cookies.txt "$REST/appliances"

     

    3.) You can see all available lists by using

     

    curl -i -b cookies.txt "$REST/list"

     

    4.) You can create an empty list with

     

    curl -i -b cookies.txt -X POST "$REST/list?name=newlist&type=category"

     

    5.) Get a list

     

    curl -i -b cookies.txt "$REST/list/com.scur.type.mediatype.4532"

     

    6.) Get list entry

     

    curl -i -b cookies.txt "$REST/list/com.scur.type.mediatype.4532/entry/1"

     

    7.) Delete list entry

     

    curl -i -b cookies.txt -X DELETE "$REST/list/com.scur.type.mediatype.4532/entry/1"

     

    8.) Modify list entry

     

    curl -i -b cookies.txt -X PUT -d @listEntryRequest.xml "$REST/list/com.scur.type.regex.11347/entry/1" -H "Content-Type: application/xml"

     

    where "listEntryRequest.xml" is a file which contains the new entry, such as:

     

    <entry xmlns="http://www.w3.org/2005/Atom">

    <content type="application/xml">

    <listEntry>

    <entry>com.scur.category.192</entry>

      <description />

    </listEntry>

    </content>

    </entry>

     

    I hope this helps. Rule modification is not yet possible as far as I know. If you need specific examples, just let me know, I will try to provide them.

     

    best,

    Andre

  • eelsasser McAfee SME 841 posts since
    Mar 24, 2010
    Currently Being Moderated
    3. Mar 18, 2012 11:52 AM (in response to fwmonitor)
    Re: Examples of REST scripting

    The current implementation of of REST on MWG only allows you to do certain functions.

    Actions:

    restart

    shutdown

    flushcache

    rotateLogs

    rotateAndPushLogs

    license

     

    Logs and file server files:

    list of directories and log files

    download log file

    delete log file

    list of files

    download file

    add file

    modify file

    delete file

     

    And manipulate lists. Add/Remove/Modify/etc.

     

    It does not provide access tot he rules or policy, other than the list contents.

  • dstraube McAfee Employee 90 posts since
    Jan 19, 2011
    Currently Being Moderated
    5. Apr 10, 2012 3:18 AM (in response to fwmonitor)
    Re: Examples of REST scripting

    Hello,

     

    to delete a list you just need to issue a DELETE request using the list-ID. Following the examples posted earlier it should look like this:

     

    curl -i -b cookies.txt -X DELETE "$REST/list/com.scur.type.regex.4537"

     

    Can you give an example of the request you are sending? So far I haven't seen the error you mentioned.

     

    Regards,

     

    Dirk

  • dstraube McAfee Employee 90 posts since
    Jan 19, 2011
    Currently Being Moderated
    7. Apr 12, 2012 9:36 AM (in response to fwmonitor)
    Re: Examples of REST scripting

    Yes, that's a bug. The command is correct and should work. I can reproduce the error with MWG 7.1.6.1.

     

    I can't reproduce it with MWG 7.2 (which will be released fairly soon), so it seems that it's fixed. Deleting entries or the whole list worked fine in my test and after a commit the changed entries or the list was actually gone. I tested with the latest internal MWG 7.2 build, I haven't checked with the Beta build yet.

     

    If you need the fix to be backported to the 7.1.6 branch, please raise a ticket with support.

     

    Regards,

     

    Dirk

  • consoul Newcomer 35 posts since
    Aug 18, 2011
    Currently Being Moderated
    8. Jun 18, 2013 1:54 PM (in response to fwmonitor)
    Re: Examples of REST scripting

    How do you log back out? In testing I end up with many many active sessions, which creates problems if you dont allow multiple logins per account. Thoughts?

  • eelsasser McAfee SME 841 posts since
    Mar 24, 2010
    Currently Being Moderated
    9. Jun 18, 2013 2:12 PM (in response to consoul)
    Re: Examples of REST scripting

    If you are using the examples set forth in the docs with curl:

     

    curl -i -b cookies.txt -X POST "$REST/logout"

     

     

    Message was edited by: eelsasser on 6/18/13 3:12:22 PM EDT
1 2 Previous Next

More Like This

  • Retrieving data ...

Bookmarked By (2)

Legend

  • Correct Answers - 5 points
  • Helpful Answers - 3 points