• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [SOLVED] Automatic XML module export script
PostPosted: Mon Jun 29, 2009 4:38 pm 
Offline
Forum Members
Forum Members

Joined: Sat Aug 02, 2008 7:41 pm
Posts: 22
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.


Last edited by ikulis on Sat Aug 08, 2009 9:58 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 9:58 pm 
Offline
Forum Members
Forum Members

Joined: Sat Aug 02, 2008 7:41 pm
Posts: 22
I have created the PHP script for automatic XML module generation. Hope somebody will find is useful.
Writes the XML data to standard output.


Code:
<?
// @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;
}

?>


Top
 Profile  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 10:01 pm 
Did you ever hit the XML button in "Extensions->Modules" ?


Top
  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 10:02 pm 
Offline
Forum Members
Forum Members

Joined: Sat Aug 02, 2008 7:41 pm
Posts: 22
NaN wrote:

Did you ever hit the XML button in "Extensions->Modules" ?


Read the first post ...


Top
 Profile  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 10:06 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 6576
Location: Fernie British Columbia, Canada
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.

_________________
Follow me on twitter
--
if you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
----------------
Don't make me angry..... you won't like me when I'm angry....


Top
 Profile  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 10:39 pm 
Offline
Forum Members
Forum Members

Joined: Sat Aug 02, 2008 7:41 pm
Posts: 22
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.


Top
 Profile  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 10:53 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 6576
Location: Fernie British Columbia, Canada
An excerpt from my BASH script:

Code:
# 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
--
if you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
----------------
Don't make me angry..... you won't like me when I'm angry....


Top
 Profile  
 
 Post subject: Re: [SOLVED] Automatic XML module export script
PostPosted: Sat Aug 08, 2009 11:41 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Wed Aug 01, 2007 5:36 pm
Posts: 485
And the full code is...
Code:
#!/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


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...


Last edited by blast2007 on Sat Aug 08, 2009 11:44 pm, edited 1 time in total.

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting