|
From: <be...@us...> - 2013-07-23 14:04:53
|
Revision: 11850
http://sourceforge.net/p/xoops/svn/11850
Author: beckmi
Date: 2013-07-23 14:04:50 +0000 (Tue, 23 Jul 2013)
Log Message:
-----------
Adding generic folder checker
Modified Paths:
--------------
XoopsModules/wfdownloads/trunk/wfdownloads/admin/index.php
XoopsModules/wfdownloads/trunk/wfdownloads/include/functions.php
XoopsModules/wfdownloads/trunk/wfdownloads/language/english/admin.php
Added Paths:
-----------
XoopsModules/wfdownloads/trunk/wfdownloads/include/folderchecker.php
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/admin/index.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/admin/index.php 2013-07-22 18:53:14 UTC (rev 11849)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/admin/index.php 2013-07-23 14:04:50 UTC (rev 11850)
@@ -21,6 +21,8 @@
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/include/cp_header.php';
include_once dirname(__FILE__) . '/admin_header.php';
+include_once dirname(dirname(__FILE__)) . '/include/folderchecker.php';
+
xoops_cp_header();
$indexAdmin = new ModuleAdmin();
@@ -119,11 +121,30 @@
);
}
-//---------------------
+//------ check directories ---------------
+$indexAdmin->addConfigBoxLine('');
+$redirectFile = $_SERVER['PHP_SELF'];
+
+$languageConstants = array(_AM_WFD_AVAILABLE,_AM_WFD_NOTAVAILABLE, _AM_WFD_CREATETHEDIR, _AM_WFD_NOTWRITABLE, _AM_WFD_SETMPERM, _AM_WFD_DIRCREATED,_AM_WFD_DIRNOTCREATED,_AM_WFD_PERMSET,_AM_WFD_PERMNOTSET);
+
+$path = $xoopsModuleConfig['uploaddir'] . '/';
+$indexAdmin->addConfigBoxLine(FoldersChecker::getDirectoryStatus($path,0777,$languageConstants,$redirectFile));
+
+$path = XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['screenshots'] . '/';
+$indexAdmin->addConfigBoxLine(FoldersChecker::getDirectoryStatus($path,0777,$languageConstants,$redirectFile));
+
+$path = XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['catimage'] . '/';
+$indexAdmin->addConfigBoxLine(FoldersChecker::getDirectoryStatus($path,0777,$languageConstants,$redirectFile));
+
+
+$path = XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['mainimagedir'] . '/';
+$indexAdmin->addConfigBoxLine(FoldersChecker::getDirectoryStatus($path,0777,$languageConstants,$redirectFile));
+
+//---------------------------
+
echo $indexAdmin->addNavigation('index.php');
echo $indexAdmin->renderIndex();
echo wfd_serverstats();
-//xoops_cp_footer();
include_once "admin_footer.php";
Added: XoopsModules/wfdownloads/trunk/wfdownloads/include/folderchecker.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/include/folderchecker.php (rev 0)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/include/folderchecker.php 2013-07-23 14:04:50 UTC (rev 11850)
@@ -0,0 +1,120 @@
+
+<?php
+/*
+ You may not change or alter any portion of this comment or credits
+ of supporting developers from this source code or any supporting source code
+ which is considered copyrighted (c) material of the original comment or credit authors.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+/**
+ * WF-Downloads module
+ *
+ * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/
+ * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
+ * @package wfdownload
+ * @since 3.23
+ * @author Xoops Development Team
+ * @version svn:$id$
+ */
+
+//defined("XOOPS_ROOT_PATH") or die("XOOPS root path not defined");
+
+require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/include/cp_header.php';
+
+/**
+ * Class FoldersChecker
+ * check status of a folder
+ */
+class FoldersChecker
+{
+ /**
+ * @param $path
+ * @param int $mode
+ * @param array $languageConstants
+ * @param $redirectFile
+ *
+ * @return bool|string
+ */
+ public static function getDirectoryStatus($path, $mode = 0777,$languageConstants=array(), $redirectFile)
+ {
+ global $pathIcon16;
+
+ $languageConstants1 = array($languageConstants[5],$languageConstants[6]);
+ $languageConstants2 = array($languageConstants[7],$languageConstants[8]);
+
+ $myWords1 = urlencode(json_encode($languageConstants1));
+ $myWords2 = urlencode(json_encode($languageConstants2));
+
+ if (empty($path)) {
+ return false;
+ }
+ if (!@is_dir($path)) {
+ $path_status = "<img src='" . $pathIcon16 . "/0.png' >" . $path . ' ( ' . $languageConstants[1] . ' ) ' . "<a href=".$_SERVER['PHP_SELF']."?op=createdir&path=$path&redirect=$redirectFile&languageConstants=$myWords1>" . $languageConstants[2] . '</a>';
+ } elseif (@is_writable($path)) {
+ $path_status = "<img src='" . $pathIcon16 . "/1.png' >" . $path . ' ( ' . $languageConstants[0] . ' ) ';
+ $currentMode = (substr(decoct(fileperms($path)), 2));
+ if ($currentMode != decoct($mode)) {$path_status = "<img src='" . $pathIcon16 . "/0.png' >" . $path . sprintf($languageConstants[3],decoct($mode),$currentMode) . "<a href=".$_SERVER['PHP_SELF']."?op=setperm&mode=$mode&path=$path&redirect=$redirectFile&languageConstants=$myWords2> " . $languageConstants[4] . '</a>';
+ }
+ } else {
+ $currentMode = (substr(decoct(fileperms($path)), 2));
+ $path_status = "<img src='" . $pathIcon16 . "/0.png' >" . $path . sprintf($languageConstants[3],decoct($mode),$currentMode) . "<a href=".$_SERVER['PHP_SELF']."?op=setperm&mode=$mode&path=$path&redirect=$redirectFile&languageConstants=$myWords2> " . $languageConstants[4] . '</a>';
+ }
+ return $path_status;
+ }
+
+ /**
+ * @param $target
+ * @param int $mode
+ *
+ * @return bool
+ */
+ public static function createDirectory($target, $mode=0777)
+ {
+ $target = str_replace("..", "", $target);
+ // http://www.php.net/manual/en/function.mkdir.php
+ return is_dir($target) or ( self::createDirectory(dirname($target), $mode) and mkdir($target, $mode) );
+ }
+
+ /**
+ * @param $target
+ * @param int $mode
+ *
+ * @return bool
+ */
+ public static function setDirectoryPermissions($target, $mode = 0777)
+ {
+ $target = str_replace("..", "", $target);
+ return @chmod($target, (int) $mode);
+ }
+}
+
+$op = (isset($_GET['op']))? $_GET['op'] : "";
+
+switch ($op) {
+case "createdir":
+ $languageConstants=array();
+ if (isset($_GET['path'])) $path = $_GET['path'];
+ if (isset($_GET['redirect'])) $redirect = $_GET['redirect'];
+ if (isset($_GET['languageConstants'])) $languageConstants = json_decode($_GET['languageConstants']);
+ $result = FoldersChecker::createDirectory($path);
+ $msg = ($result)?$languageConstants[0]:$languageConstants[1];
+ redirect_header($redirect, 2, $msg . ': ' . $path);
+ exit();
+ break;
+
+case "setperm":
+ $languageConstants=array();
+ if (isset($_GET['path'])) $path = $_GET['path'];
+ if (isset($_GET['mode'])) $mode = $_GET['mode'];
+ if (isset($_GET['redirect'])) $redirect = $_GET['redirect'];
+ if (isset($_GET['languageConstants'])) $languageConstants = json_decode($_GET['languageConstants']);
+ $result = FoldersChecker::setDirectoryPermissions($path, $mode);
+ $msg = ($result)?$languageConstants[0]:$languageConstants[1];
+ redirect_header($redirect, 2, $msg . ': ' . $path);
+ exit();
+ break;
+
+}
Property changes on: XoopsModules/wfdownloads/trunk/wfdownloads/include/folderchecker.php
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev URL
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/include/functions.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/include/functions.php 2013-07-22 18:53:14 UTC (rev 11849)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/include/functions.php 2013-07-23 14:04:50 UTC (rev 11850)
@@ -23,7 +23,6 @@
}
-
/**
* Recursively sort categories by level and weight
*
@@ -452,68 +451,6 @@
return $modfooter;
}
-
-
-/**
-* Thanks to the NewBB2 Development Team
-*/
-function &wfdownloads_admin_getPathStatus($item, $getStatus=false)
-{
- if ($item == 'root') {
- $path = '';
- } else {
- $path = $item;
- }
-
- $thePath = wfdownloads_getUploadDir(true, $path);
-
- if(empty($thePath)) return false;
- if(@is_writable($thePath)) {
- $pathCheckResult = 1;
- $path_status = _AM_WFD_AVAILABLE;
- } elseif(!@is_dir($thePath)) {
- $pathCheckResult = -1;
- $path_status = _AM_WFD_NOTAVAILABLE . " <a href=main.php?op=createdir&path=$item>" . _AM_WFD_CREATETHEDIR . '</a>';
- } else {
- $pathCheckResult = -2;
- $path_status = _AM_WFD_NOTWRITABLE . " <a href=main.php?op=setperm&path=$item>" . _AM_SCS_SETMPERM . '</a>';
- }
- if (!$getStatus) {
- return $path_status;
- } else {
- return $pathCheckResult;
- }
-}
-
-
-
-/**
-* Thanks to the NewBB2 Development Team
-*/
-function wfdownloads_admin_mkdir($target)
-{
- // http://www.php.net/manual/en/function.mkdir.php
- // saint at corenova.com
- // bart at cdasites dot com
- if (is_dir($target)||empty($target)) return true; // best case check first
- if (file_exists($target) && !is_dir($target)) return false;
- if (wfdownloads_admin_mkdir(substr($target,0,strrpos($target,'/'))))
- if (!file_exists($target)) return mkdir($target); // crawl back up & create dir tree
- return true;
-}
-
-
-
-/**
-* Thanks to the NewBB2 Development Team
-*/
-function wfdownloads_admin_chmod($target, $mode = 0777)
-{
- return @chmod($target, $mode);
-}
-
-
-
function wfdownloads_getUploadDir($local=true, $item=false)
{
if ($item) {
@@ -547,7 +484,6 @@
}
-
function wfdownloads_formatErrors($errors=array())
{
$ret = '';
@@ -722,31 +658,7 @@
$html.= "<ul>\n";
$html.= "<li>" . _AM_WFD_DOWN_SERVERPATH . " <b>" . XOOPS_ROOT_PATH . "</b>\n";
- //
- if (empty($xoopsModuleConfig['uploaddir'])) {
- $html.= "<li>" . _AM_WFD_DOWN_UPLOADPATH . " <b><span style=\"color: red;\">" . _AM_WFD_DOWN_NOTSET . "</span></b>\n";
- } else {
- $html.= "<li>" . _AM_WFD_DOWN_UPLOADPATH . " <b>" . $xoopsModuleConfig['uploaddir'] . "</b>\n";
- }
- //
- if (empty($xoopsModuleConfig['screenshots'])) {
- $html.= "<li>" . _MI_WFD_SCREENSHOTS . " <b><span style=\"color: red;\">" . _AM_WFD_DOWN_NOTSET . "</span></b>\n";
- } else {
- $html.= "<li>" . _MI_WFD_SCREENSHOTS . " <b>" . XOOPS_ROOT_PATH . DS . $xoopsModuleConfig['screenshots'] . "</b>\n";
- }
- //
- if (empty($xoopsModuleConfig['catimage'])) {
- $html.= "<li>" . _MI_WFD_CATEGORYIMG . " <b><span style=\"color: red;\">" . _AM_WFD_DOWN_NOTSET . "</span></b>\n";
- } else {
- $html.= "<li>" . _MI_WFD_CATEGORYIMG . " <b>" . XOOPS_ROOT_PATH . DS . $xoopsModuleConfig['catimage'] . "</b>\n";
- }
- //
- if (empty($xoopsModuleConfig['mainimagedir'])) {
- $html.= "<li>" . _MI_WFD_MAINIMGDIR . " <b><span style=\"color: red;\">" . _AM_WFD_DOWN_NOTSET . "</span></b>\n";
- } else {
- $html.= "<li>" . _MI_WFD_MAINIMGDIR . " <b>" . XOOPS_ROOT_PATH . DS . $xoopsModuleConfig['mainimagedir'] . "</b>\n";
- }
- //
+
$html.= "</ul>\n";
$html.= "<br />\n";
$html.= _AM_WFD_DOWN_UPLOADPATHDSC . "\n";
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/language/english/admin.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/language/english/admin.php 2013-07-22 18:53:14 UTC (rev 11849)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/language/english/admin.php 2013-07-23 14:04:50 UTC (rev 11850)
@@ -618,3 +618,15 @@
define("_AM_WFD_MIME_EXTF_DESC","");
define("_AM_WFD_MIME_NAMEF_DESC","Enter application associated with this extension.");
define("_AM_WFD_MIME_TYPEF_DESC","Enter each mimetype associated with the file extension. Each Mimetype must be separated with a space.");
+
+//directories
+define('_AM_WFD_AVAILABLE',"<span style='color : green;'>Available. </span>");
+define('_AM_WFD_NOTAVAILABLE',"<span style='color : red;'>is not available. </span>");
+define('_AM_WFD_NOTWRITABLE',"<span style='color : red;'>".' should have permission ( %1$d ), but it has ( %2$d )'. '</span>');
+define('_AM_WFD_CREATETHEDIR','Create it');
+define('_AM_WFD_SETMPERM','Set the permission');
+
+define('_AM_WFD_DIRCREATED','The directory has been created');
+define('_AM_WFD_DIRNOTCREATED','The directory can not be created');
+define('_AM_WFD_PERMSET','The permission has been set');
+define('_AM_WFD_PERMNOTSET','The permission can not be set');
|