HEX
Server: Apache
System: Linux msm5694.mjhst.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: camjab_ssh (1000)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: //home/httpd/mech_ftp/baretube.com/admin/ftp_photos.php
<?php
require "db.php";

function dir_copy($srcdir, $dstdir, $offset = '', $verbose = false) {
    if (!isset($offset)) {
        $offset = 0;
    }
    $num = 0;
    $fail = 0;
    $sizetotal = 0;
    $fifail = '';
    if (!is_dir($dstdir)) {
        mkdir($dstdir);
    }
    if ($curdir = opendir($srcdir)) {
        while ($file = readdir($curdir)) {
            if ($file != '.' && $file != '..') {
                $srcfile = $srcdir . '/' . $file;
                $dstfile = $dstdir . '/' . $file;
                if (is_file($srcfile)) {
                    if (is_file($dstfile)) {
                        $ow = filemtime($srcfile) - filemtime($dstfile);
                    } else {
                        $ow = 1;
                    }
                    if ($ow > 0) {
                        if ($verbose) {
                            echo "Copying '$srcfile' to '$dstfile'...<br />";
                        }
                        if (copy($srcfile, $dstfile)) {
                            touch($dstfile, filemtime($srcfile));
                            $num++;
                            chmod($dstfile, 0777);
                            $sizetotal = ($sizetotal + filesize($dstfile));
                            if ($verbose) {
                                echo "OK\n";
                            }
                        } else {
                            echo "Error: File '$srcfile' could not be copied!<br />\n";
                            $fail++;
                            $fifail = $fifail . $srcfile . '|';
                        }
                    }
                } else if (is_dir($srcfile)) {
                    $res = explode(',', $ret);
                    $ret = dir_copy($srcfile, $dstfile, $verbose);
                    $mod = explode(',', $ret);
                    $imp = array($res[0] + $mod[0], $mod[1] + $res[1], $mod[2] + $res[2], $mod[3] . $res[3]);
                    $ret = implode(',', $imp);
                }
            }
        }
        closedir($curdir);
    }
    $red = explode(',', $ret);
    $ret = ($num + $red[0]) . ',' . (($fail - $offset) + $red[1]) . ',' . ($sizetotal + $red[2]) . ',' . $fifail . $red[3];
    return $ret;
}

$ftp_path = $basepath . '/ftp_photos';
$content_path = $gallery_path;

if (isset($_POST['formSubmit'])) {

    if (!isset($_POST['paysite']) || !is_numeric($_POST['paysite'])) {
        setMessage('Please select paysite', 'error');
    }

    if (!getMessages(false, 'error')) {
        $counter = 0;
        $directories = scandir($ftp_path);

        $getUser = dbRow("SELECT `record_num` FROM `users` WHERE `username` = '" . mysqli_real_escape_string($dbconn, $_POST['submitter']) . "'", false);
        $_POST['submitter'] = is_array($getUser) ? $getUser['record_num'] : 0;

        foreach ($directories as $dir) {
            if ($dir != '.' && $dir != '..' && is_dir("$ftp_path/$dir")) {
                $new_directory = uniqid();
                $files_array = array();
                mkdir("$content_path/$new_directory");
                chmod("$content_path/$new_directory", 0777);
                dir_copy("$ftp_path/$dir", "$content_path/$new_directory");
                $files = scandir("$content_path/$new_directory");
                foreach ($files as $f) {
                    if ($f != '.' && $f != '..') {
                        $files_array[] = $f;
                    }
                }
                mkdir("$content_path/$new_directory/thumbs");
                chmod("$content_path/$new_directory/thumbs", 0777);
                shuffle($files_array);

                $insert_id = dbInsert('content', array(
                    'title' => $dir,
                    'filename' => $new_directory,
                    'submitter' => (int) $_POST['submitter'],
                    'paysite' => (int) $_POST['paysite'],
                    'approved' => 0,
                    'photos' => 1,
                    'date_added' => 'NOW()',
                ));
                if (is_numeric($insert_id)) {
                    if (count($_POST['niche']) > 0) {
                        foreach ($_POST['niche'] as $niche_id) {
                            dbQuery("INSERT INTO `content_niches` (`content`, `niche`) VALUES ('$insert_id', '$niche_id')");
                        }
                    }
                    if (count($_POST['pornstar']) > 0) {
                        foreach ($_POST['pornstar'] as $pornstar_id) {
                            dbQuery("INSERT INTO `content_pornstars` (`content`, `pornstar`) VALUES ('$insert_id', '$pornstar_id')");
                        }
                    }
                    $images_array = array();
                    foreach ($files_array as $file) {
                        $images_array[] = dbInsert('images', array(
                            'title' => '',
                            'filename' => $file,
                            'gallery' => $insert_id,
                        ));
                    }
                    dbUpdate('content', array(
                        'thumbnail' => $images_array[0],
                        'record_num' => $insert_id,
                    ));

                    if (strlen($dir) > 0 && is_dir("$ftp_path/$dir")) {
                        shell_exec("rm -rf \"$ftp_path/$dir\"");
                    }
                    $counter++;
                }
            }
        }
        setMessage("<strong>$counter galleries added to import queue. <a href=\"$basehttp/admin/queue.php\">Click here to proceed to the approval queue</a></strong>", 'info');
        header("Location: $_SERVER[REQUEST_URI]");
        exit();
    }
}

