Jump to content


Photo

SF 600 API programming


  • Please log in to reply
10 replies to this topic

#1 Roel van den Bussche

Roel van den Bussche
  • Members
  • 4 posts

Posted 24 December 2009 - 07:53 AM

Hi everyone,I'm trying to add some information to my barracuda via the API. So far no luck at all.. I've read the API guide 4.x thoroughly.In the guide they give information about how to add information to the cuda by using methods like "config.add" e.g. I'm able to add an domain to the unit and set the right IP address for the mail server. For this I use the URL:http://barrasIP:8000/cgi-bin/add_domain.cgi?password=secr3t&domain=unfiltereddomain.nlMy wish is to do this via the XML-RPC method in combination with PHP in the future. By using this I might also be able to add an user as domain admin for the specified domain.Here is my question, is someone familiar with the XML-RPC method? If so would you like to help me out?

#2 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 08 May 2010 - 01:27 PM

I'm using ASP not PHP but hopefully tis will get you started in the right direction.The url you want to post to is:http://BARRACUDAIP:8000/cgi-mod/api.cgi?password=YOURAPIPASSwordTo create a domain name mydomain.com you would use the domain.add method and the XML would be as follows:<?xml version="1.0" encoding="UTF8"?><methodCall><methodName>domain.add</methodName><params><param><value><struct><member><name>domain</name><value><string><![CDATA[MYDOMAIN.COM]]></string></value></member></struct></value></param></params></methodCall>To edit the settings of the domain use the config.set method:<?XML version="1.0" encoding="UTF8"?><methodCall><methodName>config.set</methodName><params><param><value><struct># Domain > Basic > IP Configuration tab<member><name>mta_relay_advanced_host</name><value>0.0.0.0</value></member><member><name>mta_relay_advanced_email</name><value>administrator@mydomain.com</value></member><member><name>mta_relay_advanced_port</name><value>25</value></member># Domain > Users > LDAP Configuration tab<member><name>mta_ldap_advanced_host</name><value>0.0.0.0</value></member><member><name>mta_recipient_verify_advanced_unify</name><value>Yes</value></member><member><name>mta_ldap_advanced_username</name><value>cn=barracuda,ou=service,ou=domain,${defaultNamingContext}</value></member><member><name>mta_ldap_advanced_password</name><value>LDAPPASSWORD</value></member><member><name>mta_ldap_advanced_email</name><value>administrator@mydomain.com</value></member># Domain > Users > Valid Recipients tab<member><name>mta_recipient_verify_advanced_exchange</name><value>Yes</value></member># Member to affect and member type <member><name>path</name><value><string><![CDATA[mydomain.com]]></string></value></member><member><name>type</name><value><string><![CDATA[domain]></string></value></member></struct></value></param></params></methodCall>The member name of the parameters you want to alter match the field names on the corresponding pages of the Barracuda. Just view the html source to find them.As far as the specific PHP code, I believe you would use:<?php$fp = fsockopen("BARRACUDAIP", 8000, $errno, $errstr, 30); $xmlpacket ='<?XML version="1.0" encoding="UTF8"?> <Your_xml> </Your_xml>'; $contentlength = strlen($xmlpacket); $out = "post /cgi-mod/api.cgi?password=YourAPIPassword HTTP/1.0rn"; $out .= "Host: BARRACUDAIP:8000rn"; $out .= "Connection: Keep-Alivern"; $out .= "Content-type: text/xmlrn"; $out .= "Content-length: $contentlengthrnrn"; $out .= "xml=$xmlpacket"; fwrite($fp, $out); while (!feof($fp)) { $theOutput .= fgets($fp, 128); // $theOutput is the response returned from the remote script } fclose($fp); ?>But I am not a PHP guy and I culled this off the web without testing it. If someone could confirm or correct I'd appreciate it!Hope this helps!

#3 Daniel Senie

Daniel Senie
  • Members
  • 12 posts

Posted 25 June 2010 - 03:19 PM

I tried the domain.add request from the example given. With 4.0.xx firmware, I get a response 451, Invalid Request. There is no such response listed in the API guide. It'd sure be nice if the API guide matched the running software :(If there's anyone who has successfully used the 4.x API, I'd sure love to see some example scripts.

#4 Roel van den Bussche

Roel van den Bussche
  • Members
  • 4 posts

Posted 26 June 2010 - 02:05 AM

