1 <?php
3 class goLdapServer extends goService{
5 var $cli_summary = "This plugin is used within the ServerService Pluign \nand indicates that this server has goLdapServer defined.";
6 var $cli_description = "Some longer text\nfor help";
7 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* This plugin only writes its objectClass */
10 var $objectclasses = array("goLdapServer");
11 var $attributes = array("goLdapBase");
12 var $StatusFlag = "goLdapServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goLdapServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $cn = "";
20 var $goLdapServerStatus = "";
21 var $goLdapBase = "";
22 var $oldBase = "";
23 var $view_logged =FALSE;
25 var $krb_service_prefix = "ldap/";
27 function goLdapServer(&$config,$dn)
28 {
29 goService::goService($config,$dn);
30 $this->DisplayName = _("LDAP service");
32 /* Suggest a default value */
33 if ($this->goLdapBase == ""){
34 if ($this->dn == ""){
35 $srv= _("enter your servers DNS name");
36 } else {
37 $srv= preg_replace("/^cn=([^,]+),.*$/", "$1", $this->dn);
38 }
39 $this->goLdapBase= "ldap://$srv:389/".$config->current['BASE'];
40 }
41 $this->oldBase = $this->goLdapBase;
42 }
45 function execute()
46 {
48 if($this->is_account && !$this->view_logged){
49 $this->view_logged = TRUE;
50 new log("view","server/".get_class($this),$this->dn);
51 }
53 $smarty = get_smarty();
54 foreach($this->attributes as $attr){
55 $smarty->assign($attr, set_post($this->$attr));
56 }
57 $tmp = $this->plInfo();
58 foreach($tmp['plProvidedAcls'] as $name => $translated){
59 $smarty->assign($name."ACL",$this->getacl($name));
60 }
61 return($smarty->fetch(get_template_path("goLdapServer.tpl",TRUE,dirname(__FILE__))));
62 }
65 function getListEntry()
66 {
67 $fields = goService::getListEntry();
68 $fields['Message'] = _("LDAP service");
69 return($fields);
70 }
74 function check()
75 {
76 $message = plugin::check();
77 if(empty($this->goLdapBase)){
78 $message[] = msgPool::required(_("LDAP URI"));
79 }
80 if(!preg_match("/^ldap[si]?:\/\/[0-9a-z_.-]{1,}+(:[0-9]+)?\/.+$/i", $this->goLdapBase)){
81 $message[] = msgPool::invalid(_("LDAP URI"),"","","(ldap|ldaps|ldapi)://"._("Server")."(:"._("Port").")/"._("Base"));
82 }
83 return($message);
84 }
87 function save_object()
88 {
89 if(isset($_POST['goLdapServerPosted'])){
90 plugin::save_object();
91 }
92 }
95 function save()
96 {
97 goService::save();
99 /* Update object relation */
100 if(!empty($this->oldBase) && $this->oldBase != $this->goLdapBase){
101 $new = array();
102 $ldap = $this->config->get_ldap_link();
103 $ldap->cd($this->config->current['BASE']);
104 $ldap->search('(&(objectClass=GOhard)(gotoLdapServer=*'.$this->oldBase.'))',array("cn","gotoLdapServer"));
105 while($attrs = $ldap->fetch()){
106 $ldapServer = array();
107 for($i = 0 ; $i < $attrs['gotoLdapServer']['count'] ; $i ++ ){
108 $ldapServer[] = preg_replace("/".preg_quote($this->oldBase, '/')."/",$this->goLdapBase,$attrs['gotoLdapServer'][$i]);
109 }
110 $new[$attrs['dn']]['gotoLdapServer'] = $ldapServer;
111 }
112 foreach($new as $dn => $data){
113 $ldap->cd($dn);
114 $ldap->modify($data);
115 if(!$ldap->success()){
116 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
117 }
118 }
119 }
120 }
123 /* Return plugin informations for acl handling */
124 static function plInfo()
125 {
126 return (array(
127 "plShortName" => _("LDAP"),
128 "plDescription" => _("LDAP service").")",
129 "plSelfModify" => FALSE,
130 "plDepends" => array(),
131 "plPriority" => 96,
132 "plSection" => array("administration"),
133 "plCategory" => array("server"),
134 "plRequirements"=> array(
135 'ldapSchema' => array('goLdapServer' => '>=2.7'),
136 'onFailureDisablePlugin' => array(get_class())
137 ),
139 "plProvidedAcls"=> array(
140 "start" => _("Start"),
141 "stop" => _("Stop"),
142 "restart" => _("Restart"),
143 "goLdapBase" => _("LDAP base"))
144 ));
145 }
146 }
147 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
148 ?>