Файл: adultscript-2.0.3-pro/files/admin/modules/module/components/add.php
Строк: 82
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_module_add
{
public function __construct()
{
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
$loaded = FALSE;
$message = '';
$credentials = array(
'hostname' => 'localhost',
'port' => 21,
'username' => '',
'password' => '',
'basepath' => '',
'method' => 'ftp'
);
$methods = array(
'ftp' => 'FTP',
'ftp-ssl' => 'FTP (SSL)',
);
$module = '';
// if (function_exists('ssh2_sftp')) {
// $methods['ssh'] = 'SSH2';
// }
if (isset($_POST['upload'])) {
if (!$file = VUpload::process('file', 20, array('zip'))) {
$errors = array_merge($errors, VUpload::error());
}
if (!$errors) {
$package = VF::factory('package');
$name = $_FILES['file']['name'];
if (!$package->valid($name)) {
$errors[] = $package->get_error();
}
if (!$errors) {
$tmp_path = TMP_DIR.'/uploads/'.$name;
if (!move_uploaded_file($_FILES['file']['tmp_name'], $tmp_path)) {
$errors[] = 'Failed to move uploaded file! Aborting...';
}
}
if (!$errors) {
if ($package->extract($tmp_path)) {
$package_name = VFile::strip_ext($name);
if ($package->load($package_name)) {
$module = VFile::strip_ext($name);
$loaded = TRUE;
} else {
$errors[] = $package->get_error();
}
} else {
$errors[] = $package->get_error();
}
}
}
}
if (isset($_POST['install'])) {
$filter = VF::factory('filter');
$module = $filter->get('module');
$hostname = $filter->get('hostname');
$port = (int) trim($_POST['port']);
$username = $filter->get('username');
$password = trim($_POST['password']);
$basepath = $filter->get('basepath');
$method = $filter->get('method');
if ($hostname == '') {
$errors[] = 'Hostname field cannot be left blank!';
} else {
$credentials['hostname'] = $hostname;
}
if ($port === 0 OR !is_numeric($port)) {
$errors[] = 'Porn field cannot be left blank!';
} else {
$credentials['port'] = $port;
}
if ($username == '') {
$errors[] = 'Username field cannot be left blank!';
} else {
$credentials['username'] = $username;
}
if ($basepath != '') {
if (strpos($basepath, '..') !== FALSE) {
$errors[] = 'Invalid characters in the base path!';
} else {
$credentials['basepath'] = $basepath;
}
}
if (!$errors) {
$package = VF::factory('package');
if (!$package->valid($module)) {
$errors[] = $package->get_error();
}
if (!$errors) {
if (!$package->load($module)) {
$errors[] = $package->get_error();
}
}
if (!$errors) {
$options = array(
'driver' => $method,
'host' => $hostname,
'port' => $port,
'ssl' => ($method == 'ftp-ssl') ? TRUE : FALSE,
'username' => $username,
'password' => $password,
'basedir' => $basepath
);
if ($package->install($module, $options)) {
$messages[] = 'Module installed!';
$message = $package->get_message();
} else {
$errors[] = $package->get_error();
}
// we need to rebuild the module cache now
VF::cache_del('modules', 'config');
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'extend';
$tpl->meta_title = 'Admin::Module::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->warnings = $warnings;
$tpl->methods = $methods;
$tpl->credentials = $credentials;
$tpl->loaded = $loaded;
$tpl->message = $message;
$tpl->package = (isset($package_name)) ? $package_name : NULL;
$tpl->module = $module;
$tpl->load(array('header', 'module_add', 'footer'));
$tpl->display();
}
}