Odyssey
cu_remote_top.prg
1 <?php
2  /*
3  *** This will include functions for managing the information for
4  calling the remote scripts
5  */
6 
7 
8  /* VALUE
9  Remote_Servers -- Array of the available remote server to update
10  Array values
11  IP -- this is the IP address of the remote server
12  host -- this is the host name, to help identify which machine we are on
13  upd -- This is a default setting when true the server is included by default, when false the server is excluded by default
14  http_login -- This is set to true when the browser needs to pass along the http user and pwd information for the hcuadm folder
15  */
16 
17  // * DETERMINE IF THIS IS THE www4 DEVELOPMENT HOST
18  $production_update = true;
19  $home_host = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], "."));
20 
21  // ** Default Remote_Results
22  $Remote_Results = '';
23 
24  $production_update = $prodStack;
25 
26  $Remote_Servers["www5"]["IP"] = "www5.homecu.net";
27  $Remote_Servers["www5"]["host"] = "www5.homecu.net";
28  $Remote_Servers["www5"]["upd"] = $production_update;
29  $Remote_Servers["www5"]["http_login"] = true;
30 
31  $Remote_Servers["www6"]["IP"] = "www6.homecu.net";
32  $Remote_Servers["www6"]["host"] = "www6.homecu.net";
33  $Remote_Servers["www6"]["upd"] = $production_update;
34  $Remote_Servers["www6"]["http_login"] = true;
35 
36  $Remote_Servers["www3"]["IP"] = "www3.homecu.net";
37  $Remote_Servers["www3"]["host"] = "www3.homecu.net";
38  $Remote_Servers["www3"]["upd"] = $production_update;
39  $Remote_Servers["www3"]["http_login"] = true;
40 
41  $Remote_Servers["www4"]["IP"] = "www4.homecu.net";
42  $Remote_Servers["www4"]["host"] = "www4.homecu.net";
43  $Remote_Servers["www4"]["upd"] = false;
44  $Remote_Servers["www4"]["http_login"] = true;
45 
46  $Remote_Servers["ivr"]["IP"] = "ivr.homecu.net";
47  $Remote_Servers["ivr"]["host"] = "ivr.homecu.net";
48  $Remote_Servers["ivr"]["upd"] = false;
49  $Remote_Servers["ivr"]["http_login"] = true;
50 
51  // ** By default do NOT update the www site.
52  $Remote_Servers["www"]["IP"] = "www.homecu.net";
53  $Remote_Servers["www"]["host"] = "www.homecu.net";
54  $Remote_Servers["www"]["upd"] = $production_update;
55  $Remote_Servers["www"]["http_login"] = true;
56 
57  // ** Predefined Allowed Tables for Updating
58  /* Allowed_Tables Array
59  Array of fields for each of the tables that may be updated
60  Array Values for each field in a table
61 
62  name -- Name of the field in the database
63  dt -- datatype of the field
64  len -- length of the field
65  key -- Is this field part of the key
66  */
67 
68  // ** VENDOR TABLE (cuvendors)
69  $Allowed_Tables['cuvndr']['tablename'] = 'cuvendors';
70  $Allowed_Tables['cuvndr']['vendcode'] = array("name"=>"vendor", "dt"=>"C", "len"=>15, "key"=>1);
71  $Allowed_Tables['cuvndr']['venddesc'] = array("name"=>"venddesc", "dt"=>"C", "len"=>30, "key"=>0);
72  $Allowed_Tables['cuvndr']['vendvar'] = array("name"=>"vendvar", "dt"=>"C", "len"=>30, "key"=>0);
73  $Allowed_Tables['cuvndr']['addr1'] = array("name"=>"addr1", "dt"=>"C", "len"=>40, "key"=>0);
74  $Allowed_Tables['cuvndr']['addr2'] = array("name"=>"addr2", "dt"=>"C", "len"=>40, "key"=>0);
75  $Allowed_Tables['cuvndr']['city'] = array("name"=>"city", "dt"=>"C", "len"=>25, "key"=>0);
76  $Allowed_Tables['cuvndr']['st'] = array("name"=>"st", "dt"=>"C", "len"=>15, "key"=>0);
77  $Allowed_Tables['cuvndr']['zip'] = array("name"=>"zip", "dt"=>"C", "len"=>15, "key"=>0);
78  $Allowed_Tables['cuvndr']['phone'] = array("name"=>"phone", "dt"=>"C", "len"=>20, "key"=>0);
79  $Allowed_Tables['cuvndr']['fax'] = array("name"=>"fax", "dt"=>"C", "len"=>20, "key"=>0);
80  $Allowed_Tables['cuvndr']['email'] = array("name"=>"email", "dt"=>"C", "len"=>40, "key"=>0);
81  $Allowed_Tables['cuvndr']['contact'] = array("name"=>"contact", "dt"=>"C", "len"=>40, "key"=>0);
82  $Allowed_Tables['cuvndr']['comments'] = array("name"=>"comments", "dt"=>"C", "len"=>400, "key"=>0);
83 
84 
85  // ** TRANSACTION CODE TABLE (cutrans)
86  $Allowed_Tables['cutrn']['tablename'] = 'cutrans';
87  $Allowed_Tables['cutrn']['trancode'] = array("name"=>"trancode", "dt"=>"C", "len"=>2, "key"=>1);
88  $Allowed_Tables['cutrn']['trandesc'] = array("name"=>"trandesc", "dt"=>"C", "len"=>40, "key"=>0);
89  $Allowed_Tables['cutrn']['transpec'] = array("name"=>"specialproc", "dt"=>"N", "len"=>0, "key"=>0);
90 
91  // ** ADMIN PROGRAMS TABLE (cuadminprogs)
92  $Allowed_Tables['cuprg']['tablename'] = 'cuadminprogs';
93  $Allowed_Tables['cuprg']['program'] = array("name"=>"program", "dt"=>"C", "len"=>20, "key"=>1);
94  $Allowed_Tables['cuprg']['displaytext'] = array("name"=>"displaytext", "dt"=>"C", "len"=>30, "key"=>0);
95  $Allowed_Tables['cuprg']['sort_order'] = array("name"=>"sort_order", "dt"=>"N", "len"=>0, "key"=>0);
96  $Allowed_Tables['cuprg']['description'] = array("name"=>"description", "dt"=>"C", "len"=>255, "key"=>0);
97  $Allowed_Tables['cuprg']['def_set'] = array("name"=>"def_set", "dt"=>"C", "len"=>1, "key"=>0);
98 
99  // ** EXCLUDE LIST SPECIAL PROCESS
100  // $Allowed_Tables['excludelist']['tablename'] = 'cuadminprogs';
101  $Allowed_Tables['excludelist']['program'] = array("name"=>"program", "dt"=>"C", "len"=>20, "key"=>0);
102 
103  // ** ISSUES MAINTENANCE TABLE (cuissues)
104  $Allowed_Tables['cuiss']['tablename'] = 'cuissues';
105  $Allowed_Tables['cuiss']['iss_id'] = array("name"=>"issue_id", "dt"=>"N", "len"=>0, "key"=>1);
106  $Allowed_Tables['cuiss']['iss_code'] = array("name"=>"code", "dt"=>"C", "len"=>20, "key"=>0);
107  $Allowed_Tables['cuiss']['iss_prod'] = array("name"=>"gen_for_product", "dt"=>"C", "len"=>10, "key"=>0);
108 
109  // ** ISSUES MAINTENANCE DETAIL TABLE (cuissuesitem)
110  $Allowed_Tables['cuissitm']['tablename'] = 'cuissuesitem';
111  $Allowed_Tables['cuissitm']['itm_id'] = array("name"=>"item_id", "dt"=>"N", "len"=>0, "key"=>1);
112  $Allowed_Tables['cuissitm']['iss_id'] = array("name"=>"issue_id", "dt"=>"N", "len"=>0, "key"=>0);
113  $Allowed_Tables['cuissitm']['itm_title'] = array("name"=>"title", "dt"=>"C", "len"=>80, "key"=>0);
114  $Allowed_Tables['cuissitm']['itm_desc'] = array("name"=>"item_desc", "dt"=>"C", "len"=>500, "key"=>0);
115 
116  // ** ADMIN MESSAGES TABLE (cuadmin_message)
117  $Allowed_Tables['cuadmmsg']['tablename'] = 'cuadmin_message';
118  $Allowed_Tables['cuadmmsg']['msg_id'] = array("name"=>"id", "dt"=>"N", "len"=>0, "key"=>1);
119  $Allowed_Tables['cuadmmsg']['active_date'] = array("name"=>"active_date", "dt"=>"D", "len"=>0, "key"=>0);
120  $Allowed_Tables['cuadmmsg']['expires_on'] = array("name"=>"expires_on", "dt"=>"D", "len"=>0, "key"=>0);
121  $Allowed_Tables['cuadmmsg']['message'] = array("name"=>"message", "dt"=>"C", "len"=>1000, "key"=>0);
122  $Allowed_Tables['cuadmmsg']['subject'] = array("name"=>"subject", "dt"=>"C", "len"=>50, "key"=>0);
123  $Allowed_Tables['cuadmmsg']['livebatch'] = array("name"=>"livebatch", "dt"=>"C", "len"=>1, "key"=>0);
124 
125  // ** IMAGE VENDORS TABLE (cuimagevendors)
126  $Allowed_Tables['cuimgvnd']['tablename'] = 'cuimagevendors';
127  $Allowed_Tables['cuimgvnd']['imgcode'] = array("name"=>"img", "dt"=>"C", "len"=>10, "key"=>1);
128  $Allowed_Tables['cuimgvnd']['imgdesc'] = array("name"=>"imgdesc", "dt"=>"C", "len"=>30, "key"=>0);
129  $Allowed_Tables['cuimgvnd']['imgaddr1'] = array("name"=>"addr1", "dt"=>"C", "len"=>40, "key"=>0);
130  $Allowed_Tables['cuimgvnd']['imgaddr2'] = array("name"=>"addr2", "dt"=>"C", "len"=>40, "key"=>0);
131  $Allowed_Tables['cuimgvnd']['imgcity'] = array("name"=>"city", "dt"=>"C", "len"=>25, "key"=>0);
132  $Allowed_Tables['cuimgvnd']['imgst'] = array("name"=>"st", "dt"=>"C", "len"=>2, "key"=>0);
133  $Allowed_Tables['cuimgvnd']['imgzip'] = array("name"=>"zip", "dt"=>"C", "len"=>10, "key"=>0);
134  $Allowed_Tables['cuimgvnd']['imgcnt1'] = array("name"=>"contact1", "dt"=>"C", "len"=>40, "key"=>0);
135  $Allowed_Tables['cuimgvnd']['imgrol1'] = array("name"=>"role1", "dt"=>"C", "len"=>40, "key"=>0);
136  $Allowed_Tables['cuimgvnd']['imgphn1'] = array("name"=>"phone1", "dt"=>"C", "len"=>20, "key"=>0);
137  $Allowed_Tables['cuimgvnd']['imgem1'] = array("name"=>"email1", "dt"=>"C", "len"=>50, "key"=>0);
138  $Allowed_Tables['cuimgvnd']['imgfx1'] = array("name"=>"fax1", "dt"=>"C", "len"=>20, "key"=>0);
139  $Allowed_Tables['cuimgvnd']['imgcnt2'] = array("name"=>"contact2", "dt"=>"C", "len"=>40, "key"=>0);
140  $Allowed_Tables['cuimgvnd']['imgrol2'] = array("name"=>"role2", "dt"=>"C", "len"=>40, "key"=>0);
141  $Allowed_Tables['cuimgvnd']['imgphn2'] = array("name"=>"phone2", "dt"=>"C", "len"=>20, "key"=>0);
142  $Allowed_Tables['cuimgvnd']['imgem2'] = array("name"=>"email2", "dt"=>"C", "len"=>50, "key"=>0);
143  $Allowed_Tables['cuimgvnd']['imgfx2'] = array("name"=>"fax2", "dt"=>"C", "len"=>20, "key"=>0);
144  $Allowed_Tables['cuimgvnd']['imgcnt3'] = array("name"=>"contact3", "dt"=>"C", "len"=>40, "key"=>0);
145  $Allowed_Tables['cuimgvnd']['imgrol3'] = array("name"=>"role3", "dt"=>"C", "len"=>40, "key"=>0);
146  $Allowed_Tables['cuimgvnd']['imgphn3'] = array("name"=>"phone3", "dt"=>"C", "len"=>20, "key"=>0);
147  $Allowed_Tables['cuimgvnd']['imgem3'] = array("name"=>"email3", "dt"=>"C", "len"=>50, "key"=>0);
148  $Allowed_Tables['cuimgvnd']['imgfx3'] = array("name"=>"fax3", "dt"=>"C", "len"=>20, "key"=>0);
149  $Allowed_Tables['cuimgvnd']['imgcomm'] = array("name"=>"comments", "dt"=>"C", "len"=>1000, "key"=>0);
150  $Allowed_Tables['cuimgvnd']['imgdate'] = array("name"=>"datespec", "dt"=>"C", "len"=>1000, "key"=>0);
151 
152  // ** SSO VENDORS TABLE (cussovendors)
153  $Allowed_Tables['cussovnd']['tablename'] = 'cussovendors';
154  $Allowed_Tables['cussovnd']['ssocode'] = array("name"=>"ssovendor", "dt"=>"C", "len"=>10, "key"=>1);
155  $Allowed_Tables['cussovnd']['ssotype'] = array("name"=>"ssotype", "dt"=>"C", "len"=>1, "key"=>0);
156  $Allowed_Tables['cussovnd']['ssodesc'] = array("name"=>"ssodesc", "dt"=>"C", "len"=>30, "key"=>0);
157  $Allowed_Tables['cussovnd']['ssocnt'] = array("name"=>"contact", "dt"=>"C", "len"=>50, "key"=>0);
158  $Allowed_Tables['cussovnd']['ssophn'] = array("name"=>"phone", "dt"=>"C", "len"=>20, "key"=>0);
159  $Allowed_Tables['cussovnd']['ssoem'] = array("name"=>"email", "dt"=>"C", "len"=>50, "key"=>0);
160  $Allowed_Tables['cussovnd']['ssosetup'] = array("name"=>"setup", "dt"=>"C", "len"=>1000, "key"=>0);
161 
162  // ** CHALLENGE QUESTIONS TABLE (cuquestmaster)
163  $Allowed_Tables['cuquest']['tablename'] = 'cuquestmaster';
164  $Allowed_Tables['cuquest']['qst_id'] = array("name"=>"quest_id", "dt"=>"N", "len"=>0, "key"=>1);
165  $Allowed_Tables['cuquest']['qst_lang'] = array("name"=>"quest_lang", "dt"=>"C", "len"=>5, "key"=>1);
166  $Allowed_Tables['cuquest']['qst_txt'] = array("name"=>"quest_text", "dt"=>"C", "len"=>80, "key"=>0);
167  $Allowed_Tables['cuquest']['qst_etxt'] = array("name"=>"example_text", "dt"=>"C", "len"=>30, "key"=>0);
168  $Allowed_Tables['cuquest']['qst_type'] = array("name"=>"quest_type", "dt"=>"C", "len"=>1, "key"=>0);
169 
170  // ** DMS MONITOR USERS (dmsmonitorusers)
171  $Allowed_Tables['dmsusers']['tablename'] = 'dmsmonitorusers';
172  $Allowed_Tables['dmsusers']['user_name'] = array("name"=>"user_name", "dt"=>"C", "len"=>12, "key"=>1);
173  $Allowed_Tables['dmsusers']['passwd'] = array("name"=>"passwd", "dt"=>"C", "len"=>34, "key"=>0);
174  $Allowed_Tables['dmsusers']['ip_range'] = array("name"=>"ip_range", "dt"=>"C", "len"=>1000, "key"=>0);
175  $Allowed_Tables['dmsusers']['allowed_scripts'] = array("name"=>"allowed_scripts", "dt"=>"C", "len"=>2000, "key"=>0);
176  $Allowed_Tables['dmsusers']['altipaddress'] = array("name"=>"altipaddress", "dt"=>"C", "len"=>15, "key"=>0);
177  $Allowed_Tables['dmsusers']['usersms'] = array("name"=>"usersms", "dt"=>"C", "len"=>40, "key"=>0);
178  $Allowed_Tables['dmsusers']['notifyemail'] = array("name"=>"notifyemail", "dt"=>"C", "len"=>100, "key"=>0);
179  $Allowed_Tables['dmsusers']['userconfirm'] = array("name"=>"userconfirm", "dt"=>"C", "len"=>50, "key"=>0);
180  $Allowed_Tables['dmsusers']['notifyhours'] = array("name"=>"notifyhours", "dt"=>"C", "len"=>20, "key"=>0);
181  $Allowed_Tables['dmsusers']['notifypin'] = array("name"=>"notifypin", "dt"=>"C", "len"=>34, "key"=>0);
182  $Allowed_Tables['dmsusers']['notifyenabled'] = array("name"=>"notifyenabled", "dt"=>"C", "len"=>100, "key"=>0);
183 
184  $Allowed_Tables['trustvendor']['tablename'] = 'cutrustedmaster';
185  $Allowed_Tables['trustvendor']['trustedid'] = array("name"=>"trustedid", "dt"=>"C", "len"=>20, "key"=>1);
186  $Allowed_Tables['trustvendor']['trustedvendor'] = array("name"=>"trustedvendor", "dt"=>"C", "len"=>15, "key"=>0);
187  $Allowed_Tables['trustvendor']['trustedtype'] = array("name"=>"trustedtype", "dt"=>"C", "len"=>10, "key"=>0);
188  $Allowed_Tables['trustvendor']['hcuinterface'] = array("name"=>"hcuinterface", "dt"=>"C", "len"=>100, "key"=>0);
189  $Allowed_Tables['trustvendor']['trustedfields'] = array("name"=>"trustedfields", "dt"=>"C", "len"=>5000, "key"=>0);
190 
191  // ** OnLine Loan App Lookup Header
192  $Allowed_Tables['lnappanslookupheader']['tablename'] = 'lnappanslookupheader';
193  $Allowed_Tables['lnappanslookupheader']['ansid'] = array("name"=>"ansid", "dt"=>"N", "len"=>0, "key"=>1);
194  $Allowed_Tables['lnappanslookupheader']['anstitle'] = array("name"=>"anstitle", "dt"=>"C", "len"=>50, "key"=>0);
195 
196  // ** OnLine Loan App Lookup Detail
197  $Allowed_Tables['lnappanslookupdetail']['tablename'] = 'lnappanslookupdetail';
198  $Allowed_Tables['lnappanslookupdetail']['ansdetailid'] = array("name"=>"ansdetailid", "dt"=>"N", "len"=>0, "key"=>1);
199  $Allowed_Tables['lnappanslookupdetail']['ansid'] = array("name"=>"ansid", "dt"=>"N", "len"=>0, "key"=>0);
200  $Allowed_Tables['lnappanslookupdetail']['ansvalue'] = array("name"=>"ansvalue", "dt"=>"C", "len"=>50, "key"=>0);
201  $Allowed_Tables['lnappanslookupdetail']['ansdisplay'] = array("name"=>"ansdisplay", "dt"=>"C", "len"=>50, "key"=>0);
202 
203  // ** Custom Content Maintenance
204  $Allowed_Tables['cucmsdocs']['tablename'] = 'cucmsdocs';
205  $Allowed_Tables['cucmsdocs']['docsid'] = array("name"=>"docsid", "dt"=>"N", "len"=>0, "key"=>1);
206  $Allowed_Tables['cucmsdocs']['docsname'] = array("name"=>"docsname", "dt"=>"C", "len"=>50, "key"=>0);
207  $Allowed_Tables['cucmsdocs']['docsdesc'] = array("name"=>"docsdesc", "dt"=>"C", "len"=>250, "key"=>0);
208  $Allowed_Tables['cucmsdocs']['docstitle'] = array("name"=>"docstitle", "dt"=>"C", "len"=>100, "key"=>0);
209  $Allowed_Tables['cucmsdocs']['docstype'] = array("name"=>"docstype", "dt"=>"N", "len"=>2, "key"=>0);
210  $Allowed_Tables['cucmsdocs']['docsdisplaylink'] = array("name"=>"docsdisplaylink", "dt"=>"C", "len"=>1, "key"=>0);
211  $Allowed_Tables['cucmsdocs']['docsdisplaytext'] = array("name"=>"docsdisplaytext", "dt"=>"C", "len"=>100, "key"=>0);
212  $Allowed_Tables['cucmsdocs']['docsdefaultavail'] = array("name"=>"docsdefaultavail", "dt"=>"C", "len"=>1, "key"=>0);
213  $Allowed_Tables['cucmsdocs']['docsresponsetype'] = array("name"=>"docsresponsetype", "dt"=>"C", "len"=>1, "key"=>0);
214  $Allowed_Tables['cucmsdocs']['docsmaintsection'] = array("name"=>"docsmaintsection", "dt"=>"C", "len"=>30, "key"=>0);
215  $Allowed_Tables['cucmsdocs']['docsmaintsort'] = array("name"=>"docsmaintsort", "dt"=>"N", "len"=>3, "key"=>0);
216  $Allowed_Tables['cucmsdocs']['docstarget'] = array("name"=>"docstarget", "dt"=>"C", "len"=>20, "key"=>0);
217  $Allowed_Tables['cucmsdocs']['docstargetname'] = array("name"=>"docstargetname", "dt"=>"C", "len"=>100, "key"=>0);
218 
219  // ** END TABLE LAYOUTS
220 
221  // ** Security Settings **
222  $http_user = "nobody";
223  $http_pwd = "no1home";
224 
225  /*
226  * http_use_curl - This is used to determine if the post is sent using
227  * 1 - command line curl will be used
228  * 0 - fopen will be used (curl is implied for fopen url)
229  */
230  $http_use_curl = 1;
231  // ** End Settings
232 
233  // **
234  $Remote_Fields = array();
235  $Remote_Table = "";
236 
237  // *** Function: remote_update_list
238  // *** Purpose: To list the servers that are available for remote updating
239  function remote_update_list() {
240  global $Remote_Servers;
241  print <<< EOF
242  <table border="0" cellpadding="1" cellspacing="1">
243  <tr>
244  <td class="hdr">Please select all remote servers you wish to update:</td>
245  </tr>
246 EOF;
247  foreach ($Remote_Servers as $key => $value) {
248  if ($_SERVER['HTTP_HOST'] != $value['host']) {
249  // ** NOT THE SAME MACHINE PRINT THE FIELD
250  $default_checked = ($value['upd'] ? "checked" : "");
251  print "
252  <tr>
253  <td class=\"dtl\">
254  <input type=\"checkbox\" value=\"$key\" name=\"Remote_Update[]\" $default_checked>$key
255  </td>
256  </tr> ";
257  }
258  }
259  print "
260  <tr>
261  <td class=\"dtl\"><hr></td>
262  </tr>
263  </table>";
264  }
265 
266  function Remote_Update_Selected() {
267  if (isset($_POST['Remote_Update']) && is_array($_POST['Remote_Update'])) {
268  return true;
269  } else {
270  return false;
271  }
272  }
273  function Remote_Update_Send($action, $table) {
274  global $Remote_Servers;
275  // ** LOOP THROUGH EACH SERVER LISTED
276  if (Remote_Update_Selected()) {
277  foreach ($_POST['Remote_Update'] as $key => $value) {
278  // ** CALL EACH SERVER
279  if (isset($Remote_Servers[$value]["IP"])) {
280  $remote_url = Remote_Field_URL($action, $table, $value);
281  list($call_cd, $call_desc) = Call_URL($remote_url);
282  $call_msg = "";
283  if ($call_cd < "900") {
284  // *** SUCCESSFUL
285  $call_msg .= "<li>Update to server $value was successful.<br>";
286  } else {
287  // *** FAILURE
288  $call_msg .= "<li>Update to server $value failed with description '$call_desc'.<br>";
289  }
290  } else {
291  // THE SERVER WAS NOT FOUND TO MAKE A REMOTE CALL
292  // ** NOT FOUND
293  $call_msg .= "$value - NOT FOUND";
294  }
295  }
296  return $call_msg;
297  } else {
298  return "No Remote Servers Selected to Update";
299  }
300 
301  }
302 
303  // ** This will update all Servers that are set to default
304  // ** It does NOT require any selection by user -- it is
305  // all behind the scenes
306 
307  function Remote_Update_All($action, $table) {
308  global $Remote_Servers;
309  // ** LOOP THROUGH EACH SERVER LISTED
310  $call_msg = "";
311  foreach ($Remote_Servers as $key => $value) {
312  // ** CALL EACH SERVER
313  if ($value["upd"] == true && ($_SERVER['HTTP_HOST'] != $value['host'])) {
314  // if (isset($Remote_Servers[$value]["IP"])) {
315  // $remote_url = Remote_Field_URL($action, $table, $value);
316  $remote_url = Remote_Field_URL($action, $table, $key);
317  list($call_cd, $call_desc) = Call_URL($remote_url);
318  if ($call_cd < "900") {
319  // *** SUCCESSFUL
320  $call_msg .= "<li>Update to server $key was successful.<br>";
321  } else {
322  // *** FAILURE
323  $call_msg .= "<li>Update to server $key failed with description '$call_desc'.<br>";
324  }
325  } else {
326  // THE SERVER WAS NOT FOUND TO MAKE A REMOTE CALL
327  // ** NOT FOUND
328  }
329  }
330  return $call_msg;
331 
332  }
333 
334  function Remote_Field_Add($table, $fld_key, $fld_value) {
335  // Add the value to the array
336  global $Remote_Fields, $Allowed_Tables;
337 
338  // Validate the key is a valid field in a table
339  if (isset($Allowed_Tables[$table][$fld_key])) {
340  $Remote_Fields[] = array("name"=>$fld_key, "value"=>trim($fld_value));
341  }
342 
343  }
344 
345  function Remote_Field_URL($action, $table, $server) {
346  // ** Loop through each element in the Remote_Fields variable and set the URL value
347  global $Remote_Servers, $Allowed_Tables, $Remote_Fields, $Remote_Table, $http_user, $http_pwd;
348  //$return_url = "";
349  $return_url = Array('url'=>'', 'data'=>'', 'security'=>'');
350 
351  $return_data = "";
352 
353  if (is_array($Remote_Servers[$server]) && in_array($action, array("U", "D", "S")) && is_array($Allowed_Tables[$table])) {
354  foreach ($Remote_Fields as $key=>$value) {
355  $return_data .= "&" . "col[$key][name]=" . urlencode($value['name']) .
356  "&" . "col[$key][value]=" . urlencode($value['value']);
357  }
358  // ** prepare security section if applicable for the server
359  if ($Remote_Servers[$server]["http_login"] == true) {
360  $url_security = "{$http_user}:{$http_pwd}@";
361  } else {
362  $url_security = "";
363  }
364  // Prepare the beginning part of the url
365 // $return_url = "https://$url_security" . $Remote_Servers[$server]["IP"] . "/hcuadm/remote_monitor_save.prg?ac=$action&tbl=$table" . $return_url;
366  $return_url['url'] = "https://" . $Remote_Servers[$server]["IP"] . "/hcuadm/remote_monitor_save";
367  $return_url['data'] = "ac=$action&tbl=$table" . $return_data;
368  if ($Remote_Servers[$server]["http_login"] == true) {
369  $return_url['security'] = "{$http_user}:{$http_pwd}";
370  }
371 
372  // ** Check security
373  $Remote_Table = $table;
374  }
375  return $return_url;
376  }
377 
378  function Call_URL($remote_url) {
379  // *** This function will call the remote script and pass back the results
380  global $http_use_curl;
381  // ** Pass the file
382 // $results_ary = file($remote_url);
383 
384 
385  $opts = "--connect-timeout 5 --retry 3 --retry-delay 2";
386 
387  $url_security = '';
388 
389  if ($http_use_curl) {
390  if ($remote_url['security'] != '') {
391  $url_security = " -u {$remote_url['security']} ";
392  }
393 
394  $fd = popen("/usr/bin/curl -k -N $url_security --silent $opts -d '{$remote_url['data']}' '{$remote_url['url']}'","r");
395  if (!$fd) {
396  $results_ary = Array();
397  } else {
398  $packet = "";
399  while ($buff = fread ($fd, 1500)) {
400  $packet .= $buff;
401  }
402  $pipe_err = pclose($fd);
403  $results_ary = explode("\n", $packet);
404  }
405 
406  } else {
407  // ** For fopen to use posted values, we will first setup an array with the POST HEADER information,
408  // * then create a stream_context, then include this context on the file open
409 
410  $params = array('http' => array('method' => 'POST', 'content' => $remote_url['data']));
411  if ($remote_url['security'] != '') {
412  $params['http']['header'] = "Authorization: Basic " . base64_encode($remote_url['security']);
413  }
414 
415  $ctx = stream_context_create($params);
416 
417  $results_ary = @file($remote_url['url'], false, $ctx);
418 
419  }
420 
421 
422  // ** NOW LOOP THROUGH THE RESULTS
423  // ** IDEALLY, there should only be one line returned
424 // ** TRY WITHOUT PRINTING MWS 12/27/12
425 // foreach ($results_ary as $value) {
426 // print "<Br>11 - $value";
427 // }
428 
429  if (count($results_ary) == 1 && strstr($results_ary[0], "RU: ") !== FALSE) {
430  // SUCCESS
431  return array(substr($results_ary[0], 4, 3), substr($results_ary[0], 10));
432  } else {
433  // ** ERROR --
434  return array("999", "Unable to update the remote server");
435  }
436 
437  }
438  function Remote_Fields_Reset() {
439  // ** THIS WILL RESET THE FIELDS ARRAY
440  global $Remote_Fields;
441  $Remote_Fields = array();
442 
443  }
444  function Remote_Update_Special($specialcode) {
445  global $Remote_Servers;
446  // ** LOOP THROUGH EACH SERVER LISTED
447  if (Remote_Update_Selected()) {
448  foreach ($_POST['Remote_Update'] as $key => $value) {
449  // ** CALL EACH SERVER
450  if (isset($Remote_Servers[$value]["IP"])) {
451  $remote_url = Remote_Field_URL("S", $specialcode, $value);
452  list($call_cd, $call_desc) = Call_URL($remote_url);
453  if ($call_cd < "900") {
454  // *** SUCCESSFUL
455  $call_msg .= "<li>Update to server $value was successful.<br>";
456  } else {
457  // *** FAILURE
458  $call_msg .= "<li>Update to server $value failed with description '$call_desc'.<br>";
459  }
460  } else {
461  // THE SERVER WAS NOT FOUND TO MAKE A REMOTE CALL
462  // ** NOT FOUND
463  $call_msg .= "$value - NOT FOUND";
464  }
465  }
466  return $call_msg;
467  } else {
468  return "No Remote Servers Selected to Update";
469  }
470 
471  }
472 ?>