root/freepbx/branches/experimental/vgps/client_lib.php

Revision 3282, 3.2 kB (checked in by gregmac, 2 years ago)

Import "Voicepulse Global Provisioning System" code v0.1

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Rev Date
Line 
1 <?
2 /*
3 ---------------------------------------------------------------------------
4 VoicePulse Global Provisioning System (VGPS)
5 by Ketan Patel
6 Copyright (C) 2006 VoicePulse Inc.
7
8 This program is free software, distributed under the terms of the GNU General
9 Public License Version 2. See the LICENSE file at the top of the source tree.
10 ---------------------------------------------------------------------------
11 */
12
13         function http_get($url) {
14                 $ch = curl_init();
15                 curl_setopt($ch, CURLOPT_URL, $url);
16                 curl_setopt($ch, CURLOPT_HEADER, 0);
17                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
18                 $result = curl_exec($ch);
19                 curl_close($ch);
20                 return $result;
21         }
22
23         function build_array_cols($http_result) {
24                 $lines = explode("\n", $http_result);
25                 $columns = explode("||", $lines[0]);
26                 $arr = array();
27                 for($i = 1; $i < count($lines); $i++) {
28                         $values = explode("||", $lines[$i]);
29                         if(strlen($lines[$i]) > 0) {
30                                 for($j = 0; $j < count($columns); $j++) {
31                                         $arr[$i][$columns[$j]] = $values[$j];
32                                 }
33                         }
34                 }
35                 return $arr;
36         }
37
38         function build_array($http_result) {
39                 $lines = explode("\n", $http_result);
40                 $arr = array();
41                 for($i = 0; $i < count($lines); $i++) {
42                         if(strlen($lines[$i]) > 0) {
43                                 $columns = explode("||", $lines[$i]);
44                                 $arr[$columns[0]] = $columns[1];
45                         }
46                 }
47                 return $arr;
48         }
49
50         function is_substr($string, $substring) {
51                 $pos = strpos(strtoupper($string), strtoupper($substring));
52                 if($pos === false) {
53                         return false;
54                 } else {
55                         return true;
56                 }
57         }
58
59         function set_device($model, $mac, $location, $note) {
60                 $url = "http://localhost/vgps/execute.php?op=set_device&model=$model&mac=$mac&location=$location&note=$note";
61                 $result = http_get($url);
62                 return $result;
63         }
64
65         function delete_device($mac) {
66                 $url = "http://localhost/vgps/execute.php?op=delete_device&mac=$mac";
67                 $result = http_get($url);
68                 return $result;
69         }
70
71         function set_setting($mac, $key, $value) {
72                 $url = "http://localhost/vgps/execute.php?op=set_setting&mac=$mac&key=$key&value=$value";
73                 $result = http_get($url);
74                 return $result;
75         }
76
77         function delete_setting($mac, $key) {
78                 $url = "http://localhost/vgps/execute.php?op=delete_setting&mac=$mac&key=$key";
79                 $result = http_get($url);
80                 return $result;
81         }
82
83         function regen($mac) {
84                 $url = "http://localhost/vgps/execute.php?op=regen&mac=$mac";
85                 $result = http_get($url);
86                 return $result;
87         }
88
89         function list_devices() {
90                 $url = "http://localhost/vgps/execute.php?op=list_devices";
91                 $result = http_get($url);
92                 $arr = build_array_cols($result);
93                 return $arr;
94         }
95
96         function list_device_settings($mac) {
97                 $url = "http://localhost/vgps/execute.php?op=list_device_settings&mac=$mac";
98                 $result = http_get($url);
99                 $arr = build_array($result);
100                 return $arr;
101         }       
102
103         function list_models() {
104                 $url = "http://localhost/vgps/execute.php?op=list_models";
105                 $result = http_get($url);
106                 $arr = build_array_cols($result);
107                 return $arr;
108         }
109
110         function list_generic_settings() {
111                 $url = "http://localhost/vgps/execute.php?op=list_generic_settings";
112                 $result = http_get($url);
113                 $arr = build_array_cols($result);
114                 return $arr;
115         }       
116 ?>
Note: See TracBrowser for help on using the browser.
Donate



Support
Download
Develop
Forums
News
Documentation
Paid Support
About

Paid Ads