-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsftk.php
169 lines (162 loc) · 6.29 KB
/
sftk.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
//*** tokens control ***
//
$dev='ppthtml2';
if (gethostname()==$dev) {
define("PATH_AZURE_PHP", "pear/WindowsAzure/");
//define("PATH_AZURE_PHP", "services/azure-sdk-for-php/");
} else {
//define("PATH_AZURE_PHP", "pear/WindowsAzure/");
define("PATH_AZURE_PHP", "services/azure-sdk-for-php/WindowsAzure/");
}
//require_once PATH_AZURE_PHP."WindowsAzure/WindowsAzure.php";
require_once PATH_AZURE_PHP."WindowsAzure.php";
//require_once "WindowsAzure/WindowsAzure.php";
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\Table\Models\Entity;
use WindowsAzure\Table\Models\EdmType;
/*
$name='sfclmstorage';
$key='JtyoTzjNZHBAWVuDQNpN3LaJcPWjc51bMvRT7xG4hZA7vpT6qZTjKoJUU6z8sY2+zsvsGe7j05OupWmumABz5A==';
//$UseDevelopmentStorage=true
$connectionString = "DefaultEndpointsProtocol=http;AccountName=$name;AccountKey=$key";
echo "Start azure";
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
//$filter = "org_id eq '00D20000000Caz4EAC'";
$filter = "token eq '88e3a10944d71ac5fe8739ed'";
try {
$result = $tableRestProxy->queryEntities("sftokens", $filter);
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
$entities = $result->getEntities();
var_dump($entities);
foreach($entities as $entity){
echo $entity->getPartitionKey().":".$entity->getRowKey()."<br />";
}
*/
//-------------------------Azure storage class------------------------------------
class AzureStore {
var $state;
var $az_table_proxy;
var $az_table_slide_tokens;
var $az_table_org_tokens;
var $az_table_name;
var $org_id='';
var $app_id='';
function __construct() {
$name='sfclmstorage';
$key='JtyoTzjNZHBAWVuDQNpN3LaJcPWjc51bMvRT7xG4hZA7vpT6qZTjKoJUU6z8sY2+zsvsGe7j05OupWmumABz5A==';
$connectionString = "DefaultEndpointsProtocol=http;AccountName=$name;AccountKey=$key";
$this->az_table_slide_tokens="sftokens";
$this->az_table_org_tokens ="orgtokens";
try {
$this->az_table_proxy = ServicesBuilder::getInstance()->createTableService($connectionString);
$this->state.=';conected';
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
$this->state.=';error-conection';
error_log(__FUNCTION__.' '.$this->state." ".$code.$error_message);
}
}
function addOrgToken($org_id) {
$entity = new Entity();
$entity->setPartitionKey($org_id);
$entity->setRowKey($org_id);
$cur_token=uniqid('',true);
$entity->addProperty("token", null, $cur_token);
//$entity->addProperty("DueDate",EdmType::DATETIME,new DateTime("2012-11-05T08:15:00-08:00"));
try {
$this->az_table_proxy->insertEntity($this->az_table_org_tokens, $entity);
return $cur_token;
} catch (ServiceException $e) {
error_log(__FUNCTION__.' '. $e->getCode().' '.$e->getMessage());
return 0;
}
}
function addSlideToken($org_id,$app_id) {
$entity = new Entity();
$entity->setPartitionKey($org_id);
$entity->setRowKey($app_id);
$cur_token=uniqid('',true);
$entity->addProperty("token", null, $cur_token);
//$entity->addProperty("DueDate",EdmType::DATETIME,new DateTime("2012-11-05T08:15:00-08:00"));
try {
$this->az_table_proxy->insertEntity($this->az_table_slide_tokens, $entity);
return $cur_token;
} catch (ServiceException $e) {
error_log(__FUNCTION__.' '. $e->getCode().' '.$e->getMessage());
return 0;
}
}
function getOrgToken($org_id) {
$filter = "PartitionKey eq '$org_id'";
$cur_token='0';
try {
$result = $this->az_table_proxy->queryEntities($this->az_table_org_tokens, $filter);
$entities = $result->getEntities();
$cur_token=$entities[0]->getProperty("token")->getValue();
} catch(ServiceException $e){
$cur_token ='-1';
error_log(__FUNCTION__.' '. $e->getCode().' '.$e->getMessage());
}
return $cur_token;
}
function getSlideToken($org_id,$app_id) {
$filter = "PartitionKey eq '$org_id' and RowKey eq '$app_id'";
$cur_token='0';
try {
$result = $this->az_table_proxy->queryEntities($this->az_table_slide_tokens, $filter);
$entities = $result->getEntities();
$cur_token=$entities[0]->getProperty("token")->getValue();
} catch(ServiceException $e){
$cur_token ='-1';
error_log(__FUNCTION__.' '. $e->getCode().' '.$e->getMessage());
}
return $cur_token;
}
function findSlideByToken($tk) {
$filter = "token eq '$tk'";
try {
//echo "findByKey <br>filter=$filter";
$result = $this->az_table_proxy->queryEntities($this->az_table_slide_tokens, $filter);
$entities = $result->getEntities();
//var_dump($entities);
$this->state.=';table-conected';
if (count($entities) >=1 ) {
$this->org_id=$entities[0]->getPartitionKey();//$entities[0]->getProperty("token")->getValue();
$this->app_id=$entities[0]->getRowKey();
return true;
} else return false;
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
$this->state.='error-conection-table';
error_log(__FUNCTION__.' '.$this->state." ".$code.$error_message);
return false;
}
}
function findSlideByOrgApp($org_id,$app_id) {
$filter = "PartitionKey eq '$org_id' and RowKey eq '$app_id'";
try {
$result = $this->az_table_proxy->queryEntities($this->az_table_slide_tokens, $filter);
$entities = $result->getEntities();
if (count($entities)>=1){
$this->org_id=$org_id;
$this->app_id=$app_id;
}
return true;
} catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
$this->state.='error-conection-table-by-org-app';
error_log(__FUNCTION__.' '.$this->state." ".$code.$error_message);
return false;
}
}
}
?>