Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
9ecb36e8
Commit
9ecb36e8
authored
10 years ago
by
Thomas Müller
Browse files
Options
Downloads
Patches
Plain Diff
integrate code checker in the installer
parent
d74662df
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/app/codechecker.php
+19
-4
19 additions, 4 deletions
lib/private/app/codechecker.php
lib/private/app/codecheckvisitor.php
+0
-0
0 additions, 0 deletions
lib/private/app/codecheckvisitor.php
lib/private/installer.php
+8
-50
8 additions, 50 deletions
lib/private/installer.php
with
27 additions
and
54 deletions
lib/private/app/codechecker.php
+
19
−
4
View file @
9ecb36e8
...
...
@@ -29,6 +29,12 @@ class CodeChecker extends BasicEmitter {
const
CLASS_CONST_FETCH_NOT_ALLOWED
=
1003
;
const
CLASS_NEW_FETCH_NOT_ALLOWED
=
1004
;
/** @var Parser */
private
$parser
;
/** @var string[] */
private
$blackListedClassNames
;
public
function
__construct
()
{
$this
->
parser
=
new
Parser
(
new
Lexer
);
$this
->
blackListedClassNames
=
[
...
...
@@ -67,14 +73,22 @@ class CodeChecker extends BasicEmitter {
throw
new
\RuntimeException
(
"No app with given id <
$appId
> known."
);
}
return
$this
->
analyseFolder
(
$appPath
);
}
/**
* @param string $folder
* @return array
*/
public
function
analyseFolder
(
$folder
)
{
$errors
=
[];
$excludes
=
array_map
(
function
(
$item
)
use
(
$
appPath
)
{
return
$
appPath
.
'/'
.
$item
;
$excludes
=
array_map
(
function
(
$item
)
use
(
$
folder
)
{
return
$
folder
.
'/'
.
$item
;
},
[
'vendor'
,
'3rdparty'
,
'.git'
,
'l10n'
]);
$iterator
=
new
RecursiveDirectoryIterator
(
$
appPath
,
RecursiveDirectoryIterator
::
SKIP_DOTS
);
$iterator
=
new
RecursiveCallbackFilterIterator
(
$iterator
,
function
(
$item
)
use
(
$
appPath
,
$excludes
){
$iterator
=
new
RecursiveDirectoryIterator
(
$
folder
,
RecursiveDirectoryIterator
::
SKIP_DOTS
);
$iterator
=
new
RecursiveCallbackFilterIterator
(
$iterator
,
function
(
$item
)
use
(
$
folder
,
$excludes
){
/** @var SplFileInfo $item */
foreach
(
$excludes
as
$exclude
)
{
if
(
substr
(
$item
->
getPath
(),
0
,
strlen
(
$exclude
))
===
$exclude
)
{
...
...
@@ -96,6 +110,7 @@ class CodeChecker extends BasicEmitter {
return
$errors
;
}
/**
* @param string $file
* @return array
...
...
This diff is collapsed.
Click to expand it.
lib/private/app/codecheck
er
visitor.php
→
lib/private/app/codecheckvisitor.php
+
0
−
0
View file @
9ecb36e8
File moved
This diff is collapsed.
Click to expand it.
lib/private/installer.php
+
8
−
50
View file @
9ecb36e8
...
...
@@ -308,7 +308,7 @@ class OC_Installer{
}
$info
=
OC_App
::
getAppInfo
(
$extractDir
.
'/appinfo/info.xml'
,
true
);
// check the code for not allowed calls
if
(
!
$isShipped
&&
!
OC_Installer
::
checkCode
(
$info
[
'id'
],
$extractDir
))
{
if
(
!
$isShipped
&&
!
OC_Installer
::
checkCode
(
$extractDir
))
{
OC_Helper
::
rmdirr
(
$extractDir
);
throw
new
\Exception
(
$l
->
t
(
"App can't be installed because of not allowed code in the App"
));
}
...
...
@@ -529,58 +529,16 @@ class OC_Installer{
* @param string $folder the folder of the app to check
* @return boolean true for app is o.k. and false for app is not o.k.
*/
public
static
function
checkCode
(
$appname
,
$folder
)
{
$blacklist
=
array
(
// classes replaced by the public api
'OC_API::'
,
'OC_App::'
,
'OC_AppConfig::'
,
'OC_Avatar'
,
'OC_BackgroundJob::'
,
'OC_Config::'
,
'OC_DB::'
,
'OC_Files::'
,
'OC_Helper::'
,
'OC_Hook::'
,
'OC_Image::'
,
'OC_JSON::'
,
'OC_L10N::'
,
'OC_Log::'
,
'OC_Mail::'
,
'OC_Request::'
,
'OC_Response::'
,
'OC_Template::'
,
'OC_User::'
,
'OC_Util::'
,
);
public
static
function
checkCode
(
$folder
)
{
// is the code checker enabled?
if
(
OC_Config
::
getValue
(
'appcodechecker'
,
false
))
{
// check if grep is installed
$grep
=
\OC_Helper
::
findBinaryPath
(
'grep'
);
if
(
!
$grep
)
{
OC_Log
::
write
(
'core'
,
'grep not installed. So checking the code of the app "'
.
$appname
.
'" was not possible'
,
OC_Log
::
ERROR
);
return
true
;
}
// iterate the bad patterns
foreach
(
$blacklist
as
$bl
)
{
$cmd
=
'grep --include \\*.php -ri '
.
escapeshellarg
(
$bl
)
.
' '
.
$folder
.
''
;
$result
=
exec
(
$cmd
);
// bad pattern found
if
(
$result
<>
''
)
{
OC_Log
::
write
(
'core'
,
'App "'
.
$appname
.
'" is using a not allowed call "'
.
$bl
.
'". Installation refused.'
,
OC_Log
::
ERROR
);
return
false
;
}
}
return
true
;
}
else
{
if
(
!
OC_Config
::
getValue
(
'appcodechecker'
,
false
))
{
return
true
;
}
$codeChecker
=
new
\OC\App\CodeChecker
();
$errors
=
$codeChecker
->
analyseFolder
(
$folder
);
return
empty
(
$errors
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment