changed git call from https to git readonly
[atutor.git] / mods / adobe_connect / lib / ACUser.php
1 <?php
2
3 require_once('lib/ACConnection.php');
4
5 class ACUser extends ACConnection {
6
7
8     public function getUserSession($username) {
9
10         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
11         if (!$fp) {
12             return false;
13         }
14   
15         $url = '/api/xml?action=login&external-auth=use';
16
17         fputs($fp, "GET ".$url." HTTP/1.0\r\n".$this->adobe_connect_adminpass.":".$username."\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
18
19         while($line = fgets($fp)) {
20
21             if (preg_match('/BREEZESESSION=(.*)\;/', $line, $result)) {
22                 $session = explode(';', $result[1]);
23                 $sessionid = $session[0];
24                 break;
25             }
26
27         }
28         fclose($fp);
29
30         if (empty($sessionid)) {
31             return false;
32         }
33
34         return $sessionid;
35     }
36
37
38     public function createUser($sessionid, $username, $fname, $lname) {
39
40         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
41         if (!$fp) {
42             return false;
43         }
44
45         if ($this->checkUser($sessionid, $username)) {
46             return false;
47         }
48   
49         if ($fname == '' OR $fname == false OR $fname == ' ') { return false;}
50         if ($lname == '' OR $lname == false OR $lname == ' ') { return false;}
51         if ($username == '' OR $username == false OR $username == ' ') { return false;}
52         if (strlen($fname) > 40) { return false;}
53         if (strlen($lname) > 40) { return false;}
54         if (strlen($username) > 40) { return false;}
55         $username = trim($username);
56
57         $url = "/api/xml?action=principal-update&login=$username&first-name=$fname&has-children=0&last-name=$lname&type=user&session=$sessionid";
58         fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
59
60         while($line = fgets($fp)) {
61             if (preg_match('/\ principal-id=\"([0-9]*)\"/', $line, $result)) {
62                 $principalid = $result[1];
63             }
64         }
65         fclose($fp);
66
67         if (empty($principalid)) {
68             return false;
69         }
70
71         return true;
72     }
73
74
75     public function deleteUser($sessionid, $username) {
76
77         if (!$principalid = $this->checkUser($sessionid, $username)) { 
78             return false;
79         } else {
80
81             $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
82             if (!$fp) {
83                 return false;
84             }
85
86             $url = "/api/xml?action=principals-delete&principal-id=$principalid&session=$sessionid";
87             fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
88
89             $response = $this->checkResponse($fp, __FUNCTION__);
90             fclose($fp);
91             return $response;
92         }
93     }
94
95
96     public function checkUser($sessionid, $username) {
97   
98         $fp = @fsockopen($this->adobe_connect_host, $this->adobe_connect_port);
99         if (!$fp) {
100             return false;
101         }
102
103         $url = "/api/xml?action=principal-list&filter-login=$username&session=$sessionid";
104         fputs($fp, "GET ".$url." HTTP/1.0\r\nHost: ".$this->adobe_connect_host."\r\n\r\n");
105
106         while($line = fgets($fp)) {
107
108             if (preg_match('/\ principal-id=\"([0-9]*)\"/', $line, $result)) {
109                 $principalid = $result[1];
110             }
111
112         }
113         fclose($fp);
114
115         if (empty($principalid)) {
116             return false;
117         }
118
119         return $principalid;
120     }
121
122 }
123
124 ?>