I tried the domain.add request from the example given. With 4.0.xx firmware, I get a response 451, Invalid Request. There is no such response listed in the API guide. It'd sure be nice if the API guide matched the running software :(If there's anyone who has successfully used the 4.x API, I'd sure love to see some example scripts.

I'll Try it out on monday, first thing in the morning. Reply back here.Have a great weekend

#5 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 01 July 2010 - 06:57 PM

How'd you guys make out with this? I have seen references to doing this in with Pear and Curl but don't know enough about either to troubleshoot the errors I get when I attempt it.As I said before, I'm not a PHP guy. It can be easily accomplished in asp or vbscript. I also do it in a VBA module in Excel so I can store the info about my domains and easily recreate them or edit them with a few clicks.Here's the sample code, in VBA remove the Server. when creating the objects:Set xmlHTTP = Server.CreateObject("MSXML2.ServerxmlHTTP")xmlHTTP.Open "POST", "http://BARRACUDAIP:8000/cgi-mod/api.cgi?password=BARRACUDAAPIPASSWORD", falsexmlHTTP.setRequestHeader "Content-Type","text/xml"xmlHTTP.send (strXML)Set objXMLDoc = Server.CreateObject("Microsoft.XMLDOM") objXMLDoc.async = False objXMLDoc.loadXML(xmlHTTP.responseText) Set objRoot = objXMLDoc.documentElement Set objNodeList = objRoot.getElementsByTagName("string") For Each Elem In objNodeList Response.Write(Elem.firstChild.nodeValue & "<br>") 'However you want to handle the responseNextSet xmlHTTP = NothingSet objRoot = NothingSet objNodeList = Nothing

#6 Roel van den Bussche

Roel van den Bussche
  • Members
  • 4 posts

Posted 02 July 2010 - 01:50 AM

The scripts above doesn�t work.

#7 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 02 July 2010 - 05:17 PM

Roe,Are you talking about the PHP in my original post or the ASP in my last post. I am using the ASP, it's a direct copy and paste from the file I am using. The only thing I left out was the XML string as it seemed redundant. If it's the ASP, what's the error you are receiving?What browser are you using? If it's IE, is Show Friendlty HTTP Errors turned off? What's the hosting enviroment/OS?

#8 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 03 July 2010 - 05:24 PM

Gentlemen,Minor correction got this working!<?php$fp = fsockopen("BARRACUDAIP", 8000, $errno, $errstr, 30); $xmlpacket ='<?XML version="1.0" encoding="UTF8"?> <Your_xml> </Your_xml>'; $contentlength = strlen($xmlpacket); $out = "POST /cgi-mod/api.cgi?password=YourAPIPassword HTTP/1.0rn"; $out .= "Host: BARRACUDAIP:8000rn"; $out .= "Connection: Keep-Alivern"; $out .= "Content-type: text/xmlrn"; $out .= "Content-length: $contentlengthrnrn"; $out .= "xml=$xmlpacket"; fwrite($fp, $out); while (!feof($fp)) { $theOutput .= fgets($fp, 128); // $theOutput is the response returned from the remote script } fclose($fp); ?>Got to love case sensitivity!I leave it to you to figure out the return!

#9 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 07 July 2010 - 11:46 AM

It would be a lot more effective to have a useful conversation with someone if there wasn't such a significant delay in posting............

#10 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 08 July 2010 - 11:28 AM

Guys, I installed PHP and tested this. Got to love case sensitivity. The method must be all caps.<?php$fp = fsockopen("BARRACUDAIP", 8000, $errno, $errstr, 30); $xmlpacket ='<?XML version="1.0" encoding="UTF8"?> <Your_xml> </Your_xml>'; $contentlength = strlen($xmlpacket); $out = "POST /cgi-mod/api.cgi?password=YourAPIPassword HTTP/1.0rn"; $out .= "Host: BARRACUDAIP:8000rn"; $out .= "Connection: Keep-Alivern"; $out .= "Content-type: text/xmlrn"; $out .= "Content-length: $contentlengthrnrn"; $out .= "xml=$xmlpacket"; fwrite($fp, $out); while (!feof($fp)) { $theOutput .= fgets($fp, 128); // $theOutput is the response returned from the remote script } fclose($fp); ?>I'll leave it to you to handle the output.

#11 Mathew DeCourcy

Mathew DeCourcy
  • Members
  • 0 posts

Posted 05 August 2010 - 11:10 AM

How'd you guys (or any one else for that matter) make out with this?