HEX
Server: LiteSpeed
System: Linux w5304130.sdnsbox.com 4.18.0-425.3.1.lve.el8.x86_64 #1 SMP Tue Nov 22 22:59:23 EST 2022 x86_64
User: makefitmeserver (1001)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //var/softaculous/apps/git/gitdeploy.php
<?php

//////////////////////////////////////////////////////////////
//===========================================================
// WEBUZO CONTROL PANEL
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Mamta Malvi
// Date:       10th Jan 2009
// Time:       21:00 hrs
// Site:       https://webuzo.com/ (WEBUZO)
// ----------------------------------------------------------
// Please Read the Terms of Use at https://webuzo.com/terms
// ----------------------------------------------------------
//===========================================================
// (c) Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

@define('SOFTACULOUS', 1);

error_reporting(0);

$globals['path'] = '/usr/local/webuzo/';
// include_once($globals['path'].'universal.php'); // permission denied error
include_once($globals['path'].'globals.php');
include_once($globals['path'].'includes/functions.php');
include_once($globals['path'].'includes/functions/file_functions.php');

function git_log($path, $str){
	file_put_contents($path, $str."\n", FILE_APPEND);
}

// print_r($argv);
// exec('whoami', $output, $res); print_r($output);
// print_r($_ENV);

$user = $_ENV['USER'];
$home_dir = $_ENV['HOME'];
$git_dir = substr($_ENV['PWD'], 0, -5);

$log_path = $home_dir.'/.webuzo/log';

if (!file_exists($log_path)) {
    mkdir($log_path, 0700, true);
}

$deploy_time = time();

$log_file = $log_path.'/git_deploy_'.$deploy_time.'.log';

echo $deploy_msg = "
-------------------------------- \n
Running Deployment \n
-------------------------------- \n
Deployment Time: ".$deploy_time." \n
Deployment Log Path: ".$log_file." \n
Repository Root:".$git_dir." \n";

git_log($log_file, $deploy_msg);

if(empty($argv[1])){

    echo $invalid = "Opps, Invalid Action. \n
Stopping Deployment! \n";
   
    git_log($log_file, $invalid);

    die();

}

// Check if json file exists in directory for deployment
$output = wexo('cd '.$git_dir.'; test -e .deploy.json 2>&1', $res);
if(empty($res)){
    
    /**
     * 
     * $cpbin - copy binary path
     * $cmd - user mentioned files to deploy
     * $DEPLOYPATH - path where file is to be deployed
     * 
    */

    $deploy_info['deploy_time'] = $deploy_time;
	$deploy_info['latest_SHA'] = $latest_SHA;

    writedata($git_dir.'/.git/deploy_info', $deploy_info);

    $stop_deploy_msg = "\nStatus : Quiting Deployment";

    exec('which cp', $cpath, $res); 
   
    $cpbin = $cpath[0];

    $deploy_json = loaddata($git_dir.'/.deploy.json');

    if(empty($deploy_json)){

        echo $invalid_json = "Invalid Data Found In JSON File. \n".$stop_deploy_msg."\n";

        git_log($log_file, $invalid_json);

        die();

    }

    $DEPLOYPATH = $deploy_json['DEPLOYPATH'];
    // $DEPLOYPATH = '/home/mmm/public_html';

    // Check if user has used proper deployment path
	$valid_path = 0;
	if(strpos($DEPLOYPATH, $home_dir) !== false){
		$valid_path = 1;

		if(!file_exists($DEPLOYPATH)){
			mkdir($DEPLOYPATH, 0777, true);
		}
	}

	if(empty($valid_path)){

		echo $dep_path_nf = "Invalid Deployment Path!. \n".$stop_deploy_msg."\n";

        git_log($log_file, $dep_path_nf);

        die();

	}

    $quit = 0;

    foreach($deploy_json['task'] as $index => $cmd){
        
        $out = wexo('cd '.$git_dir.'; '.$cpbin.' -R '.$cmd.' '.$DEPLOYPATH.' 2>&1', $res);

        if(!empty($res)){

            echo $error = $out."\n".$stop_deploy_msg."\n";

            git_log($log_file, $error);

            $quit = 1;

            break;

        }

        echo $succsess_msg = "Successfully deployed ".$cmd." file.\n";

        git_log($log_file,  $succsess_msg);

    }

    if(empty($quit)){
        
        $latest_SHA = wexo('cd '.$git_dir.'/.git; git rev-parse HEAD', $return);
		
		$deploy_info['latest_SHA'] = $latest_SHA;
		
		writedata($git_dir.'/.git/deploy_info', $deploy_info);

        echo $deploy_done = "Status : Deployment Done Successfully. \n";

        git_log($log_file,  $deploy_done);

    }

}

exit(0);