All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jwall.apache.httpd.service.SshApacheConfigService Maven / Gradle / Ivy

The newest version!
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *   Copyright (C) 2010-2014 Christian Bockermann 
 *    
 *   This file is part of the jwall.org apache-config library. The apache-config library is
 *   a parsing library to handle Apache HTTPD configuration files.
 *
 *   More information and documentation for the jwall-tools can be found at
 *   
 *                      http://www.jwall.org/apache-config
 *   
 *   This program is free software; you can redistribute it and/or modify it under
 *   the terms of the GNU General Public License as published by the Free Software
 *   Foundation; either version 3 of the License, or (at your option) any later version.
 *   
 *   This program is distributed in the hope that it will be useful, but WITHOUT ANY
 *   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 *   FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 *   You should have received a copy of the GNU General Public License along with this 
 *   program; if not, see .
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package org.jwall.apache.httpd.service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.jwall.apache.httpd.config.ApacheConfig;
import org.jwall.apache.httpd.config.ConfigParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SshApacheConfigService implements ApacheConfigService {

	static Logger log = LoggerFactory.getLogger( SshApacheConfigService.class );
	SshFileSystem fs;
	
	public SshApacheConfigService( String host, String user, String pass ) throws Exception {
		fs = new SshFileSystem( host, user, pass );
	}
	
	
	
	public ApacheConfig getConfig(String filename) throws Exception {
		ConfigParser p = new ConfigParser( new File( filename ), fs );
		return p.parseConfig();
	}
	

	public boolean putConfig(ApacheConfig config) throws Exception {
		log.info( "Put config... " );
		
		List configs = new ArrayList();
		configs.add( config );
		
		for( ApacheConfig cfg : configs ){
			File out = new File( "/tmp" + cfg.getFile().getAbsolutePath() );
			log.info( "putting {} to {} ", cfg.getFile(), out );
			fs.put( out, cfg.toPlainTxt().getBytes() );
		}
		return false;
	}

	
	public boolean putConfigAll(ApacheConfig config) throws Exception {
		log.info( "Put config... " );
		
		List configs = new ArrayList();
		configs.add( config );
		configs.addAll( config.getSubTrees() );
		
		for( ApacheConfig cfg : configs ){
			File out = new File( "/tmp" + cfg.getFile().getAbsolutePath() );
			log.info( "putting {} to {} ", cfg.getFile(), out );
			fs.put( out, cfg.toPlainTxt().getBytes() );
		}
		return false;
	}
	
	
	public static void main( String[] args ) throws Exception {

		SshApacheConfigService cfg = new SshApacheConfigService( "shuttle.fritz.box", "chris", "p3m4mbit" );
		ApacheConfig c = cfg.getConfig( "/etc/apache2/apache2.conf" );
		log.info( "Config: {}", c.getFile() );
		log.info( "Subtrees: {}", c.getFiles() );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy