ok

Mini Shell

Direktori : /proc/thread-self/root/usr/local/sitepad/lib/panels/interworx/plugin/Plugin/
Upload File :
Current File : //proc/thread-self/root/usr/local/sitepad/lib/panels/interworx/plugin/Plugin/Sitepad.php

<?php
/**
 * InterWorx Hosting Control Panel
 *
 * <pre>
 * +----------------------------------------------------------------------+
 * | Copyright (c) 2000-2010 InterWorx L.L.C., All Rights Reserved.       |
 * +----------------------------------------------------------------------+
 * | Redistribution and use in source form, with or without modification  |
 * | is NOT permitted without consent from the copyright holder.          |
 * |                                                                      |
 * | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND |
 * | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,    |
 * | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A          |
 * | PARTICULAR PURPOSE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,    |
 * | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,  |
 * | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   |
 * | PROFITS; OF BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY  |
 * | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT         |
 * | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    |
 * | USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH     |
 * | DAMAGE.                                                              |
 * +----------------------------------------------------------------------+
 * </pre>
 *
 * @package InterWorx
 * @author  Paul Oehler <poehler@interworx.com>
 * @date    Sep 22, 2009
 */

/**
 * R1soft integration plugin.
 *
 * @package    InterWorx
 * @subpackage Plugin
 */
class Plugin_Sitepad extends Plugin {

	/**
	* Plugin init.
	*/
	protected function _init() {

		if( !is_dir( '/usr/local/sitepad' ) ) {
			$err = 'Can not find /usr/local/sitepad. Install SitePad first';
			$this->_disable( $err );
			return;
		}

		if( !is_link( '/usr/local/interworx/html/sitepad' ) ) {
			symlink( '/usr/local/sitepad/www',
				   '/usr/local/interworx/html/sitepad' );
		}

		//chmod( '/usr/local/interworx/plugins/sitepad', 0711 );

	}

  /**
   * Get category.
   *
   * @return string
   */
  public function getCategory() {
    return Plugin_Category::SCRIPT_INSTALLERS;
  }

  /**
   * Get priority.
   *
   * @return integer
   */
  public function getPriority() {
    return 40;
  }

  /**
   * Launches the installer script into the background.
   */
  public function runInstaller() {
    $installer = "{$this->getPluginDir()}/lib/install.sh";
    if( IWorxFileSys::fileExists( $installer ) ) {
      IWorxFileSys::rm( $installer );
    }

    $cmd = "wget -O {$installer} http://files.sitepad.com/install.sh";
    IWorxExec::exec( $cmd, $res, $ret, IWorxExec::NO_OUTPUT );
    IWorxFileSys::chmod( 0755, $installer );

    $cmd  = Ini::get( Ini::IWORX_BIN, 'runasuser' );
    $cmd .= " root custom {$installer} " .
      "> {$this->getPluginDir()}/install.log 2>&1";
    IWorxExec::exec( $cmd,
                     $result,
                     $retval,
                     IWorxExec::IN_BACKGROUND |
                     IWorxExec::ALLOW_REDIR_OUT |
                     IWorxExec::ALLOW_AMPERSAND );
    sleep( 10 );
  }

  /**
   * Executes the end user interface.
   */
  public function runEnduser() {
    putenv( 'IWORX_SESSION_ID=' . session_id() );
    session_write_close();

    $uniqname = IW::SW()->getUniqname();

    $cmd  = Ini::get( Ini::IWORX_BIN, 'runasuser' );
    $cmd .= " {$uniqname} custom /usr/local/sitepad/enduser.php 2>&1";

    putenv( 'QUERY_STRING=' . http_build_query( $_GET ) );
    putenv( 'REQUEST_METHOD=' . $_SERVER['REQUEST_METHOD'] );

    putenv( 'REMOTE_ADDR=' . $_SERVER['REMOTE_ADDR'] );
    putenv( 'HTTPS=' . $_SERVER['HTTPS'] );
    putenv( 'HTTP_HOST=' . $_SERVER['HTTP_HOST'] );
    putenv( 'HTTP_USER_AGENT=' . $_SERVER['HTTP_USER_AGENT'] );

    if( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
      putenv( 'CONTENT_LENGTH=' . $_SERVER['CONTENT_LENGTH'] );
      putenv( 'POST=' . http_build_query( $_POST ) );
      putenv( 'HTTP_RAW_POST_DATA=' . http_build_query( $_POST ) );
    }

    $this->_passthruWithHeaders( $cmd );
    exit;
  }

  /**
   * Executes the admin interface.
   */
  public function runAdmin() {
    putenv( 'IWORX_SESSION_ID=' . session_id() );
    session_write_close();

    $cmd = Ini::get( Ini::IWORX_BIN, 'runasuser' );

    $user = 'root';
    $cmd .= " {$user} custom /usr/local/sitepad/admin.php 2>&1";

    putenv( 'QUERY_STRING=' . http_build_query( $_GET ) );
    putenv( 'REQUEST_METHOD=' . $_SERVER['REQUEST_METHOD'] );

    putenv( 'REMOTE_ADDR=' . $_SERVER['REMOTE_ADDR'] );
    putenv( 'HTTPS=' . $_SERVER['HTTPS'] );
    putenv( 'HTTP_HOST=' . $_SERVER['HTTP_HOST'] );
    putenv( 'HTTP_USER_AGENT=' . $_SERVER['HTTP_USER_AGENT'] );

    if( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
      putenv( 'CONTENT_LENGTH=' . $_SERVER['CONTENT_LENGTH'] );
      putenv( 'POST=' . http_build_query( $_POST ) );
      putenv( 'HTTP_RAW_POST_DATA=' . http_build_query( $_POST ) );
    }

    $this->_passthruWithHeaders( $cmd );
  }

  /**
   * Do the equivalent to a "passthru" call, except treat the first lines as headers.
   *
   * @param string $cmd
   */
  private function _passthruWithHeaders( $cmd ) {
    $descriptorspec = array( 0 => array( 'pipe', 'r' ),   // stdin
                             1 => array( 'pipe', 'w' ),   // stdout
                             2 => array( 'pipe', 'w' ) ); // stderr

    $process = proc_open( $cmd, $descriptorspec, $pipes );
    fclose( $pipes[0] );
    if( is_resource( $process ) ) {
      while( $s = fgets( $pipes[1] ) ) {
        header( $s );
        if( $s == "\n" || $s == "\r\n") {
          break;
        }
      }
      while( $s = fgets( $pipes[1] ) ) {
        echo $s;
      }
    }
  }

  /**
   * Customizations to siteworx menu can be done here.
   *
   * @param IWorxMenuManager $MenuMan
   */
  public function updateSiteworxMenu( IWorxMenuManager $MenuMan ) {
    $new_data = array( 'text'   => 'SitePad Website Builder',
                       'url'    => '/siteworx/sitepad',
                       'parent' => 'iw-menu-features',
                       'class'  => 'iw-i-plugin' );
    $MenuMan->addMenuItemAfter( 'iw-menu-features-ssl', 'sitepad', $new_data );
    // also updateMenuItem( $id, $data )
    //      removeMenuItem( $id )
  }

  /**
   * Customizations to siteworx menu can be done here.
   *
   * @param IWorxMenuManager $MenuMan
   */
  public function updateNodeworxMenu( IWorxMenuManager $MenuMan ) {
    $new_data = array( 'text'   => 'SitePad Website Builder',
                       'url'    => '/nodeworx/sitepad',
                       'parent' => 'iw-menu-sw',
                       'class'  => 'iw-i-plugin' );
    $MenuMan->addMenuItemAfter( 'iw-menu-sw-import', 'sitepad', $new_data );
    // also updateMenuItem( $id, $data )
    //      removeMenuItem( $id )
  }  
}

Zerion Mini Shell 1.0