Odyssey
restart.prg
1 <?php
2  $monLibrary= dirname(__FILE__) . "/../library";
3  require_once("$monLibrary/cu_top.i");
4  require_once("$monLibrary/ck_hticket.i");
5 
6  if (!CheckPerm($link, $Hu, basename($_SERVER['SCRIPT_NAME']), $_SERVER['REMOTE_ADDR'])) {
7  // ** Permissions failed
8  // ** redirect to new page
9  header("Location: /hcuadm/hcu_noperm.prg");
10  exit;
11  }
12 
13 $dms_ok=array('cuhome'=>'string','cu'=>'string','nounpack'=>'digits','delhist'=>'digits','skipbal'=>'digits','truncate'=>'digits','RestartCU'=>'string');
14 dms_import($dms_ok);
15 
16  /* Constants */
17  function no_dupes($estring) {
18  foreach (explode(";",$estring) as $x => $ema) {
19  $ema = trim($ema);
20  if ($ema != "" && (strpos("$return","$ema") === false)) {
21  $return .= "$ema;";
22  }
23  }
24  return $return;
25  }
26 
27 
28  function Check_Lock_Status($pFile_to_Check) {
29  // Function - Check_Lock_Status
30  // Purpose - This function will check the lock status of the file named in pFile_to_Check.
31  // Return - This will return 'true' if fuser stated it was locked and 'false' if was NOT in use
32  $upl_in_process = false;
33  // *** FIRST THING.... CHECK LOCK STATUS OF status.txt FILE
34  $ret_fuser = exec("/bin/fuser " . escapeshellcmd($pFile_to_Check));
35  if ($ret_fuser != false) {
36  $upl_in_process = true;
37  }
38  return $upl_in_process;
39  }
40  // ** Set the database handle
41  $dbh = $link;
42 
43  cu_header('Upload Restart');
44 
45  // ** MWS 5/12/2009 - Check here to see if the upload is already in process.. If it is, do NOT allow restarting of the process
46  $upl_in_process = false;
47 
48  // ** Using the cu passed in by the GET or POST.. This ends up using GLOBAL cu value
49  // $sql = "select cu, user_name from cuadmin where user_name = '" . $cu . "'";
50  // ** MWS 6/8/09 -- Problem with the cu variable.. The first pass it is lowercase and the second pass it is uppercase...
51  // ** causing issues.. So lookup the information from cuadmin using the cu value.. but use it uppercase..
52  $sql = "select cu, user_name from cuadmin where cu = '" . strtoupper($cu) . "'";
53 
54  $sth = db_query($sql, $dbh);
55  if ($sth) {
56  $row = db_fetch_array($sth);
57  $row['cu'] = trim($row['cu']);
58  $row['user_name'] = trim($row['user_name']);
59  $cu = $row['cu'];
60  $cuhome ="/home/" . $row['user_name'];
61  } else {
62  // ** ERROR
63  ?>
64  <p>
65  <center>
66  <center>
67  <table width="80%" border=0 cellpadding=3 cellspacing=0 class="dmsbg"><tr><td>
68  <table width="100%" border=0 cellpadding=2 cellspacing=0 bgcolor=white>
69  <tr><td colspan=1 class="bar" align="center">
70  Problem Accessing Credit Union</td>
71  </tr>
72  <tr><td class='dtlc'><span style="font-size: 12pt;color: #990000;">An error was encountered. The Credit Union upload was NOT restarted. Please try again by using the 'Upload Restart' link on the left.</span></td>
73  </tr>
74  </table>
75  </td></tr></table>
76  </body>
77  </html>
78  <?php
79  exit;
80  }
81 
82  // ** Only check if cuhome is set.. This gets set when they press 'GO'
83  // *** CHECK FOR USER ON .txt FILE
84  $txt_path_file = "{$cuhome}/public_html/status.txt";
85 
86 
87  $upl_in_process = Check_Lock_Status($txt_path_file);
88 
89  if ($upl_in_process) {
90  // ** HERE -- I want to display a message to the user telling them they may not make changes at this time and their is a process currently
91  // * Locking the upload status.txt file
92 
93  ?>
94  <p>
95  <center>
96  <center>
97  <table width="80%" border=0 cellpadding=3 cellspacing=0 class="dmsbg"><tr><td>
98  <table width="100%" border=0 cellpadding=2 cellspacing=0 bgcolor=white>
99  <tr><td colspan=1 class="bar" align="center">
100  Upload Already Restarted</td>
101  </tr>
102  <tr><td class='dtlc'><span style="font-size: 12pt;color: #990000;">The upload for <?php echo $cu; ?> is currently being processed. Please check back later.</span></td>
103  </tr>
104  </table>
105  </td></tr></table>
106  </body>
107  </html>
108  <?php
109 
110  } else {
111 
112  if (isset($RestartCU)) {
113 
114 
115  // ** NO lock on the status.txt file.. Either allow them to have option
116 
117  /* UPLOAD CODE HERE */
118  $cmdopt = "-";
119  if (isset($nounpack)) {
120  $cmdopt=$cmdopt."U";
121  }
122  if (isset($delhist)) {
123  $cmdopt=$cmdopt."D";
124  }
125  if (isset($skipbal)) {
126  $cmdopt=$cmdopt."B";
127  }
128  if (isset($truncate)) {
129  $cmdopt=$cmdopt."T";
130  }
131  $cmdopt = ($cmdopt=="-" ? "" : $cmdopt);
132 
133  $cuhome = escapeshellcmd($cuhome); /* to be safe */
134  $command = "mv $cuhome/public_html/status.old.txt $cuhome/public_html/status.older.txt";
135  system ($command);
136  $command = "mv $cuhome/public_html/status.txt $cuhome/public_html/status.old.txt";
137 
138  system ($command);
139 
140 
141  $sql = "SELECT role, email
142  FROM cuadmnotify
143  WHERE cu = '" . strtoupper($cu) . "'
144  AND role in ('upload', 'alert') ";
145  $em_rs = db_query($sql, $dbh);
146  for ($row=0; $em_row = db_fetch_array($em_rs,$row); $row++) {
147  $role = trim($em_row['role']);
148  $$role = trim($em_row['email']);
149  }
150  db_free_result($em_rs);
151 
152  putenv("ADMUSER=HCUrestart");
153  if ("$upload" != "" ) { putenv("ADMMAIL=$upload"); }
154  if ("$alert" != "" ) { putenv("ALERTMAIL=$alert"); }
155  // ** MWS 6/8/09 -- cu should be upper cased already because this is the second pass...but I want to upper it anyways..
156  // ** And because this wasn't looking up the information correctly it was not using the
157  $sql = "SELECT liveserver
158  FROM cuadmin
159  WHERE cu = '" . strtoupper($cu) . "'";
160 
161  $em_rs = db_query($sql, $dbh);
162  list($pgloadcmd) = db_fetch_array($em_rs, 0);
163  db_free_result($em_rs);
164  if (trim($pgloadcmd) == '') {
165  $pgloadcmd = "/usr/local/bin/pgload.pl -h $cuhome ";
166  }
167  $command = (escapeshellcmd("$pgloadcmd $cmdopt") . " >" . escapeshellcmd("$cuhome/public_html/status.txt") . " 2>&1 &");
168 
169  system ($command);
170 
171 
172  ?>
173  <p>
174  <center>
175  <table width="80%" border=0 cellpadding=3 cellspacing=0 class="dmsbg"><tr><td>
176  <table width="100%" border=0 cellpadding=2 cellspacing=0 bgcolor=white>
177  <tr><td colspan=2 class="bar" align="center">
178  Upload Restarted</td>
179  </tr>
180  <tr><td width="30%" class="hdr">Credit Union:</td>
181  <td width="70%" class='dtl'><?php echo $cu; ?></td>
182  <tr><td width="30%" class="hdr">Command:</td>
183  <td width="70%" class='dtl'><?php echo $command; ?></td>
184  </table>
185  </td></tr></table>
186  </body>
187  </html>
188  <?php
189  exit;
190  } else {
191 
192  /* If the user has not filled out the body of the message yet, present the form */
193  /*
194  // ** -- The following code was moved at the top before any processing..
195  $sql = "select cu, user_name from cuadmin where user_name = '" . $cu . "'";
196  $sth = db_query($sql, $dbh);
197  if ($sth) {
198  $row=db_fetch_array($sth);
199  $row['cu']=trim($row['cu']);
200  $row['user_name']=trim($row['user_name']);
201  $cuhome="/home/".$row['user_name'];
202  }
203  */
204  ?>
205 
206  <p>
207  <center>
208  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
209  <table width="80%" border=0 cellpadding=3 cellspacing=0 class="dmsbg"><tr><td>
210  <table width="100%" border=0 cellpadding=2 cellspacing=0 bgcolor=white>
211  <tr><td colspan=2 class="bar" align="center">
212  Upload Restart</td>
213  </tr>
214  <tr><td width="30%" class="hdr">Credit Union:</td>
215  <td width="70%" class='dtl'><?php echo $cu?></td>
216  </tr>
217  <tr>
218  <tr><td width="30%" class="hdr">Home Directory:</td>
219  <td width="70%" class='dtl'><?php echo $cuhome?></td>
220  </tr>
221  <tr><td width="30%" class="hdr">Upload Options:</td>
222  <td width="70%" class='dtl'>
223 
224  <input type=checkbox name="nounpack"
225  checked value="1">Skip Unpack (recommended)<br>
226  <input type=checkbox name="skipbal"
227  checked value="1">Skip Loading Balance Files<br>
228  <input type=checkbox name="delhist"
229  value="1">Delete History Prior to Inserting<br>
230  <input type=checkbox name="truncate"
231  value="1">Truncate History Files<br>
232  </center>
233  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
234  <input type="hidden" name="cu" value="<?php echo $cu?>">
235  <input type="hidden" name="cuhome" value="<?php echo $cuhome?>">
236  <input type="submit" name="RestartCU" value="GO">
237  </td></tr>
238  </table>
239  </td></tr></table>
240  </center>
241 <?php
242  }
243  }
244 ?>
245 </body></html>