FusionDirectory
class_simpleService.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2011-2019 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
26 {
27  protected static $showActions = TRUE;
28 
29  protected $status = '';
30 
31  public $conflicts = [];
32  public $DisplayName = '';
33 
41  function __construct ($dn = NULL, $parent = NULL, $attributesInfo = NULL)
42  {
43  /* $parent is the instance of servicesManagement in this case, we set it as parent */
44  parent::__construct($dn, $parent, $parent, FALSE, $attributesInfo);
45 
46  /* Services do not have the activation header, but can still be disabled */
47  $this->ignore_account = FALSE;
48 
49  $plInfos = pluglist::pluginInfos(get_class($this));
50  $this->DisplayName = $plInfos['plShortName'];
51  }
52 
55  public function render (): string
56  {
57  $str = parent::render();
58 
59  if (!$this->dialog) {
60  $str .= '<p class="plugbottom servicebottom">'.
61  ' <input type="submit" name="SaveService" value="'.msgPool::saveButton().'"/>&nbsp;'.
62  ' <input type="submit" formnovalidate="formnovalidate" name="CancelService" value="'.msgPool::cancelButton().'"/>'.
63  '</div>';
64  }
65 
66  return $str;
67  }
68 
69  protected function acl_skip_write (): bool
70  {
71  return FALSE;
72  }
73 
75  function getListEntry ()
76  {
77  /* Assign status flag */
78  $fields['Status'] = $this->status;
79 
80  /* Name displayed in service overview */
81  $fields['Message'] = $this->DisplayName;
82 
83  if (static::$showActions && is_object($this->parent->parent) && isset($this->parent->parent->by_object['argonautClient']) && $this->parent->parent->by_object['argonautClient']->is_account) {
84  /* Allow/disallow some functions */
85  $fields['AllowStatus'] = ($this->status == '') && $this->acl_is_writeable('simpleServiceStatus');
86  $fields['AllowStart'] = ($this->status == 'stopped') && $this->acl_is_writeable('simpleServiceStart');
87  $fields['AllowStop'] = ($this->status == 'running') && $this->acl_is_writeable('simpleServiceStop');
88  $fields['AllowRestart'] = ($this->status == 'running') && $this->acl_is_writeable('simpleServiceRestart');
89  } else {
90  /* Disable some functions */
91  $fields['AllowStatus'] = FALSE;
92  $fields['AllowStart'] = FALSE;
93  $fields['AllowStop'] = FALSE;
94  $fields['AllowRestart'] = FALSE;
95  }
96 
97  $fields['AllowRemove'] = $this->acl_is_removeable();
98  $fields['AllowEdit'] = $this->acl_is_readable('');
99 
100  return $fields;
101  }
102 
104  function setStatus ($value)
105  {
106  /* Can't set status flag for new services (Object doesn't exists in ldap tree) */
107  if (!$this->initially_was_account) {
108  return;
109  }
110 
111  $this->status = $value;
112  }
113 
114  static function generatePlProvidedAcls (array $attributesInfo, bool $operationalAttributes = NULL): array
115  {
116  $acls = parent::generatePlProvidedAcls($attributesInfo);
117  if (static::$showActions) {
118  $acls ['simpleServiceStatus'] = _('Get service status');
119  $acls ['simpleServiceStart'] = _('Start service');
120  $acls ['simpleServiceStop'] = _('Stop service');
121  $acls ['simpleServiceRestart'] = _('Restart service');
122  }
123 
124  return $acls;
125  }
126 }
$parent
Reference to parent object.
This class is made for easy plugin creation for editing LDAP attributes.
__construct($dn=NULL, $parent=NULL, $attributesInfo=NULL)
constructor
acl_is_readable($attribute)
Can we read the acl.
$dn
dn of the opened object
acl_is_writeable($attribute, bool $skipWrite=FALSE)
Can we write the attribute.
getListEntry()
Get service information for servicesManagement plugin.
This class is made for easy service creation for editing LDAP attributes.
acl_is_removeable(string $base=NULL)
Can we delete the object.
render()
This function display the service and return the html code.
$attributesInfo
This attribute store all information about attributes.
setStatus($value)
This function save new status flag.