Has anybody made an automatic shell script for generating XML files for modules basing on given module directory.
I could be PHP/bash/(any script language) script. I would be very grateful if anybody would share such script.
I know there is Export XML module, but work in CMSMS not in shell, that`s why I have posted the question.
[SOLVED] Automatic XML module export script
[SOLVED] Automatic XML module export script
Last edited by ikulis on Sat Aug 08, 2009 9:58 pm, edited 1 time in total.
Re: [SOLVED] Automatic XML module export script
I have created the PHP script for automatic XML module generation. Hope somebody will find is useful.
Writes the XML data to standard output.
Writes the XML data to standard output.
Code: Select all
<?
// @author Szymon Lukaszczyk <szymon.lukaszczyk@gmail.com>
// @licence http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
//
// CreateXMLPackage extracted from CMSMS core
// changed a little
// variables to edit
$path = "/var/www/cmsmadesimple/"; // add the path to working cmsms catalog
$module = "DownloadManager"; // specify the name of your module
$modulepath = $path."modules/".$module."/"; // specify the path to module sources
// do not edit things below unless you know what are you doing
require_once(realpath($path).'/include.php');
global $gCms;
$message = '';
$files = 0;
function CreateXMLPackage( &$modinstance, &$filecount, $dir )
{
// get a file list
$filecount = 0;
$files = get_recursive_file_list( $dir, array ( '^\.svn' ,'^CVS$','^\#.*\#$','~$','\.bak$'));
$xmltxt = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmltxt .= "\n<!DOCTYPE module [
<!ELEMENT module (dtdversion,name,version,description*,help*,about*,requires*,file+)>
<!ELEMENT dtdversion (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT version (#PCDATA)>
<!ELEMENT mincmsversion (#PCDATA)>
<!ELEMENT description (#PCDATA)>
<!ELEMENT help (#PCDATA)>
<!ELEMENT about (#PCDATA)>
<!ELEMENT requires (requiredname,requiredversion)>
<!ELEMENT requiredname (#PCDATA)>
<!ELEMENT requiredversion (#PCDATA)>
<!ELEMENT file (filename,isdir,data)>
<!ELEMENT filename (#PCDATA)>
<!ELEMENT isdir (#PCDATA)>
<!ELEMENT data (#PCDATA)>
]>\n";
$xmltxt .= "<module>\n";
$xmltxt .= " <dtdversion>".MODULE_DTD_VERSION."</dtdversion>\n";
$xmltxt .= " <name>".$modinstance->GetName()."</name>\n";
$xmltxt .= " <version>".$modinstance->GetVersion()."</version>\n";
$xmltxt .= " <mincmsversion>".$modinstance->MinimumCMSVersion()."</mincmsversion>\n";
$xmltxt .= " <help>".base64_encode($modinstance->GetHelpPage())."</help>\n";
$xmltxt .= " <about>".base64_encode($modinstance->GetAbout())."</about>\n";
$desc = $modinstance->GetAdminDescription();
if( $desc != '' )
{
$xmltxt .= " <description>".$desc."</description>\n";
}
$depends = $modinstance->GetDependencies();
foreach( $depends as $key=>$val )
{
$xmltxt .= " <requires>\n";
$xmltxt .= " <requiredname>$key</requiredname>\n";
$xmltxt .= " <requiredversion>$val</requiredversion>\n";
$xmltxt .= " </requires>\n";
}
foreach( $files as $file )
{
// strip off the beginning
if (substr($file,0,strlen($dir)) == $dir)
{
$file = substr($file,strlen($dir));
}
if( $file == '' ) continue;
$xmltxt .= " <file>\n";
$filespec = $dir.DIRECTORY_SEPARATOR.$file;
$xmltxt .= " <filename>$file</filename>\n";
if( @is_dir( $filespec ) )
{
$xmltxt .= " <isdir>1</isdir>\n";
}
else
{
$xmltxt .= " <isdir>0</isdir>\n";
$data = base64_encode(file_get_contents($filespec));
$xmltxt .= " <data><![CDATA[".$data."]]></data>\n";
}
$xmltxt .= " </file>\n";
++$filecount;
}
$xmltxt .= "</module>\n";
return $xmltxt;
}
$object = $gCms->modules[$module]['object'];
$xmltxt = CreateXMLPackage($object,$files,$modulepath);
if( $files == 0 )
{
echo "<p class=\"error\">".lang('errornofilesexported')."</p>";
}
else
{
echo $xmltxt;
}
?>
Re: [SOLVED] Automatic XML module export script
Did you ever hit the XML button in "Extensions->Modules" ?
Re: [SOLVED] Automatic XML module export script
Read the first post ...NaN wrote:
Did you ever hit the XML button in "Extensions->Modules" ?
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: [SOLVED] Automatic XML module export script
Use wget
build a script to login to the admin
and request the appropriate url.
It's not difficult for experienced shell script developers.
I have created scripts for use in cron to create NMS jobs, and send them.
build a script to login to the admin
and request the appropriate url.
It's not difficult for experienced shell script developers.
I have created scripts for use in cron to create NMS jobs, and send them.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: [SOLVED] Automatic XML module export script
I`m using this as a part of bash script, which also generates the zip and bzip2 archives.
For wget u need webserver running, here it is not needed.
For wget u need webserver running, here it is not needed.
-
- Support Guru
- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
- Location: Fernie British Columbia, Canada
Re: [SOLVED] Automatic XML module export script
An excerpt from my BASH script:
Code: Select all
# do the login
_postdata="username=${username}&password=${password}&loginsubmit=Submit"
wget -o log -O outfile.1 --save-cookies ${_cookies} --keep-session-cookies --post-data=$_postdata ${sitename}/admin/login.php
_x=`grep -c 'password incorrect' outfile.1`
if [ $_x -gt 0 ]; then
echo "FATAL: Authentication error";
cd $_owd
rm -rf $_tmpdir 2>/dev/null
exit 1
fi
# Get the session key
_line=`cat $_cookies | grep ${keyname}`
if [ ${line:-notset} != notset ]; then
_sessionkey=`cat $_cookies | grep ${keyname} | tr '\t' , | cut -d, -f7`
else
_sessionkey=`cat log | grep ^Location | cut -d= -f2 | cut -d" " -f1`
fi
# Create an NMS job
_jn=`echo $_jobname | tr -s " " _`
_postdata="m1_messagelist=${message}&m1_listlist=${list}&m1_jobname=${_jn}"
wget -a log -O outfile.2 --load-cookies ${_cookies} --post-data=${_postdata} ${sitename}/admin/moduleinterface.php?${keyname}=${_sessionkey}\&mact=NMS,m1_,do_create_edit_job,0
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: [SOLVED] Automatic XML module export script
And the full code is...
thanks calguy1000 +++
regards
blast
P.S. pay attention at ^Location string because it's in english version only of wget
P.S.2 This example could be also used for automated (scheduled) backups from command line of our systems...
Code: Select all
#!/bin/bash
username="yourusernamehere"
password="yourpasswordhere"
sitename="http://yoursitenamehere.com"
_cookies="/tmp/cookie"
keyname="sp_"
# we want to get XML of AjaxMadeSimple but you can use what you want
module="AjaxMadeSimple"
# do the login
_postdata="username=${username}&password=${password}&loginsubmit=Submit"
wget -o log -O outfile.1 --save-cookies ${_cookies} --keep-session-cookies --post-data=$_postdata ${sitename}/admin/login.php
_x=`grep -c 'password incorrect' outfile.1`
if [ $_x -gt 0 ]; then
echo "FATAL: Authentication error";
cd $_owd
rm -rf $_tmpdir 2>/dev/null
exit 1
fi
# Get the session key
_line=`cat $_cookies | grep ${keyname}`
if [ ${line:-notset} != notset ]; then
_sessionkey=`cat $_cookies | grep ${keyname} | tr '\t' , | cut -d, -f7`
else
_sessionkey=`cat log | grep ^Location | cut -d= -f2 | cut -d" " -f1`
fi
wget -a log -O $module.xml --load-cookies ${_cookies} ${sitename}/admin/listmodules.php?${keyname}=${_sessionkey}\&action=exportxml\&module=$module
regards
blast
P.S. pay attention at ^Location string because it's in english version only of wget
P.S.2 This example could be also used for automated (scheduled) backups from command line of our systems...
Last edited by blast2007 on Sat Aug 08, 2009 11:44 pm, edited 1 time in total.