diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..2fa97d6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,27 @@
+# EditorConfig is awesome: http://EditorConfig.org
+# top-most EditorConfig file
+root = true
+
+# Unix-style newlines with a newline ending every file
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = true
+
+# Matches multiple files with brace expansion notation
+# Set default charset
+[*.{js,php}]
+charset = utf-8
+indent_style = space
+indent_size = 4
+
+# 4 space indentation
+[*.min.js]
+indent_style = space
+indent_size = 0
+
+
+# Matches the exact files either package.json or .travis.yml
+[{composer.json,.travis.yml,build.xml}]
+indent_style = space
+indent_size = 2
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index c040d47..8e98e71 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,17 +1,52 @@
-language: php
+language: php
php:
- 5.3
- 5.4
- 5.5
- 5.6
+ - 7.0
env:
- - RUN=vendor/bin/phing
+ global:
+ # PHP Code Sniffer special rules
+ - R_CLASS="Squiz.Classes.ValidClassName" # must use CamleClasName
+ - R_CONST="Generic.NamingConventions.UpperCaseConstantName" # const must UPPERCASE
+ - R_FILE="PSR1.Files.SideEffects" # a file declare , or executes logic, not both
+ - R_LINE="Generic.Files.LineLength" #
+ - R_METHOD="PSR1.Methods.CamelCapsMethodName" # must use camleMethodName
+ - R_NS="PSR1.Classes.ClassDeclaration" # class must use Namespace
+ - CS_INGNORE="" # ingore Files
+ matrix:
+ #strict mode to check formatting
+ - STRICT=true
+ # exclude some special or unsupported conventions
+ - STRICT=false CS_INGNORE="dialog.php"
-script: ${RUN}
+#allow failures
+matrix:
+ allow_failures:
+ - env: STRICT=true
-before_script:
- - composer selfupdate
- - composer --version
+#install dependence
+install:
- composer install --prefer-dist --verbose
+
+#init the env to exclude
+before_script:
+ # STRICT mode only exclude Namespace and LineLength
+ - if [[ "$STRICT" == "true" ]];then
+ export CS_EXCLUDE="$R_LINE,$R_NS";
+ else
+ export CS_EXCLUDE="$R_CLASS,$R_CONST,$R_FILE,$R_LINE,$R_METHOD,$R_NS";
+ fi
+ - echo $CS_EXCLUDE
+
+# check formatting and Syntax
+script:
+ - ./vendor/bin/phpcs components
+ --standard=PSR2
+ --exclude="$CS_EXCLUDE"
+ --ignore="$CS_INGNORE"
+ --colors
+ --extensions=php
diff --git a/components/active/class.active.php b/components/active/class.active.php
index d17b603..3df3873 100644
--- a/components/active/class.active.php
+++ b/components/active/class.active.php
@@ -8,7 +8,8 @@
require_once('../../common.php');
-class Active extends Common {
+class Active extends Common
+{
//////////////////////////////////////////////////////////////////
// PROPERTIES
@@ -29,7 +30,8 @@ class Active extends Common {
// Construct
//////////////////////////////////////////////////////////////////
- public function __construct(){
+ public function __construct()
+ {
$this->actives = getJSON('active.php');
}
@@ -37,48 +39,50 @@ class Active extends Common {
// List User's Active Files
//////////////////////////////////////////////////////////////////
- public function ListActive(){
+ public function ListActive()
+ {
$active_list = array();
- $tainted = FALSE;
+ $tainted = false;
$root = WORKSPACE;
- if($this->actives){
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username']) && $data['username']==$this->username){
- if($this->isAbsPath($data['path'])) {
- $root = "";
- } else {
- $root = $root.'/';
+ if ($this->actives) {
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username']) && $data['username']==$this->username) {
+ if ($this->isAbsPath($data['path'])) {
+ $root = "";
+ } else {
+ $root = $root.'/';
+ }
+ if (file_exists($root.$data['path'])) {
+ $focused = isset($data['focused']) ? $data['focused'] : false;
+ $active_list[] = array('path'=>$data['path'], 'focused'=>$focused);
+ } else {
+ unset($this->actives[$active]);
+ $tainted = true;
+ }
}
- if (file_exists($root.$data['path'])) {
- $focused = isset($data['focused']) ? $data['focused'] : false;
- $active_list[] = array('path'=>$data['path'], 'focused'=>$focused);
- } else {
- unset($this->actives[$active]);
- $tainted = TRUE;
- }
- }
}
}
- if ($tainted){
- saveJSON('active.php',$this->actives);
+ if ($tainted) {
+ saveJSON('active.php', $this->actives);
}
- echo formatJSEND("success",$active_list);
+ echo formatJSEND("success", $active_list);
}
//////////////////////////////////////////////////////////////////
// Check File
//////////////////////////////////////////////////////////////////
- public function Check(){
+ public function Check()
+ {
$cur_users = array();
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username']) && $data['username']!=$this->username && $data['path']==$this->path){
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username']) && $data['username']!=$this->username && $data['path']==$this->path) {
$cur_users[] = $data['username'];
}
}
- if(count($cur_users)!=0){
- echo formatJSEND("error","Warning: File ".substr($this->path,strrpos($this->path,"/")+1)." Currently Opened By: " . implode(", ",$cur_users));
- }else{
+ if (count($cur_users)!=0) {
+ echo formatJSEND("error", "Warning: File ".substr($this->path, strrpos($this->path, "/")+1)." Currently Opened By: " . implode(", ", $cur_users));
+ } else {
echo formatJSEND("success");
}
}
@@ -87,16 +91,17 @@ class Active extends Common {
// Add File
//////////////////////////////////////////////////////////////////
- public function Add(){
+ public function Add()
+ {
$process_add = true;
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username']) && $data['username']==$this->username && $data['path']==$this->path){
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username']) && $data['username']==$this->username && $data['path']==$this->path) {
$process_add = false;
}
}
- if($process_add){
+ if ($process_add) {
$this->actives[] = array("username"=>$this->username,"path"=>$this->path);
- saveJSON('active.php',$this->actives);
+ saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
}
@@ -105,14 +110,15 @@ class Active extends Common {
// Rename File
//////////////////////////////////////////////////////////////////
- public function Rename(){
+ public function Rename()
+ {
$revised_actives = array();
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username'])){
- $revised_actives[] = array("username"=>$data['username'],"path"=>str_replace($this->path,$this->new_path,$data['path']));
- }
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username'])) {
+ $revised_actives[] = array("username"=>$data['username'],"path"=>str_replace($this->path, $this->new_path, $data['path']));
+ }
}
- saveJSON('active.php',$revised_actives);
+ saveJSON('active.php', $revised_actives);
echo formatJSEND("success");
}
@@ -120,13 +126,14 @@ class Active extends Common {
// Remove File
//////////////////////////////////////////////////////////////////
- public function Remove(){
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username']) && $this->username==$data['username'] && $this->path==$data['path']){
+ public function Remove()
+ {
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username']) && $this->username==$data['username'] && $this->path==$data['path']) {
unset($this->actives[$active]);
}
}
- saveJSON('active.php',$this->actives);
+ saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
@@ -134,32 +141,33 @@ class Active extends Common {
// Remove All Files
//////////////////////////////////////////////////////////////////
- public function RemoveAll(){
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username']) && $this->username==$data['username']){
+ public function RemoveAll()
+ {
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username']) && $this->username==$data['username']) {
unset($this->actives[$active]);
}
}
- saveJSON('active.php',$this->actives);
+ saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
//////////////////////////////////////////////////////////////////
- // Mark File As Focused
+ // Mark File As Focused
// All other files will be marked as non-focused.
//////////////////////////////////////////////////////////////////
- public function MarkFileAsFocused(){
- foreach($this->actives as $active=>$data){
- if(is_array($data) && isset($data['username']) && $this->username==$data['username']){
+ public function MarkFileAsFocused()
+ {
+ foreach ($this->actives as $active => $data) {
+ if (is_array($data) && isset($data['username']) && $this->username==$data['username']) {
$this->actives[$active]['focused']=false;
- if($this->path==$data['path']){
+ if ($this->path==$data['path']) {
$this->actives[$active]['focused']=true;
}
}
}
- saveJSON('active.php',$this->actives);
+ saveJSON('active.php', $this->actives);
echo formatJSEND("success");
}
-
}
diff --git a/components/active/controller.php b/components/active/controller.php
index 8adcef5..39f97a3 100755
--- a/components/active/controller.php
+++ b/components/active/controller.php
@@ -21,69 +21,67 @@
// Get user's active files
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='list'){
- $Active->username = $_SESSION['user'];
- $Active->ListActive();
- }
+if ($_GET['action']=='list') {
+ $Active->username = $_SESSION['user'];
+ $Active->ListActive();
+}
//////////////////////////////////////////////////////////////////
// Add active record
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='add'){
- $Active->username = $_SESSION['user'];
- $Active->path = $_GET['path'];
- $Active->Add();
- }
+if ($_GET['action']=='add') {
+ $Active->username = $_SESSION['user'];
+ $Active->path = $_GET['path'];
+ $Active->Add();
+}
//////////////////////////////////////////////////////////////////
// Rename
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='rename'){
- $Active->username = $_SESSION['user'];
- $Active->path = $_GET['old_path'];
- $Active->new_path = $_GET['new_path'];
- $Active->Rename();
- }
+if ($_GET['action']=='rename') {
+ $Active->username = $_SESSION['user'];
+ $Active->path = $_GET['old_path'];
+ $Active->new_path = $_GET['new_path'];
+ $Active->Rename();
+}
//////////////////////////////////////////////////////////////////
// Check if file is active
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='check'){
- $Active->username = $_SESSION['user'];
- $Active->path = $_GET['path'];
- $Active->Check();
- }
+if ($_GET['action']=='check') {
+ $Active->username = $_SESSION['user'];
+ $Active->path = $_GET['path'];
+ $Active->Check();
+}
//////////////////////////////////////////////////////////////////
// Remove active record
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='remove'){
- $Active->username = $_SESSION['user'];
- $Active->path = $_GET['path'];
- $Active->Remove();
- }
+if ($_GET['action']=='remove') {
+ $Active->username = $_SESSION['user'];
+ $Active->path = $_GET['path'];
+ $Active->Remove();
+}
//////////////////////////////////////////////////////////////////
// Remove all active record
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='removeall'){
- $Active->username = $_SESSION['user'];
- $Active->RemoveAll();
- }
+if ($_GET['action']=='removeall') {
+ $Active->username = $_SESSION['user'];
+ $Active->RemoveAll();
+}
//////////////////////////////////////////////////////////////////
// Mark file as focused
//////////////////////////////////////////////////////////////////
- if($_GET['action']=='focused'){
- $Active->username = $_SESSION['user'];
- $Active->path = $_GET['path'];
- $Active->MarkFileAsFocused();
- }
-
-?>
\ No newline at end of file
+if ($_GET['action']=='focused') {
+ $Active->username = $_SESSION['user'];
+ $Active->path = $_GET['path'];
+ $Active->MarkFileAsFocused();
+}
diff --git a/components/fileext_textmode/class.fileextension_textmode.php b/components/fileext_textmode/class.fileextension_textmode.php
index 54faf2c..66093e6 100644
--- a/components/fileext_textmode/class.fileextension_textmode.php
+++ b/components/fileext_textmode/class.fileextension_textmode.php
@@ -10,337 +10,344 @@
require_once '../../common.php';
-class fileextension_textmode{
+class fileextension_textmode
+{
- //////////////////////////////////////////////////////////////////
- //default associations
- //////////////////////////////////////////////////////////////////
- private $defaultExtensions = array(
- 'html' => 'html',
- 'htm' => 'html',
- 'tpl' => 'html',
- 'js' => 'javascript',
- 'css' => 'css',
- 'scss' => 'scss',
- 'sass' => 'scss',
- 'less' => 'less',
- 'php' => 'php',
- 'php4' => 'php',
- 'php5' => 'php',
- 'phtml' => 'php',
- 'json' => 'json',
- 'java' => 'java',
- 'xml' => 'xml',
- 'sql' => 'sql',
- 'md' => 'markdown',
- 'c' => 'c_cpp',
- 'cpp' => 'c_cpp',
- 'd' => 'd',
- 'h' => 'c_cpp',
- 'hpp' => 'c_cpp',
- 'py' => 'python',
- 'rb' => 'ruby',
- 'erb' => 'html_ruby',
- 'jade' => 'jade',
- 'coffee' => 'coffee',
- 'vm' => 'velocity');
+ //////////////////////////////////////////////////////////////////
+ //default associations
+ //////////////////////////////////////////////////////////////////
+ private $defaultExtensions = array(
+ 'html' => 'html',
+ 'htm' => 'html',
+ 'tpl' => 'html',
+ 'js' => 'javascript',
+ 'css' => 'css',
+ 'scss' => 'scss',
+ 'sass' => 'scss',
+ 'less' => 'less',
+ 'php' => 'php',
+ 'php4' => 'php',
+ 'php5' => 'php',
+ 'phtml' => 'php',
+ 'json' => 'json',
+ 'java' => 'java',
+ 'xml' => 'xml',
+ 'sql' => 'sql',
+ 'md' => 'markdown',
+ 'c' => 'c_cpp',
+ 'cpp' => 'c_cpp',
+ 'd' => 'd',
+ 'h' => 'c_cpp',
+ 'hpp' => 'c_cpp',
+ 'py' => 'python',
+ 'rb' => 'ruby',
+ 'erb' => 'html_ruby',
+ 'jade' => 'jade',
+ 'coffee' => 'coffee',
+ 'vm' => 'velocity');
- //////////////////////////////////////////////////////////////////
- //availiable text modes
- //////////////////////////////////////////////////////////////////
- private $availiableTextModes = array(
- 'abap',
- 'abc',
- 'actionscript',
- 'ada',
- 'apache_conf',
- 'applescript',
- 'asciidoc',
- 'assembly_x86',
- 'autohotkey',
- 'batchfile',
- 'c9search',
- 'c_cpp',
- 'cirru',
- 'clojure',
- 'cobol',
- 'coffee',
- 'coldfusion',
- 'csharp',
- 'css',
- 'curly',
- 'd',
- 'dart',
- 'diff',
- 'django',
- 'dockerfile',
- 'dot',
- 'eiffel',
- 'ejs',
- 'elixir',
- 'elm',
- 'erlang',
- 'forth',
- 'ftl',
- 'gcode',
- 'gherkin',
- 'gitignore',
- 'glsl',
- 'gobstones',
- 'golang',
- 'groovy',
- 'haml',
- 'handlebars',
- 'haskell',
- 'haxe',
- 'html',
- 'html_elixir',
- 'html_ruby',
- 'ini',
- 'io',
- 'jack',
- 'jade',
- 'java',
- 'javascript',
- 'json',
- 'jsoniq',
- 'jsp',
- 'jsx',
- 'julia',
- 'latex',
- 'lean',
- 'less',
- 'liquid',
- 'lisp',
- 'livescript',
- 'logiql',
- 'lsl',
- 'lua',
- 'luapage',
- 'lucene',
- 'makefile',
- 'markdown',
- 'mask',
- 'matlab',
- 'maze',
- 'mel',
- 'mips_assembler',
- 'mushcode',
- 'mysql',
- 'nix',
- 'nsis',
- 'objectivec',
- 'ocaml',
- 'pascal',
- 'perl',
- 'pgsql',
- 'php',
- 'plain_text',
- 'powershell',
- 'praat',
- 'prolog',
- 'protobuf',
- 'python',
- 'r',
- 'razor',
- 'rdoc',
- 'rhtml',
- 'rst',
- 'ruby',
- 'rust',
- 'sass',
- 'scad',
- 'scala',
- 'scheme',
- 'scss',
- 'sh',
- 'sjs',
- 'smarty',
- 'snippets',
- 'soy_template',
- 'space',
- 'sql',
- 'sqlserver',
- 'stylus',
- 'svg',
- 'swift',
- 'swig',
- 'tcl',
- 'tex',
- 'text',
- 'textile',
- 'toml',
- 'twig',
- 'typescript',
- 'vala',
- 'vbscript',
- 'velocity',
- 'verilog',
- 'vhdl',
- 'wollok',
- 'xml',
- 'xquery',
- 'yaml'
- );
+ //////////////////////////////////////////////////////////////////
+ //availiable text modes
+ //////////////////////////////////////////////////////////////////
+ private $availiableTextModes = array(
+ 'abap',
+ 'abc',
+ 'actionscript',
+ 'ada',
+ 'apache_conf',
+ 'applescript',
+ 'asciidoc',
+ 'assembly_x86',
+ 'autohotkey',
+ 'batchfile',
+ 'c9search',
+ 'c_cpp',
+ 'cirru',
+ 'clojure',
+ 'cobol',
+ 'coffee',
+ 'coldfusion',
+ 'csharp',
+ 'css',
+ 'curly',
+ 'd',
+ 'dart',
+ 'diff',
+ 'django',
+ 'dockerfile',
+ 'dot',
+ 'eiffel',
+ 'ejs',
+ 'elixir',
+ 'elm',
+ 'erlang',
+ 'forth',
+ 'ftl',
+ 'gcode',
+ 'gherkin',
+ 'gitignore',
+ 'glsl',
+ 'gobstones',
+ 'golang',
+ 'groovy',
+ 'haml',
+ 'handlebars',
+ 'haskell',
+ 'haxe',
+ 'html',
+ 'html_elixir',
+ 'html_ruby',
+ 'ini',
+ 'io',
+ 'jack',
+ 'jade',
+ 'java',
+ 'javascript',
+ 'json',
+ 'jsoniq',
+ 'jsp',
+ 'jsx',
+ 'julia',
+ 'latex',
+ 'lean',
+ 'less',
+ 'liquid',
+ 'lisp',
+ 'livescript',
+ 'logiql',
+ 'lsl',
+ 'lua',
+ 'luapage',
+ 'lucene',
+ 'makefile',
+ 'markdown',
+ 'mask',
+ 'matlab',
+ 'maze',
+ 'mel',
+ 'mips_assembler',
+ 'mushcode',
+ 'mysql',
+ 'nix',
+ 'nsis',
+ 'objectivec',
+ 'ocaml',
+ 'pascal',
+ 'perl',
+ 'pgsql',
+ 'php',
+ 'plain_text',
+ 'powershell',
+ 'praat',
+ 'prolog',
+ 'protobuf',
+ 'python',
+ 'r',
+ 'razor',
+ 'rdoc',
+ 'rhtml',
+ 'rst',
+ 'ruby',
+ 'rust',
+ 'sass',
+ 'scad',
+ 'scala',
+ 'scheme',
+ 'scss',
+ 'sh',
+ 'sjs',
+ 'smarty',
+ 'snippets',
+ 'soy_template',
+ 'space',
+ 'sql',
+ 'sqlserver',
+ 'stylus',
+ 'svg',
+ 'swift',
+ 'swig',
+ 'tcl',
+ 'tex',
+ 'text',
+ 'textile',
+ 'toml',
+ 'twig',
+ 'typescript',
+ 'vala',
+ 'vbscript',
+ 'velocity',
+ 'verilog',
+ 'vhdl',
+ 'wollok',
+ 'xml',
+ 'xquery',
+ 'yaml'
+ );
- const storeFilename = 'extensions.php';
-
- //////////////////////////////////////////////////////////////////
- //check the session if the user is allowed to do anything here
- //////////////////////////////////////////////////////////////////
- public function __construct(){
- Common::checkSession();
- }
+ const storeFilename = 'extensions.php';
+
+ //////////////////////////////////////////////////////////////////
+ //check the session if the user is allowed to do anything here
+ //////////////////////////////////////////////////////////////////
+ public function __construct()
+ {
+ Common::checkSession();
+ }
- public function getAvailiableTextModes(){
- return $this->availiableTextModes;
- }
+ public function getAvailiableTextModes()
+ {
+ return $this->availiableTextModes;
+ }
- public function getDefaultExtensions(){
- return $this->defaultExtensions;
- }
+ public function getDefaultExtensions()
+ {
+ return $this->defaultExtensions;
+ }
- //////////////////////////////////////////////////////////////////
- //checks if the sended extensions are valid to prevent any injections
- //////////////////////////////////////////////////////////////////
- public function validateExtension($extension){
- return preg_match('#^[a-z0-9\_]+$#i', $extension);
- }
+ //////////////////////////////////////////////////////////////////
+ //checks if the sended extensions are valid to prevent any injections
+ //////////////////////////////////////////////////////////////////
+ public function validateExtension($extension)
+ {
+ return preg_match('#^[a-z0-9\_]+$#i', $extension);
+ }
- //////////////////////////////////////////////////////////////////
- //checks if the sended extensions are valid to prevent any injections and usage of removed text modes
- //////////////////////////////////////////////////////////////////
- public function validTextMode($mode){
- return in_array($mode, $this->availiableTextModes);
- }
+ //////////////////////////////////////////////////////////////////
+ //checks if the sended extensions are valid to prevent any injections and usage of removed text modes
+ //////////////////////////////////////////////////////////////////
+ public function validTextMode($mode)
+ {
+ return in_array($mode, $this->availiableTextModes);
+ }
- //////////////////////////////////////////////////////////////////
- //process the form with the associations
- //////////////////////////////////////////////////////////////////
- private function processFileExtTextModeForm(){
- if(!Common::checkAccess()){
- return array('status' =>'error', 'msg' =>'You are not allowed to edit the file extensions.');
- }
- //Store Fileextensions and Textmodes in File:
- if(!isset($_POST['extension']) || !is_array($_POST['extension'])
- || !isset($_POST['textMode']) || !is_array($_POST['textMode'])){
- return json_encode(array('status' => 'error', 'msg' => 'incorrect data send'));
- }
+ //////////////////////////////////////////////////////////////////
+ //process the form with the associations
+ //////////////////////////////////////////////////////////////////
+ private function processFileExtTextModeForm()
+ {
+ if (!Common::checkAccess()) {
+ return array('status' =>'error', 'msg' =>'You are not allowed to edit the file extensions.');
+ }
+ //Store Fileextensions and Textmodes in File:
+ if (!isset($_POST['extension']) || !is_array($_POST['extension'])
+ || !isset($_POST['textMode']) || !is_array($_POST['textMode'])) {
+ return json_encode(array('status' => 'error', 'msg' => 'incorrect data send'));
+ }
- $exMap = array();
+ $exMap = array();
- $warning = '';
+ $warning = '';
- //Iterate over the sended extensions
- foreach ($_POST['extension'] as $key => $extension){
- //ignore empty extensions, so that they are going to removed
- if(trim($extension) == '' ){
- continue;
- }
+ //Iterate over the sended extensions
+ foreach ($_POST['extension'] as $key => $extension) {
+ //ignore empty extensions, so that they are going to removed
+ if (trim($extension) == '') {
+ continue;
+ }
- //get the sended data and check it
- if(!isset($_POST["textMode"][$key])){
- return json_encode(array('status' => 'error', 'msg' => 'incorrect data send.'));
- }
+ //get the sended data and check it
+ if (!isset($_POST["textMode"][$key])) {
+ return json_encode(array('status' => 'error', 'msg' => 'incorrect data send.'));
+ }
- $extension = strtolower(trim($extension));
- $textMode = strtolower(trim($_POST["textMode"][$key]));
-
- if(!$this->validateExtension($extension)){
- return json_encode(array('status' => 'error', 'msg' => 'incorrect extension:'.htmlentities($extension)));
- }
+ $extension = strtolower(trim($extension));
+ $textMode = strtolower(trim($_POST["textMode"][$key]));
+
+ if (!$this->validateExtension($extension)) {
+ return json_encode(array('status' => 'error', 'msg' => 'incorrect extension:'.htmlentities($extension)));
+ }
- if(!$this->validTextMode($textMode)){
- return json_encode(array('status' => 'error', 'msg' => 'incorrect text mode:'.htmlentities($textMode)));
- }
+ if (!$this->validTextMode($textMode)) {
+ return json_encode(array('status' => 'error', 'msg' => 'incorrect text mode:'.htmlentities($textMode)));
+ }
- //data was correct and could be insert
- if(isset($exMap[$extension])){
- $warning = htmlentities($extension).' is already set.
';
- }else{
- $exMap[$extension] = $textMode;
- }
- }
+ //data was correct and could be insert
+ if (isset($exMap[$extension])) {
+ $warning = htmlentities($extension).' is already set.
';
+ } else {
+ $exMap[$extension] = $textMode;
+ }
+ }
- //store the associations
- Common::saveJSON(fileextension_textmode::storeFilename, $exMap);
- if($warning != ''){
- return json_encode(array('status' => 'warning', 'msg' => $warning, 'extensions' => $exMap ));
- }else{
- return json_encode(array('status' => 'success', 'msg' => 'File extensions are saved successfully.', 'extensions' => $exMap));
- }
+ //store the associations
+ Common::saveJSON(fileextension_textmode::storeFilename, $exMap);
+ if ($warning != '') {
+ return json_encode(array('status' => 'warning', 'msg' => $warning, 'extensions' => $exMap ));
+ } else {
+ return json_encode(array('status' => 'success', 'msg' => 'File extensions are saved successfully.', 'extensions' => $exMap));
+ }
+ }
- }
+ //////////////////////////////////////////////////////////////////
+ //process all the possible forms
+ //////////////////////////////////////////////////////////////////
+ public function processForms()
+ {
+ if (!isset($_GET['action'])) {
+ return json_encode(array('status' => 'error', 'msg' => 'incorrect data send.'));
+ }
- //////////////////////////////////////////////////////////////////
- //process all the possible forms
- //////////////////////////////////////////////////////////////////
- public function processForms(){
- if(!isset($_GET['action'])){
- return json_encode(array('status' => 'error', 'msg' => 'incorrect data send.'));
- }
+ switch ($_GET['action']) {
+ case 'FileExtTextModeForm':
+ return $this->processFileExtTextModeForm();
+ break;
+ case 'GetFileExtTextModes':
+ return $this->prcessGetFileExtTextModes();
+ break;
+ default:
+ return json_encode(array('status' => 'error', 'msg' => 'Incorrect data send'));
+ break;
+ }
+ }
- switch($_GET['action']){
- case 'FileExtTextModeForm':
- return $this->processFileExtTextModeForm();
- break;
- case 'GetFileExtTextModes':
- return $this->prcessGetFileExtTextModes();
- break;
- default:
- return json_encode(array('status' => 'error', 'msg' => 'Incorrect data send'));
- break;
- }
- }
+ //////////////////////////////////////////////////////////////////
+ //Send the default extensions
+ //////////////////////////////////////////////////////////////////
+ private function prcessGetFileExtTextModes()
+ {
+ $ext = false;
+ //ignore warnings
+ $ext = @Common::getJSON(fileextension_textmode::storeFilename);
- //////////////////////////////////////////////////////////////////
- //Send the default extensions
- //////////////////////////////////////////////////////////////////
- private function prcessGetFileExtTextModes(){
- $ext = false;
- //ignore warnings
- $ext = @Common::getJSON(fileextension_textmode::storeFilename);
-
- if(!is_array($ext)){
- //default extensions
- $ext = $this->defaultExtensions;
- }
-
- //the availiable extensions, which aren't removed
- $availEx = array();
- foreach($ext as $ex => $mode){
- if(in_array($mode, $this->availiableTextModes)){
- $availEx[$ex] = $mode;
- }
- }
- return json_encode(array('status' => 'success', 'extensions' => $availEx, 'textModes' => $this->availiableTextModes));
- }
-
- //////////////////////////////////////////////////////////////////
- //return a select-field with all availiable text modes, the one in the parameter is selected
- //////////////////////////////////////////////////////////////////
- public function getTextModeSelect($extension){
- $extension = trim(strtolower($extension));
- $find = false;
- $ret = ''."\n";
-
- return $ret;
- }
+ if (!is_array($ext)) {
+ //default extensions
+ $ext = $this->defaultExtensions;
+ }
+
+ //the availiable extensions, which aren't removed
+ $availEx = array();
+ foreach ($ext as $ex => $mode) {
+ if (in_array($mode, $this->availiableTextModes)) {
+ $availEx[$ex] = $mode;
+ }
+ }
+ return json_encode(array('status' => 'success', 'extensions' => $availEx, 'textModes' => $this->availiableTextModes));
+ }
+
+ //////////////////////////////////////////////////////////////////
+ //return a select-field with all availiable text modes, the one in the parameter is selected
+ //////////////////////////////////////////////////////////////////
+ public function getTextModeSelect($extension)
+ {
+ $extension = trim(strtolower($extension));
+ $find = false;
+ $ret = ''."\n";
+
+ return $ret;
+ }
}
-
-?>
diff --git a/components/fileext_textmode/controller.php b/components/fileext_textmode/controller.php
index 73d813d..6dcdd24 100644
--- a/components/fileext_textmode/controller.php
+++ b/components/fileext_textmode/controller.php
@@ -13,5 +13,3 @@ $fileExTM = new fileextension_textmode();
echo $fileExTM->processForms();
-
-?>
\ No newline at end of file
diff --git a/components/filemanager/class.dirzip.php b/components/filemanager/class.dirzip.php
index 3e5ea00..3727463 100644
--- a/components/filemanager/class.dirzip.php
+++ b/components/filemanager/class.dirzip.php
@@ -6,50 +6,50 @@
*/
class DirZip
{
- /**
- * Add files and sub-directories in a folder to zip file.
- * @param string $folder
- * @param ZipArchive $zipFile
- * @param int $exclusiveLength Number of text to be exclusived from the file path.
- */
- private static function folderToZip($folder, &$zipFile, $exclusiveLength) {
- $handle = opendir($folder);
- while ($f = readdir($handle)) {
- if ($f != '.' && $f != '..') {
- $filePath = "$folder/$f";
- // Remove prefix from file path before add to zip.
- $localPath = substr($filePath, $exclusiveLength);
- if (is_file($filePath)) {
- $zipFile->addFile($filePath, $localPath);
- } elseif (is_dir($filePath)) {
- // Add sub-directory.
- $zipFile->addEmptyDir($localPath);
- self::folderToZip($filePath, $zipFile, $exclusiveLength);
- }
- }
- }
- closedir($handle);
- }
+ /**
+ * Add files and sub-directories in a folder to zip file.
+ * @param string $folder
+ * @param ZipArchive $zipFile
+ * @param int $exclusiveLength Number of text to be exclusived from the file path.
+ */
+ private static function folderToZip($folder, &$zipFile, $exclusiveLength)
+ {
+ $handle = opendir($folder);
+ while ($f = readdir($handle)) {
+ if ($f != '.' && $f != '..') {
+ $filePath = "$folder/$f";
+ // Remove prefix from file path before add to zip.
+ $localPath = substr($filePath, $exclusiveLength);
+ if (is_file($filePath)) {
+ $zipFile->addFile($filePath, $localPath);
+ } elseif (is_dir($filePath)) {
+ // Add sub-directory.
+ $zipFile->addEmptyDir($localPath);
+ self::folderToZip($filePath, $zipFile, $exclusiveLength);
+ }
+ }
+ }
+ closedir($handle);
+ }
- /**
- * Zip a folder (include itself).
- * Usage:
- * DirZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
- *
- * @param string $sourcePath Path of directory to be zip.
- * @param string $outZipPath Path of output zip file.
- */
- public static function zipDir($sourcePath, $outZipPath)
- {
- $pathInfo = pathInfo($sourcePath);
- $parentPath = $pathInfo['dirname'];
- $dirName = $pathInfo['basename'];
+ /**
+ * Zip a folder (include itself).
+ * Usage:
+ * DirZip::zipDir('/path/to/sourceDir', '/path/to/out.zip');
+ *
+ * @param string $sourcePath Path of directory to be zip.
+ * @param string $outZipPath Path of output zip file.
+ */
+ public static function zipDir($sourcePath, $outZipPath)
+ {
+ $pathInfo = pathInfo($sourcePath);
+ $parentPath = $pathInfo['dirname'];
+ $dirName = $pathInfo['basename'];
- $z = new ZipArchive();
- $z->open($outZipPath, ZIPARCHIVE::CREATE);
- $z->addEmptyDir($dirName);
- self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
- $z->close();
- }
+ $z = new ZipArchive();
+ $z->open($outZipPath, ZIPARCHIVE::CREATE);
+ $z->addEmptyDir($dirName);
+ self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
+ $z->close();
+ }
}
-?>
\ No newline at end of file
diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php
index de29bf2..a04d779 100755
--- a/components/filemanager/class.filemanager.php
+++ b/components/filemanager/class.filemanager.php
@@ -9,7 +9,8 @@
require_once('../../lib/diff_match_patch.php');
require_once('../../common.php');
-class Filemanager extends Common {
+class Filemanager extends Common
+{
//////////////////////////////////////////////////////////////////
// PROPERTIES
@@ -48,42 +49,55 @@ class Filemanager extends Common {
// Construct
//////////////////////////////////////////////////////////////////
- public function __construct($get,$post,$files) {
- $this->rel_path = Filemanager::cleanPath( $get['path'] );
+ public function __construct($get, $post, $files)
+ {
+ $this->rel_path = Filemanager::cleanPath($get['path']);
- if($this->rel_path!="/"){ $this->rel_path .= "/"; }
- if(!empty($get['query'])){ $this->query = $get['query']; }
- if(!empty($get['options'])){ $this->foptions = $get['options']; }
+ if ($this->rel_path!="/") {
+ $this->rel_path .= "/";
+ }
+ if (!empty($get['query'])) {
+ $this->query = $get['query'];
+ }
+ if (!empty($get['options'])) {
+ $this->foptions = $get['options'];
+ }
$this->root = $get['root'];
- if($this->isAbsPath($get['path'])) {
- $this->path = Filemanager::cleanPath( $get['path'] );
+ if ($this->isAbsPath($get['path'])) {
+ $this->path = Filemanager::cleanPath($get['path']);
} else {
$this->root .= '/';
- $this->path = $this->root . Filemanager::cleanPath( $get['path'] );
+ $this->path = $this->root . Filemanager::cleanPath($get['path']);
}
// Search
- if(!empty($post['search_string'])){ $this->search_string = $post['search_string']; }
- if(!empty($post['search_file_type'])){
- $this->search_file_type = $post['search_file_type'];
+ if (!empty($post['search_string'])) {
+ $this->search_string = $post['search_string'];
+ }
+ if (!empty($post['search_file_type'])) {
+ $this->search_file_type = $post['search_file_type'];
}
// Create
- if(!empty($get['type'])){ $this->type = $get['type']; }
+ if (!empty($get['type'])) {
+ $this->type = $get['type'];
+ }
// Modify\Create
- if(!empty($get['new_name'])){ $this->new_name = $get['new_name']; }
+ if (!empty($get['new_name'])) {
+ $this->new_name = $get['new_name'];
+ }
- foreach(array('content', 'mtime', 'patch') as $key){
- if(!empty($post[$key])){
- if(get_magic_quotes_gpc()){
+ foreach (array('content', 'mtime', 'patch') as $key) {
+ if (!empty($post[$key])) {
+ if (get_magic_quotes_gpc()) {
$this->$key = stripslashes($post[$key]);
- }else{
+ } else {
$this->$key = $post[$key];
}
}
}
// Duplicate
- if(!empty($get['destination'])){
- $get['destination'] = Filemanager::cleanPath( $get['destination'] );
- if($this->isAbsPath($get['path'])) {
+ if (!empty($get['destination'])) {
+ $get['destination'] = Filemanager::cleanPath($get['destination']);
+ if ($this->isAbsPath($get['path'])) {
$this->destination = $get['destination'];
} else {
$this->destination = $this->root . $get['destination'];
@@ -95,15 +109,21 @@ class Filemanager extends Common {
// INDEX (Returns list of files and directories)
//////////////////////////////////////////////////////////////////
- public function index(){
+ public function index()
+ {
- if(file_exists($this->path)){
+ if (file_exists($this->path)) {
$index = array();
- if(is_dir($this->path) && $handle = opendir($this->path)){
+ if (is_dir($this->path) && $handle = opendir($this->path)) {
while (false !== ($object = readdir($handle))) {
if ($object != "." && $object != ".." && $object != $this->controller) {
- if(is_dir($this->path.'/'.$object)){ $type = "directory"; $size=count(glob($this->path.'/'.$object.'/*')); }
- else{ $type = "file"; $size=@filesize($this->path.'/'.$object); }
+ if (is_dir($this->path.'/'.$object)) {
+ $type = "directory";
+ $size=count(glob($this->path.'/'.$object.'/*'));
+ } else {
+ $type = "file";
+ $size=@filesize($this->path.'/'.$object);
+ }
$index[] = array(
"name"=>$this->rel_path . $object,
"type"=>$type,
@@ -114,29 +134,32 @@ class Filemanager extends Common {
$folders = array();
$files = array();
- foreach($index as $item=>$data){
- if($data['type']=='directory'){
+ foreach ($index as $item => $data) {
+ if ($data['type']=='directory') {
$folders[] = array("name"=>$data['name'],"type"=>$data['type'],"size"=>$data['size']);
}
- if($data['type']=='file'){
+ if ($data['type']=='file') {
$files[] = array("name"=>$data['name'],"type"=>$data['type'],"size"=>$data['size']);
}
}
- function sorter($a, $b, $key = 'name') { return strnatcmp($a[$key], $b[$key]); }
+ function sorter($a, $b, $key = 'name')
+ {
+ return strnatcmp($a[$key], $b[$key]);
+ }
- usort($folders,"sorter");
- usort($files,"sorter");
+ usort($folders, "sorter");
+ usort($files, "sorter");
- $output = array_merge($folders,$files);
+ $output = array_merge($folders, $files);
$this->status = "success";
$this->data = '"index":' . json_encode($output);
- }else{
+ } else {
$this->status = "error";
$this->message = "Not A Directory";
}
- }else{
+ } else {
$this->status = "error";
$this->message = "Path Does Not Exist";
}
@@ -144,21 +167,28 @@ class Filemanager extends Common {
$this->respond();
}
- public function find(){
- if(!function_exists('shell_exec')){
+ public function find()
+ {
+ if (!function_exists('shell_exec')) {
$this->status = "error";
$this->message = "Shell_exec() Command Not Enabled.";
} else {
chdir($this->path);
- $input = str_replace('"' , '', $this->query);
+ $input = str_replace('"', '', $this->query);
$vinput = preg_quote($input);
$cmd = 'find -L ';
if ($this->foptions && $this->foptions['strategy']) {
- switch($this->f_options['strategy']){
- case 'left_prefix': $cmd = "$cmd -iname \"$vinput*\""; break;
- case 'substring': $cmd = "$cmd -iname \"*$vinput*\""; break;
- case 'regexp': $cmd = "$cmd -regex \"$input\""; break;
- }
+ switch ($this->f_options['strategy']) {
+ case 'left_prefix':
+ $cmd = "$cmd -iname \"$vinput*\"";
+ break;
+ case 'substring':
+ $cmd = "$cmd -iname \"*$vinput*\"";
+ break;
+ case 'regexp':
+ $cmd = "$cmd -regex \"$input\"";
+ break;
+ }
} else {
$cmd = 'find -L -iname "' . $input . '*"';
}
@@ -170,21 +200,21 @@ class Filemanager extends Common {
error_reporting(0);
foreach ($file_arr as $i => $fentry) {
- $farr = explode(" ", $fentry);
- $fname = trim($farr[0]);
- if ($farr[1] == 'f') {
- $ftype = 'file';
- } else {
- $ftype = 'directory';
- }
- if (strlen($fname) != 0){
- $fname = $this->rel_path . substr($fname, 2);
- $f = array('path' => $fname, 'type' => $ftype );
- array_push( $output_arr, $f);
- }
+ $farr = explode(" ", $fentry);
+ $fname = trim($farr[0]);
+ if ($farr[1] == 'f') {
+ $ftype = 'file';
+ } else {
+ $ftype = 'directory';
+ }
+ if (strlen($fname) != 0) {
+ $fname = $this->rel_path . substr($fname, 2);
+ $f = array('path' => $fname, 'type' => $ftype );
+ array_push($output_arr, $f);
+ }
}
- if(count($output_arr)==0){
+ if (count($output_arr)==0) {
$this->status = "error";
$this->message = "No Results Returned";
} else {
@@ -193,41 +223,41 @@ class Filemanager extends Common {
}
}
$this->respond();
-
}
//////////////////////////////////////////////////////////////////
// SEARCH
//////////////////////////////////////////////////////////////////
- public function search(){
- if(!function_exists('shell_exec')){
+ public function search()
+ {
+ if (!function_exists('shell_exec')) {
$this->status = "error";
$this->message = "Shell_exec() Command Not Enabled.";
- }else{
- if($_GET['type'] == 1) {
+ } else {
+ if ($_GET['type'] == 1) {
$this->path = WORKSPACE;
}
- $input = str_replace('"' , '', $this->search_string);
+ $input = str_replace('"', '', $this->search_string);
$input = preg_quote($input);
$output = shell_exec('find -L ' . $this->path . ' -iregex ".*' . $this->search_file_type . '" -type f | xargs grep -i -I -n -R -H "' . $input . '"');
$output_arr = explode("\n", $output);
$return = array();
- foreach($output_arr as $line){
+ foreach ($output_arr as $line) {
$data = explode(":", $line);
$da = array();
- if(count($data) > 2){
+ if (count($data) > 2) {
$da['line'] = $data[1];
- $da['file'] = str_replace($this->path,'',$data[0]);
+ $da['file'] = str_replace($this->path, '', $data[0]);
$da['result'] = str_replace($this->root, '', $data[0]);
- $da['string'] = str_replace($data[0] . ":" . $data[1] . ':' , '', $line);
+ $da['string'] = str_replace($data[0] . ":" . $data[1] . ':', '', $line);
$return[] = $da;
}
}
- if(count($return)==0){
+ if (count($return)==0) {
$this->status = "error";
$this->message = "No Results Returned";
- }else{
+ } else {
$this->status = "success";
$this->data = '"index":' . json_encode($return);
}
@@ -239,25 +269,26 @@ class Filemanager extends Common {
// OPEN (Returns the contents of a file)
//////////////////////////////////////////////////////////////////
- public function open(){
- if(is_file($this->path)){
+ public function open()
+ {
+ if (is_file($this->path)) {
$output = file_get_contents($this->path);
- if(extension_loaded('mbstring')) {
- if(!mb_check_encoding($output, 'UTF-8')) {
- if(mb_check_encoding($output, 'ISO-8859-1')) {
- $output = utf8_encode($output);
- } else {
- $output = mb_convert_encoding($content, 'UTF-8');
- }
- }
+ if (extension_loaded('mbstring')) {
+ if (!mb_check_encoding($output, 'UTF-8')) {
+ if (mb_check_encoding($output, 'ISO-8859-1')) {
+ $output = utf8_encode($output);
+ } else {
+ $output = mb_convert_encoding($content, 'UTF-8');
+ }
+ }
}
$this->status = "success";
$this->data = '"content":' . json_encode($output);
$mtime = filemtime($this->path);
$this->data .= ', "mtime":'.$mtime;
- }else{
+ } else {
$this->status = "error";
$this->message = "Not A File :".$this->path;
}
@@ -269,12 +300,13 @@ class Filemanager extends Common {
// OPEN IN BROWSER (Return URL)
//////////////////////////////////////////////////////////////////
- public function openinbrowser(){
+ public function openinbrowser()
+ {
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$domainName = $_SERVER['HTTP_HOST'];
$url = $protocol.WSURL.'/'.$this->rel_path;
$this->status = "success";
- $this->data = '"url":' . json_encode(rtrim($url,"/"));
+ $this->data = '"url":' . json_encode(rtrim($url, "/"));
$this->respond();
}
@@ -282,33 +314,36 @@ class Filemanager extends Common {
// CREATE (Creates a new file or directory)
//////////////////////////////////////////////////////////////////
- public function create(){
+ public function create()
+ {
// Create file
- if($this->type=="file"){
- if(!file_exists($this->path)){
- if($file = fopen($this->path, 'w')){
+ if ($this->type=="file") {
+ if (!file_exists($this->path)) {
+ if ($file = fopen($this->path, 'w')) {
// Write content
- if($this->content){ fwrite($file, $this->content); }
+ if ($this->content) {
+ fwrite($file, $this->content);
+ }
$this->data = '"mtime":'.filemtime($this->path);
fclose($file);
$this->status = "success";
- }else{
+ } else {
$this->status = "error";
$this->message = "Cannot Create File";
}
- }else{
+ } else {
$this->status = "error";
$this->message = "File Already Exists";
}
}
// Create directory
- if($this->type=="directory"){
- if(!is_dir($this->path)){
+ if ($this->type=="directory") {
+ if (!is_dir($this->path)) {
mkdir($this->path);
$this->status = "success";
- }else{
+ } else {
$this->status = "error";
$this->message = "Directory Already Exists";
}
@@ -321,37 +356,39 @@ class Filemanager extends Common {
// DELETE (Deletes a file or directory (+contents))
//////////////////////////////////////////////////////////////////
- public function delete(){
+ public function delete()
+ {
- function rrmdir($path, $follow) {
- if(is_file($path)) {
- unlink($path);
- } else {
- $files = array_diff(scandir($path), array('.','..'));
- foreach ($files as $file) {
- if(is_link("$path/$file")) {
- if($follow) {
+ function rrmdir($path, $follow)
+ {
+ if (is_file($path)) {
+ unlink($path);
+ } else {
+ $files = array_diff(scandir($path), array('.','..'));
+ foreach ($files as $file) {
+ if (is_link("$path/$file")) {
+ if ($follow) {
rrmdir("$path/$file", $follow);
}
unlink("$path/$file");
- } else if(is_dir("$path/$file")) {
+ } elseif (is_dir("$path/$file")) {
rrmdir("$path/$file", $follow);
} else {
- unlink("$path/$file");
- }
- }
- return rmdir($path);
- }
- }
+ unlink("$path/$file");
+ }
+ }
+ return rmdir($path);
+ }
+ }
- if(file_exists($this->path)){
- if(isset($_GET['follow'])) {
+ if (file_exists($this->path)) {
+ if (isset($_GET['follow'])) {
rrmdir($this->path, true);
} else {
rrmdir($this->path, false);
}
$this->status = "success";
- }else{
+ } else {
$this->status = "error";
$this->message = "Path Does Not Exist ";
}
@@ -363,48 +400,49 @@ class Filemanager extends Common {
// MODIFY (Modifies a file name/contents or directory name)
//////////////////////////////////////////////////////////////////
- public function modify(){
+ public function modify()
+ {
// Change name
- if($this->new_name){
- $explode = explode('/',$this->path);
+ if ($this->new_name) {
+ $explode = explode('/', $this->path);
array_pop($explode);
- $new_path = implode("/",$explode) . "/" . $this->new_name;
- if(!file_exists($new_path)){
- if(rename($this->path,$new_path)){
+ $new_path = implode("/", $explode) . "/" . $this->new_name;
+ if (!file_exists($new_path)) {
+ if (rename($this->path, $new_path)) {
//unlink($this->path);
$this->status = "success";
- }else{
+ } else {
$this->status = "error";
$this->message = "Could Not Rename";
}
- }else{
+ } else {
$this->status = "error";
$this->message = "Path Already Exists";
}
} else {
// Change content
- if($this->content || $this->patch){
- if($this->content==' '){
+ if ($this->content || $this->patch) {
+ if ($this->content==' ') {
$this->content=''; // Blank out file
}
- if ($this->patch && ! $this->mtime){
+ if ($this->patch && ! $this->mtime) {
$this->status = "error";
$this->message = "mtime parameter not found";
$this->respond();
return;
}
- if(is_file($this->path)){
+ if (is_file($this->path)) {
$serverMTime = filemtime($this->path);
$fileContents = file_get_contents($this->path);
- if ($this->patch && $this->mtime != $serverMTime){
+ if ($this->patch && $this->mtime != $serverMTime) {
$this->status = "error";
$this->message = "Client is out of sync";
//DEBUG : file_put_contents($this->path.".conflict", "SERVER MTIME :".$serverMTime.", CLIENT MTIME :".$this->mtime);
$this->respond();
return;
- } else if (strlen(trim($this->patch)) == 0 && ! $this->content ){
+ } elseif (strlen(trim($this->patch)) == 0 && ! $this->content) {
// Do nothing if the patch is empty and there is no content
$this->status = "success";
$this->data = '"mtime":'.$serverMTime;
@@ -412,8 +450,8 @@ class Filemanager extends Common {
return;
}
- if($file = fopen($this->path, 'w')){
- if ($this->patch){
+ if ($file = fopen($this->path, 'w')) {
+ if ($this->patch) {
$dmp = new diff_match_patch();
$p = $dmp->patch_apply($dmp->patch_fromText($this->patch), $fileContents);
$this->content = $p[0];
@@ -421,7 +459,7 @@ class Filemanager extends Common {
//DEBUG : file_put_contents($this->path.".patch", $this->patch);
}
- if (fwrite($file, $this->content) === false){
+ if (fwrite($file, $this->content) === false) {
$this->status = "error";
$this->message = "could not write to file";
} else {
@@ -434,19 +472,19 @@ class Filemanager extends Common {
}
fclose($file);
- }else{
- $this->status = "error";
- $this->message = "Cannot Write to File";
+ } else {
+ $this->status = "error";
+ $this->message = "Cannot Write to File";
}
- }else{
+ } else {
$this->status = "error";
$this->message = "Not A File";
}
} else {
- $file = fopen($this->path, 'w');
- fclose($file);
- $this->data = '"mtime":'.filemtime($this->path);
- $this->status = "success";
+ $file = fopen($this->path, 'w');
+ fclose($file);
+ $this->data = '"mtime":'.filemtime($this->path);
+ $this->status = "success";
}
}
@@ -457,39 +495,40 @@ class Filemanager extends Common {
// DUPLICATE (Creates a duplicate of the object - (cut/copy/paste)
//////////////////////////////////////////////////////////////////
- public function duplicate(){
+ public function duplicate()
+ {
- if(!file_exists($this->path)){
+ if (!file_exists($this->path)) {
$this->status = "error";
$this->message = "Invalid Source";
}
- function recurse_copy($src,$dst) {
+ function recurse_copy($src, $dst)
+ {
$dir = opendir($src);
@mkdir($dst);
- while(false !== ( $file = readdir($dir)) ) {
+ while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($src . '/' . $file) ) {
- recurse_copy($src . '/' . $file,$dst . '/' . $file);
- }
- else {
- copy($src . '/' . $file,$dst . '/' . $file);
+ if (is_dir($src . '/' . $file)) {
+ recurse_copy($src . '/' . $file, $dst . '/' . $file);
+ } else {
+ copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
- if($this->status!="error"){
-
- if(is_file($this->path)){
- copy($this->path,$this->destination);
+ if ($this->status!="error") {
+ if (is_file($this->path)) {
+ copy($this->path, $this->destination);
$this->status = "success";
- }else{
- recurse_copy($this->path,$this->destination);
- if(!$this->response){ $this->status = "success"; }
+ } else {
+ recurse_copy($this->path, $this->destination);
+ if (!$this->response) {
+ $this->status = "success";
+ }
}
-
}
$this->respond();
@@ -499,21 +538,21 @@ class Filemanager extends Common {
// UPLOAD (Handles uploads to the specified directory)
//////////////////////////////////////////////////////////////////
- public function upload(){
+ public function upload()
+ {
// Check that the path is a directory
- if(is_file($this->path)){
+ if (is_file($this->path)) {
$this->status = "error";
$this->message = "Path Not A Directory";
- }else{
+ } else {
// Handle upload
$info = array();
- while(list($key,$value) = each($_FILES['upload']['name'])){
- if(!empty($value)){
+ while (list($key,$value) = each($_FILES['upload']['name'])) {
+ if (!empty($value)) {
$filename = $value;
$add = $this->path."/$filename";
- if(@move_uploaded_file($_FILES['upload']['tmp_name'][$key], $add)){
-
+ if (@move_uploaded_file($_FILES['upload']['tmp_name'][$key], $add)) {
$info[] = array(
"name"=>$value,
"size"=>filesize($add),
@@ -535,50 +574,48 @@ class Filemanager extends Common {
// RESPOND (Outputs data in JSON [JSEND] format)
//////////////////////////////////////////////////////////////////
- public function respond(){
+ public function respond()
+ {
// Success ///////////////////////////////////////////////
- if($this->status=="success"){
- if($this->data){
+ if ($this->status=="success") {
+ if ($this->data) {
$json = '{"status":"success","data":{'.$this->data.'}}';
- }else{
+ } else {
$json = '{"status":"success","data":null}';
}
// Upload JSON ///////////////////////////////////////////
-
- }elseif($this->upload_json!=''){
+ } elseif ($this->upload_json!='') {
$json = $this->upload_json;
// Error /////////////////////////////////////////////////
- }else{
+ } else {
$json = '{"status":"error","message":"'.$this->message.'"}';
}
// Output ////////////////////////////////////////////////
echo($json);
-
}
//////////////////////////////////////////////////////////////////
// Clean a path
//////////////////////////////////////////////////////////////////
- public static function cleanPath( $path ){
+ public static function cleanPath($path)
+ {
// replace backslash with slash
- $path = str_replace('\\', '/', $path );
+ $path = str_replace('\\', '/', $path);
// prevent Poison Null Byte injections
- $path = str_replace(chr(0), '', $path );
+ $path = str_replace(chr(0), '', $path);
// prevent go out of the workspace
- while (strpos($path , '../') !== false)
- $path = str_replace( '../', '', $path );
+ while (strpos($path, '../') !== false) {
+ $path = str_replace('../', '', $path);
+ }
return $path;
}
-
}
-
-?>
diff --git a/components/filemanager/controller.php b/components/filemanager/controller.php
index bea9c24..e0e80ca 100755
--- a/components/filemanager/controller.php
+++ b/components/filemanager/controller.php
@@ -19,26 +19,29 @@
// Get Action
//////////////////////////////////////////////////////////////////
- if(!empty($_GET['action'])){ $action = $_GET['action']; }
- else{ exit('{"status":"error","data":{"error":"No Action Specified"}}'); }
+if (!empty($_GET['action'])) {
+ $action = $_GET['action'];
+} else {
+ exit('{"status":"error","data":{"error":"No Action Specified"}}');
+}
//////////////////////////////////////////////////////////////////
// Ensure Project Has Been Loaded
//////////////////////////////////////////////////////////////////
- if(!isset($_SESSION['project'])){
- $_GET['action']='get_current';
- $_GET['no_return']='true';
- require_once('../project/controller.php');
- }
+if (!isset($_SESSION['project'])) {
+ $_GET['action']='get_current';
+ $_GET['no_return']='true';
+ require_once('../project/controller.php');
+}
//////////////////////////////////////////////////////////////////
// Security Check
- //////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////
- if (!checkPath($_GET['path'])) {
- die('{"status":"error","message":"Invalid Path"}');
- }
+if (!checkPath($_GET['path'])) {
+ die('{"status":"error","message":"Invalid Path"}');
+}
//////////////////////////////////////////////////////////////////
// Define Root
@@ -50,22 +53,40 @@
// Handle Action
//////////////////////////////////////////////////////////////////
- $Filemanager = new Filemanager($_GET,$_POST,$_FILES);
+ $Filemanager = new Filemanager($_GET, $_POST, $_FILES);
$Filemanager->project = @$_SESSION['project']['path'];
- switch($action){
- case 'index': $Filemanager->index(); break;
- case 'search': $Filemanager->search(); break;
- case 'find': $Filemanager->find(); break;
- case 'open' : $Filemanager->open(); break;
- case 'open_in_browser': $Filemanager->openinbrowser(); break;
- case 'create': $Filemanager->create(); break;
- case 'delete': $Filemanager->delete(); break;
- case 'modify': $Filemanager->modify(); break;
- case 'duplicate': $Filemanager->duplicate(); break;
- case 'upload': $Filemanager->upload(); break;
- default: exit('{"status":"fail","data":{"error":"Unknown Action"}}');
- }
-
-
-?>
+switch ($action) {
+ case 'index':
+ $Filemanager->index();
+ break;
+ case 'search':
+ $Filemanager->search();
+ break;
+ case 'find':
+ $Filemanager->find();
+ break;
+ case 'open':
+ $Filemanager->open();
+ break;
+ case 'open_in_browser':
+ $Filemanager->openinbrowser();
+ break;
+ case 'create':
+ $Filemanager->create();
+ break;
+ case 'delete':
+ $Filemanager->delete();
+ break;
+ case 'modify':
+ $Filemanager->modify();
+ break;
+ case 'duplicate':
+ $Filemanager->duplicate();
+ break;
+ case 'upload':
+ $Filemanager->upload();
+ break;
+ default:
+ exit('{"status":"fail","data":{"error":"Unknown Action"}}');
+}
diff --git a/components/filemanager/download.php b/components/filemanager/download.php
index 3c5a93e..c3a0a52 100755
--- a/components/filemanager/download.php
+++ b/components/filemanager/download.php
@@ -18,53 +18,53 @@
// Check $_GET for invalid path
//////////////////////////////////////////////////////////////////
//TODO check if the User is allowed to access the project
- if(!isset($_GET['path'])
- || preg_match('#^[\\\/]?$#i', trim($_GET['path'])) // download all Projects
- || preg_match('#[\:*?\"<>\|]#i', $_GET['path']) //illegal chars in filenames
- || substr_count($_GET['path'], './') > 0) { // change directory up to escape Workspace
- exit('');
- }
+if (!isset($_GET['path'])
+ || preg_match('#^[\\\/]?$#i', trim($_GET['path'])) // download all Projects
+ || preg_match('#[\:*?\"<>\|]#i', $_GET['path']) //illegal chars in filenames
+ || substr_count($_GET['path'], './') > 0) { // change directory up to escape Workspace
+ exit('');
+}
//////////////////////////////////////////////////////////////////
// Run Download
//////////////////////////////////////////////////////////////////
- if(isset($_GET['type']) && ($_GET['type']=='directory' || $_GET['type']=='root')){
- // Create tarball
- $filename = explode("/",$_GET['path']);
- //$filename = array_pop($filename) . "-" . date('Y.m.d') . ".tar.gz";
- $filename = array_pop($filename) . "-" . date('Y.m.d');
- $targetPath = DATA . '/';
- $dir = WORKSPACE . '/' . $_GET['path'];
- if(!is_dir($dir)){
- exit('');
- }
-
- //////////////////////////////////////////////////////////////////
- // Check system() command and a non windows OS
- //////////////////////////////////////////////////////////////////
- if(isAvailable('system') && stripos(PHP_OS, 'win') === false){
- # Execute the tar command and save file
- $filename .= '.tar.gz';
-
- system("tar -pczf ".escapeshellarg($targetPath.$filename)." -C ".escapeshellarg(WORKSPACE)." ".escapeshellarg($_GET['path']));
- $download_file = $targetPath.$filename;
- }elseif(extension_loaded('zip')){ //Check if zip-Extension is availiable
- //build zipfile
- require_once 'class.dirzip.php';
-
- $filename .= '.zip';
- $download_file = $targetPath.$filename;
- DirZip::zipDir($dir, $targetPath .$filename);
- }else{
- exit('');
- }
- }else{
- $filename = explode("/",$_GET['path']);
- $filename = array_pop($filename);
- $download_file = WORKSPACE . '/' . $_GET['path'];
+if (isset($_GET['type']) && ($_GET['type']=='directory' || $_GET['type']=='root')) {
+ // Create tarball
+ $filename = explode("/", $_GET['path']);
+ //$filename = array_pop($filename) . "-" . date('Y.m.d') . ".tar.gz";
+ $filename = array_pop($filename) . "-" . date('Y.m.d');
+ $targetPath = DATA . '/';
+ $dir = WORKSPACE . '/' . $_GET['path'];
+ if (!is_dir($dir)) {
+ exit('');
}
+ //////////////////////////////////////////////////////////////////
+ // Check system() command and a non windows OS
+ //////////////////////////////////////////////////////////////////
+ if (isAvailable('system') && stripos(PHP_OS, 'win') === false) {
+ # Execute the tar command and save file
+ $filename .= '.tar.gz';
+
+ system("tar -pczf ".escapeshellarg($targetPath.$filename)." -C ".escapeshellarg(WORKSPACE)." ".escapeshellarg($_GET['path']));
+ $download_file = $targetPath.$filename;
+ } elseif (extension_loaded('zip')) { //Check if zip-Extension is availiable
+ //build zipfile
+ require_once 'class.dirzip.php';
+
+ $filename .= '.zip';
+ $download_file = $targetPath.$filename;
+ DirZip::zipDir($dir, $targetPath .$filename);
+ } else {
+ exit('');
+ }
+} else {
+ $filename = explode("/", $_GET['path']);
+ $filename = array_pop($filename);
+ $download_file = WORKSPACE . '/' . $_GET['path'];
+}
+
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
@@ -73,11 +73,12 @@
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($download_file));
- if (ob_get_contents())
- ob_end_clean();
+if (ob_get_contents()) {
+ ob_end_clean();
+}
flush();
readfile($download_file);
// Remove temp tarball
- if($_GET['type']=='directory' || $_GET['type']=='root'){ unlink($download_file); }
-
-?>
+if ($_GET['type']=='directory' || $_GET['type']=='root') {
+ unlink($download_file);
+}
diff --git a/components/install/process.php b/components/install/process.php
index 23fea04..68deffe 100644
--- a/components/install/process.php
+++ b/components/install/process.php
@@ -24,47 +24,53 @@
// Functions
//////////////////////////////////////////////////////////////////////
- function saveFile($file,$data){
- $write = fopen($file, 'w') or die("can't open file");
- fwrite($write, $data);
- fclose($write);
+function saveFile($file, $data)
+{
+ $write = fopen($file, 'w') or die("can't open file");
+ fwrite($write, $data);
+ fclose($write);
+}
+
+function saveJSON($file, $data)
+{
+ $data = "";
+ saveFile($file, $data);
+}
+
+function encryptPassword($p)
+{
+ return sha1(md5($p));
+}
+
+function cleanUsername($username)
+{
+ return preg_replace('#[^A-Za-z0-9'.preg_quote('-_@. ').']#', '', $username);
+}
+
+function isAbsPath($path)
+{
+ return $path[0] === '/';
+}
+
+function cleanPath($path)
+{
+
+ // prevent Poison Null Byte injections
+ $path = str_replace(chr(0), '', $path);
+
+ // prevent go out of the workspace
+ while (strpos($path, '../') !== false) {
+ $path = str_replace('../', '', $path);
}
- function saveJSON($file,$data){
- $data = "";
- saveFile($file,$data);
- }
-
- function encryptPassword($p){
- return sha1(md5($p));
- }
-
- function cleanUsername($username){
- return preg_replace('#[^A-Za-z0-9'.preg_quote('-_@. ').']#','', $username);
- }
-
- function isAbsPath( $path ) {
- return $path[0] === '/';
- }
-
- function cleanPath( $path ){
-
- // prevent Poison Null Byte injections
- $path = str_replace(chr(0), '', $path );
-
- // prevent go out of the workspace
- while (strpos($path , '../') !== false)
- $path = str_replace( '../', '', $path );
-
- return $path;
- }
+ return $path;
+}
//////////////////////////////////////////////////////////////////////
// Verify no overwrites
//////////////////////////////////////////////////////////////////////
-if(!file_exists($users) && !file_exists($projects) && !file_exists($active)){
-
+if (!file_exists($users) && !file_exists($projects) && !file_exists($active)) {
//////////////////////////////////////////////////////////////////
// Get POST responses
//////////////////////////////////////////////////////////////////
@@ -72,7 +78,7 @@ if(!file_exists($users) && !file_exists($projects) && !file_exists($active)){
$username = cleanUsername($_POST['username']);
$password = encryptPassword($_POST['password']);
$project_name = $_POST['project_name'];
- if(isset($_POST['project_path'])) {
+ if (isset($_POST['project_path'])) {
$project_path = $_POST['project_path'];
} else {
$project_path = $project_name;
@@ -85,27 +91,27 @@ if(!file_exists($users) && !file_exists($projects) && !file_exists($active)){
$project_path = cleanPath($project_path);
- if(!isAbsPath($project_path)) {
- $project_path = str_replace(" ","_",preg_replace('/[^\w-\.]/', '', $project_path));
+ if (!isAbsPath($project_path)) {
+ $project_path = str_replace(" ", "_", preg_replace('/[^\w-\.]/', '', $project_path));
mkdir($workspace . "/" . $project_path);
} else {
$project_path = cleanPath($project_path);
- if(substr($project_path, -1) == '/') {
- $project_path = substr($project_path,0, strlen($project_path)-1);
+ if (substr($project_path, -1) == '/') {
+ $project_path = substr($project_path, 0, strlen($project_path)-1);
}
- if(!file_exists($project_path)) {
- if(!mkdir($project_path.'/', 0755, true)) {
+ if (!file_exists($project_path)) {
+ if (!mkdir($project_path.'/', 0755, true)) {
die("Unable to create Absolute Path");
}
} else {
- if(!is_writable($project_path) || !is_readable($project_path)) {
+ if (!is_writable($project_path) || !is_readable($project_path)) {
die("No Read/Write Permission");
}
}
}
$project_data = array("name"=>$project_name,"path"=>$project_path);
- saveJSON($projects,array($project_data));
+ saveJSON($projects, array($project_data));
//////////////////////////////////////////////////////////////////
// Create Users file
@@ -113,13 +119,13 @@ if(!file_exists($users) && !file_exists($projects) && !file_exists($active)){
$user_data = array("username"=>$username,"password"=>$password,"project"=>$project_path);
- saveJSON($users,array($user_data));
+ saveJSON($users, array($user_data));
//////////////////////////////////////////////////////////////////
// Create Active file
//////////////////////////////////////////////////////////////////
- saveJSON($active,array(''));
+ saveJSON($active, array(''));
//////////////////////////////////////////////////////////////////
// Create Config
@@ -182,10 +188,7 @@ define("WSURL", BASE_URL . "/workspace");
//define("COMMITURL", "https://api.github.com/repos/Codiad/Codiad/commits");
';
- saveFile($config,$config_data);
+ saveFile($config, $config_data);
echo("success");
-
}
-
-?>
diff --git a/components/install/view.php b/components/install/view.php
index 17587b5..b2905ba 100644
--- a/components/install/view.php
+++ b/components/install/view.php
@@ -7,25 +7,25 @@
* [root]/license.txt for more. This information must remain intact.
*/
-$path = rtrim(str_replace("index.php", "", $_SERVER['SCRIPT_FILENAME']),"/");
+$path = rtrim(str_replace("index.php", "", $_SERVER['SCRIPT_FILENAME']), "/");
-$workspace = is_writable( $path . "/workspace");
+$workspace = is_writable($path . "/workspace");
$data = is_writable($path . "/data");
$plugins = is_writable($path . "/plugins");
$themes = is_writable($path . "/themes");
-$workspace = is_writable( $path . "/workspace");
+$workspace = is_writable($path . "/workspace");
$conf = $path . '/config.php';
$config = is_writable(file_exists($conf) ? $conf : $path);
-if(ini_get('register_globals') == 1) {
+if (ini_get('register_globals') == 1) {
$register = true;
} else {
$register = false;
}
-if(ini_get('newrelic.enabled') == 1) {
+if (ini_get('newrelic.enabled') == 1) {
$newrelic = true;
} else {
$newrelic = false;
@@ -43,51 +43,77 @@ $autocomplete = array(
);
if (!empty($query)) {
- $params = explode('&', $query);
- foreach ($params as $param) {
- $param = explode('=', $param);
- if (array_key_exists($param[0], $autocomplete)) {
- $autocomplete[$param[0]] = urldecode($param[1]);
- }
- }
+ $params = explode('&', $query);
+ foreach ($params as $param) {
+ $param = explode('=', $param);
+ if (array_key_exists($param[0], $autocomplete)) {
+ $autocomplete[$param[0]] = urldecode($param[1]);
+ }
+ }
}
-if(!$workspace || !$data || !$config || $register || $newrelic){
+if (!$workspace || !$data || !$config || $register || $newrelic) {
?>
[SYSTEM]/config.php - PASSED'; } else { echo 'ERROR'; } ?>
-[SYSTEM]/workspace - PASSED'; } else { echo 'ERROR'; } ?>
-[SYSTEM]/plugins - PASSED'; } else { echo 'ERROR'; } ?>
-[SYSTEM]/themes - PASSED'; } else { echo 'ERROR'; } ?>
-[SYSTEM]/data - PASSED'; } else { echo 'ERROR'; } ?>
+[SYSTEM]/config.php - PASSED'; +} else { + echo 'ERROR'; +} ?>
+[SYSTEM]/workspace - PASSED'; +} else { + echo 'ERROR'; +} ?>
+[SYSTEM]/plugins - PASSED'; +} else { + echo 'ERROR'; +} ?>
+[SYSTEM]/themes - PASSED'; +} else { + echo 'ERROR'; +} ?>
+[SYSTEM]/data - PASSED'; +} else { + echo 'ERROR'; +} ?>
newrelic.enabled: Off
'; } ?> + register_globals: Off'; +} +if ($newrelic) { + echo 'newrelic.enabled: Off
'; +} ?>