~fkhan-zivios/zivios/devel

« back to all changes in this revision

Viewing changes to application/modules/default/models/EMSSudoItem.php

  • Committer: Faraz Khan
  • Date: 2008-09-15 13:29:33 UTC
  • Revision ID: fkhan@zivios.org-20080915132933-d27jml5l29xw4gsr
Initial release to bazaar, code in sync with 0.5.0-release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Copyright (c) 2008 Zivios, LLC.
 
4
 *
 
5
 * This file is part of Zivios.
 
6
 *
 
7
 * Zivios 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 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * Zivios 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 Zivios.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 * @package             mod_default
 
21
 * @copyright   Copyright (c) 2008 Zivios, LLC. (http://www.zivios.org)
 
22
 * @license             http://www.zivios.org/legal/license
 
23
 * @version             $Id: EMSSudoItem.php 911 2008-08-25 11:06:13Z fkhan $
 
24
 **/
 
25
 
 
26
class EMSSudoItem extends EMSSecurityObject
 
27
{
 
28
        private $serviceclass,$computer,$userarray,$grouparray;
 
29
        public function __construct(Ecl_LdapObject $lobj)
 
30
        {
 
31
                parent::__construct($lobj);
 
32
                $param = $this->addParameter('cn','SudoItemName',1);
 
33
 
 
34
                $this->addParameter('sudocommand','Sudo Command',1);
 
35
                $this->addParameter('sudohost','Sudo Host',1);
 
36
                $this->addParameter('sudouser','Sudo User',1);
 
37
                $this->addParameter('emsplugins','Ems Plugin attached',1);
 
38
 
 
39
 
 
40
 
 
41
        }
 
42
        public function setHost(EMSComputer $computer)
 
43
        {
 
44
                $this->setProperty('sudohost',$computer->getProperty('cn'));
 
45
 
 
46
        }
 
47
 
 
48
        public function linkToService(Ecl_Service_Plugin $servplug)
 
49
        {
 
50
                $this->setProperty('emsplugins',get_class($servplug));
 
51
                $this->setProperty('sudocommand',$servplug->getAdminCommandArray());
 
52
 
 
53
        }
 
54
 
 
55
        public function addUser(EMSUser $user,Ecl_Transaction_Handler $handler=null)
 
56
        {
 
57
                $userparm = $this->getParameter('sudouser');
 
58
                $userparm->addValue($user->getProperty('uid'));
 
59
        }
 
60
 
 
61
        public function addGroup(EMSGroup $group,Ecl_Transaction_Handler $handler=null)
 
62
        {
 
63
                $groupparm = $this->getProperty('sudouser');
 
64
                $groupparm->addValue('%'.$group->getProperty('cn'));
 
65
                return parent::update($handler);
 
66
        }
 
67
 
 
68
        public function removeUser(EMSUser $user)
 
69
        {
 
70
                $userparm = $this->getParameter("sudouser");
 
71
                $userparm->removeValue($user->getProperty('uid'));
 
72
        }
 
73
 
 
74
        public function removeGroup(EMSGroup $group)
 
75
        {
 
76
        }
 
77
 
 
78
        public function makeDn($parent)
 
79
        {
 
80
                $class = $this->getProperty('emsplugins');
 
81
                $host = $this->getProperty('sudohost');
 
82
                $parentdn = $parent->getdn();
 
83
                $dn = $this->getrdn()."=".$class."__".$host.",".$parent->getdn();
 
84
                Ecl_Log::debug("Making DN for sudo item returned $dn");
 
85
                return $dn;
 
86
        }
 
87
 
 
88
        public function getrdn()
 
89
        {
 
90
                return 'cn';
 
91
        }
 
92
 
 
93
 
 
94
 
 
95
        public function add(EMSObject $parent,Ecl_Transaction_Handler $handler=null)
 
96
        {
 
97
                if ($handler == null) {
 
98
                        $handler = $this->getTransaction();
 
99
                }
 
100
                if (get_class($this) == 'EMSSudoItem') {
 
101
                        $class = $this->getProperty('emsplugins');
 
102
                        $host = $this->getProperty('sudohost');
 
103
                        $cn = $class."__".$host;
 
104
                        $this->setProperty('cn',$cn);
 
105
            $this->addObjectClass('emssudoitem');
 
106
            $this->addObjectClass('sudorole');
 
107
            $this->addObjectClass('emsignore');
 
108
 
 
109
                }
 
110
 
 
111
                if ($this->getProperty('emsdescription') == null) {
 
112
                        $this->setProperty('emsdescription','Sudo Entry');
 
113
                }
 
114
 
 
115
                $this->setProperty('emstype',self::TYPE_SUDOI);
 
116
                return parent::add($parent,$handler);
 
117
 
 
118
        }
 
119
}