Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
c29565fc
Commit
c29565fc
authored
10 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
php8 only; added variable types; short array syntax; remove glyphicons
parent
60c6f1ad
No related branches found
No related tags found
1 merge request
!66
php8 only; added variable types; short array syntax; remove glyphicons
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
public_html/deployment/classes/actionlog.class.php
+108
-72
108 additions, 72 deletions
public_html/deployment/classes/actionlog.class.php
public_html/deployment/classes/base.class.php
+3
-3
3 additions, 3 deletions
public_html/deployment/classes/base.class.php
with
111 additions
and
75 deletions
public_html/deployment/classes/actionlog.class.php
+
108
−
72
View file @
c29565fc
...
...
@@ -5,16 +5,46 @@ require_once 'user.class.php';
* class to log all project actions, ie. build, deploy etc.
*
* @author hahn
*
* 2024-08-23 v1.1 Axel Hahn php8 only; added variable types; short array syntax; remove glyphicons
*/
class
Actionlog
{
private
$_dbfile
=
''
;
private
$_aLoglevels
=
array
(
"info"
,
"warning"
,
"error"
,
"success"
);
// array of valid loglevels
private
$_sIP
=
false
;
private
$_sUser
=
false
;
private
$_sProject
=
false
;
private
$_sCreate
=
'
/**
* database file
* @var string
*/
private
string
$_dbfile
=
''
;
/**
* List of allowed loglevels
* @var array
*/
private
array
$_aLoglevels
=
[
"info"
,
"warning"
,
"error"
,
"success"
];
// array of valid loglevels
/**
* Ip address of the client
* @var string
*/
private
string
$_sIP
=
''
;
/**
* Authenticated user on the client
* @var string
*/
private
string
$_sUser
=
''
;
/**
* Current project
* @var string
*/
private
string
$_sProject
=
''
;
/**
* Create statement for the database
* @var string
*/
private
string
$_sCreate
=
'
CREATE TABLE "logs" (
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE ,
`time` DATETIME,
...
...
@@ -39,13 +69,14 @@ class Actionlog
`message` TEXT
)';
*/
/**
*
c
onstructor - sets internal environment variables and checks existence
*
C
onstructor - sets internal environment variables and checks existence
* of the database
* @global array $aConfig settings
* @param string $sProject project ID
*/
public
function
__construct
(
$sProject
=
false
)
public
function
__construct
(
string
$sProject
=
''
)
{
global
$aConfig
;
if
(
!
isset
(
$aConfig
[
"appRootDir"
]))
{
...
...
@@ -71,20 +102,22 @@ class Actionlog
}
/**
*
c
reate sqlite database - called in constructor if the file does not exist
*
C
reate sqlite database - called in constructor if the file does not exist
*/
private
function
_createDb
()
private
function
_createDb
()
:
bool
|
PDOstatement
{
echo
"try to create file
$this->_dbfile
...<br>
\n
"
;
return
$this
->
_makeQuery
(
$this
->
_sCreate
);
}
/**
* execute a sql statement
* Execute a sql statement and get the result
* TODO: support prepared statements
*
* @param string $sSql sql statement
* @return
database objec
t
* @return
bool|PDO statemen
t
*/
private
function
_makeQuery
(
$sSql
)
private
function
_makeQuery
(
string
$sSql
):
bool
|
PDOstatement
{
// $this->_log(__FUNCTION__."($sSql)");
// echo "<pre>".htmlentities($sSql)."</pre>";
...
...
@@ -100,16 +133,18 @@ class Actionlog
}
/**
* add a log message
* Add a log message
* TODO: supoport prepared statements
*
* @param string $sMessage message
* @param string $sAction project action; i.e. build, deploy, ...
* @param string $sLoglevel loglevel
* @return
type
* @return
bool|PDOstatement
*/
public
function
add
(
$sMessage
,
$sAction
=
""
,
$sLoglevel
=
"info"
,
$sTimeStart
=
false
)
public
function
add
(
string
$sMessage
,
string
$sAction
=
""
,
string
$sLoglevel
=
"info"
/*
, $sTimeStart = false
*/
):
bool
|
PDOstatement
{
if
(
array_search
(
$sLoglevel
,
$this
->
_aLoglevels
)
===
false
)
{
die
(
__
class
__
.
": loglevel
$sLoglevel
is invalid"
);
die
(
__
CLASS
__
.
": loglevel
$sLoglevel
is invalid"
);
}
$sql
=
"INSERT INTO `logs` (`time`, `loglevel`, `ip`, `user`, `project` ,`action`, `message`)
VALUES(
...
...
@@ -143,18 +178,18 @@ class Actionlog
}
/**
*
h
elper function to remove chars in a string
*
H
elper function to remove chars in a string
* @param string $sVal user value
* @param string $sOKChars good chars to keep
* @return string
*/
private
function
_filterAllowedChars
(
$sVal
,
$sOKChars
)
private
function
_filterAllowedChars
(
string
$sVal
,
string
$sOKChars
)
:
string
{
return
preg_replace
(
'/[^'
.
$sOKChars
.
']/i'
,
''
,
$sVal
);
}
/**
*
g
et log data
*
G
et log data
* @param array $aFilter with the following keys:
* 'project' - filter by project; will be mixed with where (see next key)
* 'from ' - time greater equal; time as string i.e. "2020-06-24" or "2020-06-24 11:00:00"
...
...
@@ -163,15 +198,15 @@ class Actionlog
* 'limit' - limit clausel - part behind "LIMIT "
* @return array
*/
public
function
getLogs
(
$aFilter
=
array
())
public
function
getLogs
(
array
$aFilter
=
[]):
array
{
// var_dump(R::findAll( 'log' ));
$aReturn
=
array
()
;
$aReturn
=
[]
;
$sSql
=
'SELECT `id`,`time`,`loglevel`,`ip`,`user`,`project`,`action`,`message` from logs '
;
$sWhere
=
false
;
$aWhere
=
array
()
;
$aWhere
=
[]
;
if
(
isset
(
$aFilter
[
"project"
])
&&
$aFilter
[
"project"
])
{
$aWhere
[]
=
'`project`="'
.
$this
->
_filterAllowedChars
(
$aFilter
[
"project"
],
'[a-z0-9\-\_]'
)
.
'"'
;
}
...
...
@@ -203,14 +238,14 @@ class Actionlog
}
/**
*
render
html code for a table with logs. The filter will be sent to
*
Get
html code for a table with logs. The filter will be sent to
* getLogs method.
* @param array $aFilter with the following keys:
* 'project' - filter by project; will be mixed with where (see next key)
* 'limit' - limit clausel - part behind "LIMIT "
* @return string
*/
public
function
renderLogs
(
$aFilter
=
array
(),
$bIsFullsearch
=
false
)
public
function
renderLogs
(
array
$aFilter
=
[],
bool
$bIsFullsearch
=
false
)
:
string
{
$sReturn
=
''
;
...
...
@@ -220,35 +255,36 @@ class Actionlog
$bWasShown
=
true
;
require_once
'formgen.class.php'
;
$oHtml
=
new
htmlguielements
();
// values for dropdowns - limit of lines; time
$aLimits
=
array
(
'20'
=>
array
(
'label'
=>
20
)
,
'50'
=>
array
(
'label'
=>
50
)
,
'100'
=>
array
(
'label'
=>
100
)
,
''
=>
array
(
'label'
=>
t
(
"all"
)
)
,
)
;
$aTimes
=
array
(
date
(
"Y-m-d"
,
date
(
"U"
))
=>
array
(
'label'
=>
t
(
"class-actionlog-time-today"
)
)
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
1
)
=>
array
(
'label'
=>
t
(
"class-actionlog-time-since-yesterday"
)
)
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
7
)
=>
array
(
'label'
=>
t
(
"class-actionlog-time-for-1-week"
)
)
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
7
*
2
)
=>
array
(
'label'
=>
sprintf
(
t
(
"class-actionlog-time-for-n-weeks"
),
"2"
)
)
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
7
*
4
)
=>
array
(
'label'
=>
sprintf
(
t
(
"class-actionlog-time-for-n-weeks"
),
"4"
)
)
,
''
=>
array
(
'label'
=>
t
(
"all"
)
)
,
)
;
$aForms
=
array
(
'filter'
=>
array
(
'meta'
=>
array
(
$aLimits
=
[
'20'
=>
[
'label'
=>
20
]
,
'50'
=>
[
'label'
=>
50
]
,
'100'
=>
[
'label'
=>
100
]
,
''
=>
[
'label'
=>
t
(
"all"
)
]
,
]
;
$aTimes
=
[
date
(
"Y-m-d"
,
date
(
"U"
))
=>
[
'label'
=>
t
(
"class-actionlog-time-today"
)
]
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
1
)
=>
[
'label'
=>
t
(
"class-actionlog-time-since-yesterday"
)
]
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
7
)
=>
[
'label'
=>
t
(
"class-actionlog-time-for-1-week"
)
]
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
7
*
2
)
=>
[
'label'
=>
sprintf
(
t
(
"class-actionlog-time-for-n-weeks"
),
"2"
)
]
,
date
(
"Y-m-d"
,
date
(
"U"
)
-
60
*
60
*
24
*
7
*
4
)
=>
[
'label'
=>
sprintf
(
t
(
"class-actionlog-time-for-n-weeks"
),
"4"
)
]
,
''
=>
[
'label'
=>
t
(
"all"
)
]
,
]
;
$aForms
=
[
'filter'
=>
[
'meta'
=>
[
'method'
=>
'GET'
,
'action'
=>
'?'
,
'class'
=>
'form-inline'
,
)
,
'validate'
=>
array
()
,
'form'
=>
array
()
,
)
)
;
]
,
'validate'
=>
[]
,
'form'
=>
[]
,
]
]
;
// generate filter for log table
// $bIsFullsearch: true = show all inputs; false: no interactive search
...
...
@@ -257,61 +293,61 @@ class Actionlog
// --- list of all projects in log
$sSql
=
'SELECT DISTINCT(project) from `logs` order by project asc'
;
$aForms
[
"filter"
][
"form"
][
'selectproject'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'selectproject'
]
=
[
'type'
=>
'select'
,
'name'
=>
'selectproject'
,
'label'
=>
'<i class="glyphicon glyphicon-tag"></i> '
.
t
(
'project'
),
'label'
=>
$oHtml
->
getIcon
(
'project'
)
.
' '
.
t
(
'project'
),
'class'
=>
'span2'
,
'onchange'
=>
'updateActionlog();'
,
'inline'
=>
true
,
)
;
$aForms
[
"filter"
][
"form"
][
'selectproject'
][
'options'
][
''
]
=
array
(
'label'
=>
t
(
"all"
)
)
;
]
;
$aForms
[
"filter"
][
"form"
][
'selectproject'
][
'options'
][
''
]
=
[
'label'
=>
t
(
"all"
)
]
;
foreach
(
$this
->
_makeQuery
(
$sSql
)
as
$row
)
{
if
(
$row
[
0
])
{
$aForms
[
"filter"
][
"form"
][
'selectproject'
][
'options'
][
$row
[
0
]]
=
array
(
'label'
=>
$row
[
0
]
)
;
$aForms
[
"filter"
][
"form"
][
'selectproject'
][
'options'
][
$row
[
0
]]
=
[
'label'
=>
$row
[
0
]
]
;
}
}
$aForms
[
"filter"
][
"form"
][
'selectfrom'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'selectfrom'
]
=
[
'type'
=>
'select'
,
'name'
=>
'selectWheretime'
,
'label'
=>
'<i class="glyphicon glyphicon-calendar"></i> '
.
t
(
"class-actionlog-time"
),
'label'
=>
$oHtml
->
getIcon
(
'calendar'
)
.
' '
.
t
(
"class-actionlog-time"
),
'class'
=>
'span2'
,
'onchange'
=>
'updateActionlog();'
,
'options'
=>
$aTimes
,
'inline'
=>
true
,
)
;
$aForms
[
"filter"
][
"form"
][
'selectlimit'
]
=
array
(
]
;
$aForms
[
"filter"
][
"form"
][
'selectlimit'
]
=
[
'type'
=>
'select'
,
'name'
=>
'selectlimit'
,
'label'
=>
'<i class="glyphicon glyphicon-list"></i> '
.
t
(
"class-actionlog-count"
),
'label'
=>
$oHtml
->
getIcon
(
'list'
)
.
' '
.
t
(
"class-actionlog-count"
),
'class'
=>
'span1'
,
'onchange'
=>
'updateActionlog();'
,
'options'
=>
$aLimits
,
'inline'
=>
true
,
)
;
]
;
// force a line break
$aForms
[
"filter"
][
"form"
][
'line'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'line'
]
=
[
'type'
=>
'markup'
,
'value'
=>
'<div class="col-sm-12"></div>'
,
)
;
]
;
}
else
{
// write filters as hidden fields
if
(
isset
(
$aFilter
[
"project"
]))
{
$aForms
[
"filter"
][
"form"
][
'selectproject'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'selectproject'
]
=
[
'type'
=>
'hidden'
,
'value'
=>
$aFilter
[
"project"
]
)
;
]
;
}
if
(
isset
(
$aFilter
[
"limit"
]))
{
$aForms
[
"filter"
][
"form"
][
'selectlimit'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'selectlimit'
]
=
[
'type'
=>
'hidden'
,
'value'
=>
$aFilter
[
"limit"
]
)
;
]
;
}
}
$aForms
[
"filter"
][
"form"
][
'efilterlogs'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'efilterlogs'
]
=
[
'type'
=>
'text'
,
'name'
=>
'efilterlogs'
,
'label'
=>
'<i class="glyphicon glyphicon-filter"></i>'
.
t
(
"overview-textsearch"
),
...
...
@@ -320,20 +356,20 @@ class Actionlog
'onkeypress'
=>
'filterLogTable();'
,
'onchange'
=>
'filterLogTable();'
,
//'size' => 20,
)
;
]
;
if
(
!
$bIsFullsearch
)
{
$aForms
[
"filter"
][
"form"
][
'btnalllogs'
]
=
array
(
$aForms
[
"filter"
][
"form"
][
'btnalllogs'
]
=
[
'type'
=>
'button'
,
'value'
=>
t
(
'show all'
),
'class'
=>
'btn btn-secondary btnlogs'
,
'href'
=>
'/deployment/all/setup/actionlog/'
,
'onclick'
=>
'location.href=\'/deployment/all/setup/actionlog/\'; return false;'
,
)
;
]
;
}
else
{
// $aForms["filter"]["form"]['closediv'] =
array(
// $aForms["filter"]["form"]['closediv'] =
[
// 'type' => 'markup',
// 'value' => '</div><!-- closediv -->',
//
)
;
//
]
;
}
...
...
This diff is collapsed.
Click to expand it.
public_html/deployment/classes/base.class.php
+
3
−
3
View file @
c29565fc
...
...
@@ -10,10 +10,10 @@ require_once 'user.class.php';
class
base
{
/**
* logged in user
* @var
object
* logged in user
as user object
* @var
user
*/
va
r
$oUser
=
false
;
public
use
r
$oUser
;
/**
* init user with optional given user
...
...
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