source: trunk/FACT++/www/smartfact/index.php@ 14098

Last change on this file since 14098 was 13891, checked in by tbretz, 12 years ago
Add scripts/ to path of dimscript
File size: 3.6 KB
Line 
1<?PHP
2
3require_once("config.php");
4
5function login()
6{
7 global $ldaphost;
8 global $baseDN;
9 global $groupDN;
10
11 $username = $_SERVER['PHP_AUTH_USER'];
12 $password = $_SERVER['PHP_AUTH_PW'];
13
14 $con = @ldap_connect($ldaphost);
15 if (!$con)
16 return "ldap_connect failed to ".$ldaphost;
17
18 //------------------ Look for user common name
19 $attributes = array('cn', 'mail');
20 $dn = 'ou=People,'.$baseDN;
21 $filter = '(uid='.$username.')';
22
23 $sr = @ldap_search($con, $dn, $filter, $attributes);
24 if (!$sr)
25 return "ldap_search failed for dn=".$dn.": ".ldap_error($con);
26
27 $srData = @ldap_get_entries($con, $sr);
28 if ($srData["count"]==0)
29 return "No results returned by ldap_get_entries for dn=".$dn.".";
30
31 $email =$srData[0]['mail'][0];
32 $userCommonName=$srData[0]['cn'][0];
33 $userDN =$srData[0]['dn'];
34
35 //------------------ Authenticate user
36 if (!@ldap_bind($con, $userDN, $password))
37 return "ldap_bind failed: ".ldap_error($con);
38
39 //------------------ Check if the user is in FACT ldap group
40 $attributes= array("member");
41 $filter= '(objectClass=*)';
42
43 // Get all members of the group.
44 $sr = @ldap_read($con, $groupDN, $filter, $attributes);
45 if (!$sr)
46 return "ldap_read failed for dn=".$groupDN.": ".ldap_error($con);
47
48 // retrieve the corresponding data
49 $srData = @ldap_get_entries($con, $sr);
50 if ($srData["count"]==0)
51 return "No results returned by ldap_get_entries for dn=".$dn.".";
52
53 @ldap_unbind($con);
54
55 $found = false;
56 foreach ($srData[0]['member'] as $member)
57 if (strpos($member, "cn=".$userCommonName.",")===0)
58 return "";
59
60 return "Sorry, your credentials don't match!";
61}
62// --------------------------------------------------------------------
63
64if (isset($_GET['logout']))
65{
66 if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
67 return;
68
69 return header('HTTP/1.0 401 Successfull logout!');
70}
71
72// --------------------------------------------------------------------
73
74if (!isset($_GET['start']) && !isset($_GET['stop']))
75 return header('HTTP/1.0 400 Command not supported');
76
77// --------------------------------------------------------------------
78
79if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
80{
81 header('WWW-Authenticate: Basic realm="SmartFACT++"');
82 header('HTTP/1.0 401 Unauthorized');
83 return;
84}
85
86$rc = login();
87if ($rc!="")
88 return header('HTTP/1.0 401 '.$rc);
89
90// --------------------------------------------------------------------
91
92$out = array();
93
94if (isset($_GET['stop']))
95 $str = exec($path."/dimctrl --user '".$_SERVER['PHP_AUTH_USER']."' --stop", $out, $rc);
96
97if (isset($_GET['start']))
98{
99 // Filename
100 $args = '"scripts/'.$_GET['start'].'"';
101
102 unset($_GET['start']);
103
104 /*
105 $args = "";
106 foreach ($_GET as $key => $value)
107 $args .= " --arg:".$key."=".$value;
108 $str = exec($path."/dimctrl --exec ".$args, $out, $rc);
109 */
110
111 // Label
112 if (isset($_GET['label']))
113 {
114 if ($_GET['label']>=0)
115 $args .= ":".$_GET['label'];
116 unset($_GET['label']);
117 }
118
119 // Arguments
120 foreach ($_GET as $key => $value)
121 $args .= ' --arg:"'.$key.'='.$value.'"';
122
123 // $args = "filename":label --arg:"key1=value" --arg:"key2=value"
124 $cmd = $path.'/dimctrl --user "'.$_SERVER['PHP_AUTH_USER'].'" --start '.$args;
125
126 // Execute
127 $str = exec($cmd, $out, $rc);
128}
129
130if ($rc!=1 && $rc!=2)
131 return header('HTTP/1.0 500 Execution failed [rc='.$rc."]");
132
133print($rc);
134
135if (isset($_GET['debug']))
136{
137 print("\n");
138 print_r($out);
139}
140
141?>
Note: See TracBrowser for help on using the repository browser.