Shell File Manager
<?php
function find($type, $table, $value='*', $where_clause, $execute)
{
global $db;
if($where_clause)
{
$sql = "SELECT ".$value." FROM ".$table." ".$where_clause."";
}
else
{
$sql = "SELECT ".$value." FROM ".$table;
}
//echo $sql;
$prepare_sql = $db->prepare($sql);
foreach($execute As $key=>$value)
{
$execute[$key] = stripslashes($value);
}
$prepare_sql->execute($execute);
if($prepare_sql->errorCode() == 0)
{
if($type == 'first')
{
//fetch single record from database
$result = $prepare_sql->fetch();
}
else if($type == 'all')
{
//fetch multiple record from database
$result = $prepare_sql->fetchAll();
}
return $result;
}
else
{
$errors = $prepare_sql->errorInfo();
echo '<pre>';
print_r($errors[2]);
echo '</pre>';
die();
}
}
function save($table, $fields, $values, $execute)
{
global $db;
$result = false;
$sql = "INSERT INTO ".$table." (".$fields.") VALUES (".$values.")";
$prepare_sql = $db->prepare($sql);
foreach($execute As $key=>$value){
$execute[$key] = stripslashes($value);
}
$prepare_sql->execute($execute);
$result = $db->lastInsertId();
return $result;
}
function update($table, $set_value, $where_clause, $execute)
{
global $db;
$sql = "UPDATE ".$table." SET ".$set_value." ".$where_clause."";
$prepare_sql = $db->prepare($sql);
foreach($execute As $key=>$value){
$execute[$key] = stripslashes($value);
}
//exit;
$prepare_sql->execute($execute);
return true;
}
function delete($table, $where_clause, $execute)
{
global $db;
$sql = "DELETE FROM ".$table." ".$where_clause."";
$prepare_sql = $db->prepare($sql);
$prepare_sql->execute($execute);
if($prepare_sql->errorCode() == 0)
{
return true;
}
else
{
$errors = $prepare_sql->errorInfo();
echo '<pre>';
print_r($errors[2]);
echo '</pre>';
die();
}
}
function logout($destinationPath)
{
if(count($_SESSION))
{
foreach($_SESSION AS $key=>$value)
{
session_unset($_SESSION[$key]);
}
session_destroy();
}
header("location:".$destinationPath);
}
function validation_check($checkingVariable, $destinationPath)
{
if($checkingVariable =='')
{
header("location:".$destinationPath);
}
}
function Send_HTML_Mail($mail_To, $mail_From, $mail_CC, $mail_subject, $mail_Body)
{
$mail_Headers = "MIME-Version: 1.0\r\n";
$mail_Headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mail_Headers .= "From: ${mail_From}\r\n";
if($mail_CC != '')
{
$mail_Headers .= "Cc: ${mail_CC}\r\n";
}
if(mail($mail_To, $mail_subject, $mail_Body, $mail_Headers))
{
return true;
}
else
{
return false;
}
}
function Send_SMTP_Mail($mail_To, $mail_From, $mail_CC, $mail_subject, $mail_Body)
{
$mail_Headers = "MIME-Version: 1.0\r\n";
$mail_Headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mail_Headers .= "From: ${mail_From}\r\n";
if($mail_CC != '')
{
$mail_Headers .= "Cc: ${mail_CC}\r\n";
}
if(mail($mail_To, $mail_subject, $mail_Body, $mail_Headers))
{
return true;
}
else
{
return false;
}
}
function Send_SMTP_Mail_With_Attachment($mail_To, $mail_From, $mail_CC, $mail_subject, $mail_Body, $attachmentVal)
{
$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mail.phpcodeguru.com"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "phpcodeguru"; // SMTP password
//It should be same as that of the SMTP user
$mail->PluginDir = "/home/earthen5/public_html/phpcodeguru/include/";
$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = $mail_From;
$emailArr = explode(',',$mail_To);
foreach($emailArr AS $emailVal) {
$mail->AddAddress($emailVal, ""); //Email address where you wish to receive/collect those emails.
}
if($attachmentVal!='')
{
$path = $attachmentVal;
$name = basename($attachmentVal);
$mail->AddAttachment($path, $name, $encoding = "base64", $type = "application/octet-stream");
}
$mail->WordWrap = 100; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $mail_subject;
$message = $mail_Body;
$mail->Body = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
}
function create_password($length=10)
{
$phrase = "";
$chars = array (
"1","2","3","4","5","6","7","8","9","0",
"a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
"k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
"u","U","v","V","w","W","x","X","y","Y","z","Z"
);
$count = count ($chars) - 1;
srand ((double) microtime() * 1234567);
for ($i = 0; $i < $length; $i++)
$phrase .= $chars[rand (0, $count)];
return $phrase;
}
function get_visitor_location_details($id_address)
{
$url = "http://api.ipinfodb.com/v3/ip-city/?key=".API_KEY_IPINFODB."&ip=".$id_address."&format=json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 0 );
$response = curl_exec( $ch );
curl_close($ch);
$ip_details = json_decode($response);
if($ip_details->statusCode == 'OK')
{
return $ip_details;
}else
{
return false;
}
}
function generateFormToken($form)
{
// generate a token from an unique value
$token = md5(uniqid(microtime(), true));
// Write the generated token to the session variable to check it against the hidden field when the form is sent
$_SESSION[$form.'_token'] = $token;
return $token;
}
function verifyFormToken($form)
{
// check if a session is started and a token is transmitted, if not return an error
if(!isset($_SESSION[$form.'_token']))
{
return false;
}
// check if the form is sent with token in it
if(!isset($_POST['token']))
{
return false;
}
// compare the tokens against each other if they are still the same
if ($_SESSION[$form.'_token'] !== $_POST['token'])
{
return false;
}
return true;
}
function stripcleantohtml($s)
{
return htmlentities(trim(strip_tags(stripslashes($s))), ENT_NOQUOTES, "UTF-8");
}
function cleantohtml($s)
{
return strip_tags(htmlentities(trim(stripslashes($s))), ENT_NOQUOTES);
}
function file_download($download_path)
{
$path = $download_path;
$file = $path;
$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
$download_size = filesize($file);
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "csv": $ctype="application/csv"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "docx": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: $ctype");
header('Content-Transfer-Encoding: Binary');
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Content-Disposition: attachment; filename="'.$filename.'";');
readfile($file);
}
function read_all_files($root = '.')
{
$files = array();
$directories = array();
$last_letter = $root[strlen($root)-1];
$root = ($last_letter == '\\' || $last_letter == '/') ? $root : $root.DIRECTORY_SEPARATOR;
$directories[] = $root;
while (sizeof($directories))
{
$dir = array_pop($directories);
if ($handle = opendir($dir))
{
while (false !== ($file = readdir($handle)))
{
if ($file == '.' || $file == '..')
{
continue;
}
$file = $dir.$file;
if (is_dir($file))
{
$directory_path = $file.DIRECTORY_SEPARATOR;
array_push($directories, $directory_path);
$files[] = $directory_path;
}
elseif (is_file($file))
{
$files[] = $file;
}
}
closedir($handle);
}
}
return $files;
}
/*
function xcopy()
* Copy files and directories from source to destination
* @param source: Path of the source directory / files.
* @param dest: Path of the destination directory / files.
* @param permissions: access permission of copied directory.
* @returns array of entire directory structure.
*/
function xcopy($source, $dest, $permissions = 0777)
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest, $permissions);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
xcopy("$source/$entry", "$dest/$entry", $permissions);
}
// Clean up
$dir->close();
return true;
}
/*
function scan_dir()
* Scan directory provided in $path and provide the lsits of files availabel within that directory
* @param $path: Path of the source directory / files.
* @returns array of total_files, file_size and file_names.
*/
function scan_dir($path){
$ite=new RecursiveDirectoryIterator($path);
$bytestotal=0;
$nbfiles=0;
$files = array();
foreach (new RecursiveIteratorIterator($ite) as $filename=>$cur) {
if($filename == '.' || $filename == '..' || is_dir($filename))
{
//DO NOTHING
}
else
{
$filesize=$cur->getSize();
$bytestotal+=$filesize;
$nbfiles++;
$files[] = $filename;
}
}
$bytestotal=number_format($bytestotal);
return array('total_files'=>$nbfiles,'total_size'=>$bytestotal,'files'=>$files);
}
/*
function weeks_in_month()
* This function used to get the number of weeks in a month for a specific year and month
* @param $year: current year
* @param $month: current month
* @start_day_of_week: set it to 1
* @returns count number of weeks.
*/
function weeks_in_month($year, $month, $start_day_of_week)
{
// Total number of days in the given month.
$num_of_days = date("t", mktime(0,0,0,$month,1,$year));
// Count the number of times it hits $start_day_of_week.
$num_of_weeks = 0;
for($i=1; $i<=$num_of_days; $i++)
{
$day_of_week = date('w', mktime(0,0,0,$month,$i,$year));
if($day_of_week==$start_day_of_week)
$num_of_weeks++;
}
return $num_of_weeks;
}
/*
function createDateRangeArray($strDateFrom, $strDateTo)
* This function used to get the entire date range for a specified start date and end date
* @param $strDateFrom: Start date from
* @param $strDateTo: End date to
* @returns count lists of days in an array format.
*/
function createDateRangeArray($strDateFrom, $strDateTo)
{
$aryRange=array();
$iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2), substr($strDateFrom,8,2),substr($strDateFrom,0,4));
$iDateTo=mktime(1,0,0,substr($strDateTo,5,2), substr($strDateTo,8,2),substr($strDateTo,0,4));
if ($iDateTo>=$iDateFrom)
{
array_push($aryRange,date('Y-m-d-D',$iDateFrom)); // first entry
while ($iDateFrom<$iDateTo)
{
$iDateFrom+=86400; // add 24 hours
array_push($aryRange,date('Y-m-d-D',$iDateFrom));
}
}
return $aryRange;
}
function is_dir_empty($dir)
{
if (!is_readable($dir)) return NULL;
return (count(scandir($dir)) == 2);
}
?>
Shell File Manager Version 1.1, Coded By Shell
Email: [email protected]