$directories_count = max(0, count(scandir($ftp_path)) - 2);

entities_walk($_POST);
?>

<? require "header.php"; ?>

<div class="content-page">

    <div class="header-area">
        <div class="breadcrumbs">  
            <a href="index.php">Admin Home</a>          
            <span><a href="ftp_photos.php">FTP Import (Photos)</a></span>  
        </div>
    </div>

    <div class="content-outer">  

        <h2>FTP<strong>Import (Photos)</strong></h2>

        <div class="notification info">This script will add all the content from "<i><b><? echo $ftp_path; ?></b></i>" to the approval queue. You will still need to add titles, descriptions, etc to each piece of content.</div>

        <div class="notification info"><strong>***YOU NEED TO CHMOD ALL FILES IN THIS DIRECTORY TO 777 FOR THIS TO WORK, OTHERWISE PHP WILL NOT HAVE THE NESSESARY PERMISSIONS!***</strong></div>
        
        <? if ($directories_count > 0) { ?>
            <? echo setMessage("You have <b>$directories_count directories</b> with photos ready to import", 'info', true); ?>
        <? } ?>

        <div class="content-inner">

            <? echo getMessages(); ?>

            <form method="POST" action="" class="form" novalidate autocomplete="off">
                <table class="pagetable">
                    <tbody>
                        <tr>
                            <td>Uploader:</td>
                            <td>
                                <input type="text" name="submitter" id="contentAutocomplete" value="<? echo $_POST['submitter']; ?>" placeholder="Start typing username..." />
                                <script type="text/javascript">
                                    $(document).ready(function () {
                                        $("#contentAutocomplete").autocomplete({
                                            source: "search_content.php?type=2",
                                            minLength: 2
                                        });
                                    });
                                </script>
                            </td>
                        </tr>
                        <tr>
                            <td>Paysite:</td>
                            <td>
                                <select name="paysite" required>
                                    <?php $rresult = dbQuery("SELECT * FROM `paysites` ORDER BY `name`", false); ?>
                                    <? foreach ($rresult as $rrow) { ?>
                                        <option<?php echo ($_POST['paysite'] == $rrow['record_num']) ? ' selected' : ''; ?> value="<?php echo $rrow['record_num']; ?>"><?php echo $rrow['name']; ?></option>
                                    <?php } ?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>Categories:</td>
                            <td>
                                <select name="niche[]" multiple="multiple">
                                    <?php $results = dbQuery("SELECT `record_num`, `name` FROM `niches` ORDER BY `name`", false); ?>
                                    <?php foreach ($results as $_row) { ?>
                                        <option value="<?php echo $_row['record_num']; ?>"<? echo in_array($_row['record_num'], (array) $_POST['niche']) ? ' selected' : ''; ?>><?php echo $_row['name']; ?></option>
                                    <?php } ?>
                                </select>
                                <p class="hint">(Hold CTRL to make multiple selections)</p>
                            </td>
                        </tr>
                        <tr>
                            <td>Models:</td>
                            <td>
                                <select name="pornstar[]" multiple="multiple">
                                    <?php $results = dbQuery("SELECT `record_num`, `name` FROM `pornstars` ORDER BY `name`", false); ?>
                                    <?php foreach ($results as $_row) { ?>
                                        <option value="<?php echo $_row['record_num']; ?>"<? echo in_array($_row['record_num'], (array) $_POST['pornstar']) ? ' selected' : ''; ?>><?php echo $_row['name']; ?></option>
                                    <?php } ?>
                                </select>
                                <p class="hint">(Hold CTRL to make multiple selections)</p>
                            </td>
                        </tr>
                        <tr class="item submit">
                            <td colspan="2">
                                <input type="hidden" name="formSubmit" value="1">
                                <button type="submit" class="btn action-save">Import</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
    </div>

</div>

<?php require "footer.php"; ?>