Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
IML Open Source
Imldeployment
Commits
4011ff8d
Commit
4011ff8d
authored
Sep 20, 2022
by
Hahn Axel (hahn)
Browse files
enable shell plugins (WIP)
parent
0fd07cd5
Changes
22
Hide whitespace changes
Inline
Side-by-side
public_html/deployment/classes/plugins.class.php
View file @
4011ff8d
...
...
@@ -13,29 +13,61 @@
* // print_r($CI_plugins->getPlugins());
* print_r($CI_plugins->getPlugins('build'));
*
* $CI_plugins->setPlugin('tgz', 'build');
* $CI_plugins->setPlugin('tgz', 'build');
// plugin name + type
*
*
* @author axel
*/
class
ciplugins
{
/**
* start path of all plugin types (as subdirs)
* @var string
*/
protected
$_sPlugindir
=
false
;
/**
* path of the currently set plugin
* @var string
*/
protected
$_sSelfdir
=
false
;
/**
* url of set plugin
* @var string
*/
protected
$_sSelfurl
=
false
;
/**
* current plugin type - can be set via setType or setPlugin
* @var string
*/
protected
$_sType
=
false
;
/**
* current plugin name - can be set via setPlugin
* @var string
*/
protected
$_sPluginname
=
false
;
/**
* plugin language
* @var string
*/
protected
$_sLang
=
"en-en"
;
/**
* plugin language texts (lang*.json)
* @var array
*/
protected
$_aLang
=
[];
/**
* plugin configuration data (config.json)
* @var array
*/
protected
$_aConfig
=
[];
// ---------------------------------------------------------------
// CONSTRUCTOR
...
...
@@ -51,43 +83,46 @@ class ciplugins {
return
true
;
}
// ---------------------------------------------------------------
//
LANGUA
GE
TE
XTS
//
FOR LISTING ::
GE
T
TE
R
// ---------------------------------------------------------------
/**
* get a translated text from lang_XX.json in plugin dir;
* If the key is missed it returns "[KEY :: LANG]"
*
* @see setLang()
* @param string $sKey key to find in lang file
* @return string
* get an array of available plugin types read from filesystem
* @return array
*/
protected
function
_t
(
$sKey
){
return
(
isset
(
$this
->
_aLang
[
$sKey
])
&&
$this
->
_aLang
[
$sKey
])
?
$this
->
_aLang
[
$sKey
]
:
"[
$sKey
::
$this->_sLang
]"
;
public
function
getPluginTypes
(){
$aReturn
=
[];
foreach
(
glob
(
$this
->
_sPlugindir
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
){
$aReturn
[]
=
basename
(
$sMydir
);
}
return
$aReturn
;
}
/**
* set language for output of formdata and other texts.
* This method loads the language file into a hash. The output of
* translated texts can be done with $this->_t("your_key")
*
* @see _t()
* @param string $sLang language code, i.e. "de"
* @return boolean
* get an array of available plugins read from filesystem
* @return array
*/
public
function
setLang
(
$sLang
=
false
){
$this
->
_sLang
=
$sLang
?
$sLang
:
$this
->
_sLang
;
$oReflection
=
new
ReflectionClass
(
$this
);
$sFile
=
dirname
(
$oReflection
->
getFileName
())
.
'/lang_'
.
$this
->
_sLang
.
'.json'
;
$this
->
_aLang
=
(
file_exists
(
$sFile
))
?
json_decode
(
file_get_contents
(
$sFile
),
1
)
:
$this
->
_aLang
;
return
true
;
public
function
getPlugins
(
$sType
=
false
){
$aReturn
=
[];
if
(
$sType
){
if
(
!
$this
->
setType
(
$sType
)){
return
$aReturn
;
}
}
foreach
(
glob
(
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
){
$aReturn
[]
=
basename
(
$sMydir
);
}
return
$aReturn
;
}
// ---------------------------------------------------------------
//
// BELOW ARE METHODS FOR A SET SPECIFIC PLUGIN AND TYPE
//
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// SETTER
// ---------------------------------------------------------------
...
...
@@ -97,6 +132,7 @@ class ciplugins {
* @param {string} $sType Name of a plugin type, e.g. build|rollout
*/
public
function
setType
(
$sType
){
$this
->
_sType
=
false
;
if
(
!
$sType
||
!
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$sType
)){
return
false
;
}
...
...
@@ -104,74 +140,88 @@ class ciplugins {
}
/**
* set a plugin with autoload
* reset vars before setting a new plugin;
* called in testPlugin()
* @return boolean
*/
protected
function
_resetPluginData
(){
$this
->
_sPluginname
=
false
;
$this
->
_sSelfdir
=
false
;
$this
->
_sSelfurl
=
false
;
$this
->
_aLang
=
[];
$this
->
_aConfig
=
[];
return
true
;
}
/**
* set a plugin without autoload of its php class
* It returns the path of php class for true
* or boolean false if it does not exist
*
* This can be used standalone to embed html code
* without loading any php code of the plugin class.
*
* @param {string} $sPluginName name of the plugin
* @param {string} $sType opt
u
ional: set a type
* @return bool
* @param {string} $sType optional: set a type
* @return bool
|string
*/
public
function
setPlugin
(
$sPluginName
,
$sType
=
false
){
public
function
testPlugin
(
$sPluginName
,
$sType
=
false
){
$this
->
_resetPluginData
();
if
(
$sType
){
if
(
!
$this
->
setType
(
$sType
)){
return
false
;
}
}
$sFile
=
$this
->
getPluginFilename
(
$sPluginName
);
$this
->
_sSelfdir
=
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/'
.
$sPluginName
;
$sFile
=
$this
->
_sSelfdir
.
'/plugin.php'
;
if
(
!
file_exists
(
$sFile
)){
// die(' MISS '.$sFile);
$this
->
_sSelfdir
=
false
;
return
false
;
}
include_once
$sFile
;
return
$this
->
_sPluginname
=
$sPluginName
;
$this
->
_sPluginname
=
$sPluginName
;
$this
->
_sSelfurl
=
'/deployment/plugins/'
.
$this
->
_sType
.
'/'
.
$sPluginName
;
return
$sFile
;
}
// ---------------------------------------------------------------
// GETTER
// ---------------------------------------------------------------
/**
*
g
et a
location of a plugin file with full path
*
The type must be initialized first with setType()
*
s
et a
plugin with autoload of its php class
*
It returns a boolean
*
* @param string $sPluginName optional: Name of plugin
* @return string
*/
public
function
getPluginFilename
(
$sPluginName
=
false
){
if
(
!
$sPluginName
){
$sPluginName
=
$this
->
_sPluginname
;
}
return
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/'
.
$sPluginName
.
'/'
.
$this
->
_sType
.
'_'
.
$sPluginName
.
'.php'
;
}
/**
* get an array of available plugin types read from filesystem
* @return array
* @param {string} $sPluginName name of the plugin
* @param {string} $sType optional: set a type
* @return bool
*/
public
function
g
etPlugin
Types
(
){
$
aReturn
=
[]
;
foreach
(
glob
(
$this
->
_sPlugindir
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
){
$aR
eturn
[]
=
basename
(
$sMydir
)
;
public
function
s
etPlugin
(
$sPluginName
,
$sType
=
false
){
$
sFile
=
$this
->
testPlugin
(
$sPluginName
,
$sType
)
;
if
(
!
$sFile
){
r
eturn
false
;
}
return
$aReturn
;
include_once
$sFile
;
return
true
;
}
// ---------------------------------------------------------------
// getter for plugin
// ---------------------------------------------------------------
/**
* get an array of available plugins read from filesystem
* get plugin config from its config.json
* works with
* - shellcmd plugin
* @return array
*/
public
function
getPlugins
(
$sType
=
false
){
$aReturn
=
[];
if
(
$sType
){
if
(
!
$this
->
setType
(
$sType
)){
return
$aReturn
;
}
public
function
getPluginConfig
(){
if
(
count
(
$this
->
_aConfig
)){
return
$this
->
_aConfig
;
}
foreach
(
glob
(
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
){
$aReturn
[]
=
basename
(
$sMydir
);
}
return
$aReturn
;
$this
->
_aConfig
=
(
file_exists
(
$this
->
_sSelfdir
.
'/config.json'
))
?
json_decode
(
file_get_contents
(
$this
->
_sSelfdir
.
'/config.json'
),
1
)
:
[
"error"
=>
"config.json not found in "
.
$this
->
_sSelfdir
]
;
return
$this
->
_aConfig
;
}
// ---------------------------------------------------------------
// access plugin php class
// ---------------------------------------------------------------
/**
* get a location of a plugin file with full path
...
...
public_html/deployment/classes/plugins_renderer.class.php
0 → 100644
View file @
4011ff8d
<?php
require_once
(
'plugins.class.php'
);
/**
* WIP
* base class for all plugin types to read available plugins
* and its metadata
*
* @example
* $CI_plugins=new ciplugins();
* print_r($CI_plugins->getPluginTypes());
*
* // $CI_plugins->setType('build');
* // print_r($CI_plugins->getPlugins());
* print_r($CI_plugins->getPlugins('build'));
*
* $CI_plugins->setPlugin('tgz', 'build'); // plugin name + type
*
*
* @author axel
*/
class
plugin_renderer
extends
ciplugins
{
// ---------------------------------------------------------------
//
// BELOW ARE METHODS FOR A SET SPECIFIC PLUGIN AND TYPE
//
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// LANGUAGE TEXTS (needed in ui only)
// ---------------------------------------------------------------
/**
* get a translated text from lang_XX.json in plugin dir;
* If the key is missed it returns "[KEY :: LANG]"
*
* @see setLang()
* @param string $sKey key to find in lang file
* @return string
*/
protected
function
_t
(
$sKey
){
return
(
isset
(
$this
->
_aLang
[
$sKey
])
&&
$this
->
_aLang
[
$sKey
])
?
$this
->
_aLang
[
$sKey
]
:
"[
$sKey
::
$this->_sLang
]"
;
}
/**
* set language for output of formdata and other texts.
* This method loads the language file into a hash. The output of
* translated texts can be done with $this->_t("your_key")
*
* @see _t()
* @param string $sLang language code, i.e. "de"
* @return boolean
*/
public
function
setLang
(
$sLang
=
false
){
$this
->
_sLang
=
$sLang
?
$sLang
:
$this
->
_sLang
;
$oReflection
=
new
ReflectionClass
(
$this
);
$sFile
=
dirname
(
$oReflection
->
getFileName
())
.
'/lang_'
.
$this
->
_sLang
.
'.json'
;
$this
->
_aLang
=
(
file_exists
(
$sFile
))
?
json_decode
(
file_get_contents
(
$sFile
),
1
)
:
$this
->
_aLang
;
return
true
;
}
// ---------------------------------------------------------------
// SETTER
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// prepare html code
// ---------------------------------------------------------------
/**
* for shellcmd plugins: get html code to load javascript file
* The file must exist in the plugin directory
* @params string $sFile (basename of) filename, eg. render.js
*/
public
function
getHtmlLoadScript
(
$sFile
){
return
(
file_exists
(
$this
->
_sSelfdir
.
'/'
.
$sFile
))
?
'<script src="'
.
$this
->
_sSelfurl
.
'/'
.
$sFile
.
'"></script>'
.
"
\n
"
:
''
;
}
/**
* get id for an output div
* @return string
*/
public
function
getHtmlOutId
(){
return
$this
->
_sPluginname
?
'divPlugin'
.
$this
->
_sType
.
''
.
$this
->
_sPluginname
:
false
;
}
/**
* get id for the wrapper div of an output div
* @return string
*/
public
function
getHtmlOutIdWrapper
(){
return
$this
->
getHtmlOutId
()
.
'Wrapper'
;
}
public
function
getHtmlOutwindow
(){
$aConfig
=
$this
->
getPluginConfig
();
return
'<div id="'
.
$this
->
getHtmlOutIdWrapper
()
.
'" class="cmdoutbox draggable draggable-onpage">'
// .'<button class="btn-close float-right">X</button>'
.
'<div class="header"><i class="'
.
$aConfig
[
'icon'
]
.
'"></i> '
.
$this
->
_sPluginname
.
'</div>'
.
'<div id="'
.
$this
->
getHtmlOutId
()
.
'" '
.
'class="out'
.
(
isset
(
$aConfig
[
'window-cols'
])
&&
$aConfig
[
'window-cols'
]
?
' cmd-cols-'
.
$aConfig
[
'window-cols'
]
:
''
)
.
(
isset
(
$aConfig
[
'window-lines'
])
&&
$aConfig
[
'window-lines'
]
?
' cmd-lines-'
.
$aConfig
[
'window-lines'
]
:
''
)
.
'"></div>'
.
'</div>'
;
}
// ---------------------------------------------------------------
// access plugin php class
// ---------------------------------------------------------------
}
public_html/deployment/inc_functions.php
View file @
4011ff8d
...
...
@@ -196,7 +196,7 @@ function aGotop($sClass = "scroll-link btn btn-default") {
* @global type $aParams
* @return type
*/
function
getTopArea
()
{
function
getTopArea
(
$aEmbed
=
[]
)
{
global
$aParams
,
$oHtml
;
$sReturn
=
''
;
require_once
(
"./classes/project.class.php"
);
...
...
@@ -391,6 +391,10 @@ function getTopArea() {
</ul>
<ul class="nav navbar-nav navbar-right">'
.
(
isset
(
$aEmbed
[
'right'
])
?
$aEmbed
[
'right'
]
:
''
)
.
(
$oUser
->
getUsername
()
?
'
<!-- userdata -->
...
...
public_html/deployment/index.php
View file @
4011ff8d
...
...
@@ -23,6 +23,7 @@ ini_set('display_startup_errors', 1);
error_reporting
(
E_ALL
);
require_once
(
"./classes/page.class.php"
);
require_once
(
"./classes/plugins_renderer.class.php"
);
// detect first run
$bFirstRun
=!
file_exists
(
"../../config/config_custom.php"
)
||
!
file_exists
(
"../../config/inc_user2roles.php"
);
...
...
@@ -40,7 +41,9 @@ $oHtml=new htmlguielements();
$sPrj
=
""
;
$sAction
=
"overview"
;
// ------ check parameters
// ----------------------------------------------------------------------
// check params
// ----------------------------------------------------------------------
if
(
array_key_exists
(
"prj"
,
$aParams
))
{
$sPrj
=
$aParams
[
"prj"
];
...
...
@@ -60,15 +63,55 @@ if($bFirstRun){
$sAction
=
'installer'
;
}
// ------ Ausgabe
$sHeader
=
'<style>'
;
// ----------------------------------------------------------------------
// html header
// ----------------------------------------------------------------------
$sHeader
=
"
\n
<!-- generated CSS for phases -->
\n
<style>
\n
"
;
foreach
(
$aConfig
[
"phases"
]
as
$sPhase
=>
$aData
)
{
$sHeader
.
=
array_key_exists
(
"bgdark"
,
$aData
[
"css"
])
?
'th.'
.
$sPhase
.
'{'
.
$aData
[
"css"
][
"bgdark"
]
.
'}'
:
''
;
$sHeader
.
=
array_key_exists
(
"bglight"
,
$aData
[
"css"
])
?
'td.'
.
$sPhase
.
', div.'
.
$sPhase
.
'{'
.
$aData
[
"css"
][
"bglight"
]
.
'}'
:
''
;
$sHeader
.
=
array_key_exists
(
"bgbutton"
,
$aData
[
"css"
])
?
'a.'
.
$sPhase
.
',a.'
.
$sPhase
.
':hover,button.'
.
$sPhase
.
',button.'
.
$sPhase
.
':hover{'
.
$aData
[
"css"
][
"bgbutton"
]
.
'}'
:
''
;
}
$sHeader
.
=
'</style>'
;
$sTopArea
=
getTopArea
();
$sHeader
.
=
"</style>
\n
"
;
// add shellcmd files
$sShellOuptut
=
''
;
$sTopRight
=
''
;
$CI_plugins
=
new
plugin_renderer
();
$CI_plugins
->
setType
(
'shellcmd'
);
$aPluginsShellcmd
=
$CI_plugins
->
getPlugins
();
$sHeader
=
"
\n
<!-- shellcmd plugins :: js files -->
\n
"
;
$sHeader
.
=
'<script src="/deployment/js/ubd.class.js"></script>'
.
"
\n
"
.
'<script src="/deployment/js/addi.js"></script>'
.
"
\n
"
;
foreach
(
$CI_plugins
->
getPlugins
(
'shellcmd'
)
as
$sPlugin
){
if
(
$CI_plugins
->
testPlugin
(
$sPlugin
)){
$aPluginConfig
=
$CI_plugins
->
getPluginConfig
();
$sHeader
.
=
$CI_plugins
->
getHtmlLoadScript
(
'render.js'
);
$sShellOuptut
.
=
$CI_plugins
->
getHtmlOutwindow
();
$sTopRight
.
=
''
.
'<li >'
.
$oHtml
->
getLink
(
array
(
'href'
=>
'#'
,
// 'onclick'=>'$(\'#'.$CI_plugins->getHtmlOutIdWrapper().'\').slideToggle(100);',
'onclick'
=>
'toggleShellWindow(\''
.
$CI_plugins
->
getHtmlOutIdWrapper
()
.
'\', this);'
,
'role'
=>
'button'
,
'aria-expanded'
=>
'false'
,
'icon'
=>
(
isset
(
$aPluginConfig
[
'icon'
])
?
$aPluginConfig
[
'icon'
]
:
''
),
'label'
=>
$sPlugin
,
))
.
'</li>'
;
}
}
// ----------------------------------------------------------------------
// html body
// ----------------------------------------------------------------------
$sTopArea
=
getTopArea
([
'right'
=>
$sTopRight
]);
$sBanner
=
isset
(
$aConfig
[
'banner'
])
&&
$aConfig
[
'banner'
]
?
'<div class="alert alert-info">'
.
$aConfig
[
'banner'
]
.
'</div>'
:
''
;
$sTopAction
=
getAction
();
...
...
@@ -109,11 +152,18 @@ if ($oUser->hasPermission('page_'.$sAction)){
// return false;
}
// ----------------------------------------------------------------------
// render page
// ----------------------------------------------------------------------
$oCLog
->
add
(
"Finally: rendering page ..."
);
$sPhpOut
=
'
<br>
'
.
$sTopArea
.
'
'
.
$sTopArea
.
$sShellOuptut
.
'
<div id="content">
'
.
$sBanner
.
$sTopAction
.
'
'
.
$sPhpOut
.
'
...
...
@@ -122,11 +172,8 @@ $sPhpOut = '
'
.
t
(
"menu-brand"
)
.
' © 2013-'
.
date
(
"Y"
)
.
' <a href="https://git-repo.iml.unibe.ch/iml-open-source/imldeployment/" target="_blank">Institut für Medizinische Lehre; Universität Bern</a>
</div>
<!--
<script src="/deployment/plugins/shellcmd/load/render.js" />
-->
'
.
$oCLog
->
render
();
'
.
$oCLog
->
render
();
$oPage
=
new
Page
();
$oPage
->
addResponseHeader
(
"Pragma: no-cache"
);
...
...
public_html/deployment/js/addi.js
0 → 100644
View file @
4011ff8d
/**
*
* ADDI = Axels Drag and drop implementation
*
* create draggable divs on screen if they have a defined class
* (named "draggable" by default - but you can use any other name)
*
* @author Axel Hahn
* @version 1.0
*
* @this addi
*
* @example
* <pre>
* // make all divs with class "draggable" be movable on screen<br>
* addi.init();
* </pre>
*
* @constructor
* @return nothing
*/
var
addi
=
function
(){
return
{
_saveData
:
[],
_dragClass
:
'
draggable
'
,
_draggingClass
:
'
isdragging
'
,
// last z-index value of last activated div
_addi_zIndex
:
100
,
// fixed rectangle earea whe a div can be moved
oFence
:
{
bFullscreen
:
true
,
top
:
0
,
left
:
0
,
width
:
window
.
innerWidth
,
height
:
window
.
innerHeight
},
// override existing style values while moving the div
_savstyles
:{
transition
:
'
auto
'
},
/**
* detect all draggable objects on a page and init each
*
* @see initDiv()
* @param {string} sClass optional: class of draggable elements; default: "draggable"
* @returns {undefined}
*/
init
(
sClass
){
if
(
sClass
){
this
.
_dragClass
=
sClass
;
}
// scan all elements with class draggable and make them movable
var
oList
=
document
.
getElementsByClassName
(
this
.
_dragClass
);
if
(
oList
&&
oList
.
length
){
for
(
var
i
=
0
;
i
<
oList
.
length
;
i
++
)
{
this
.
initDiv
(
oList
[
i
],
false
);
}
}
},
// ------------------------------------------------------------
// private functions
// ------------------------------------------------------------
/**
* get a top left position {xpos, ypos} to fix current position and
* make a div fully visible
* @see move()
*
* @private