PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/setup.php

http://ebpls.googlecode.com/
PHP | 314 lines | 261 code | 33 blank | 20 comment | 46 complexity | a7579297a5734ea87b0616570f39144f MD5 | raw file
  1. <?php
  2. $valid=$HTTP_POST_VARS["valid"];
  3. $dbname=$HTTP_POST_VARS["dbname"];
  4. $dbuser=$HTTP_POST_VARS["dbuser"];
  5. $dbpass=$HTTP_POST_VARS["dbpass"];
  6. $dbhost=$HTTP_POST_VARS["dbhost"];
  7. $site=$HTTP_POST_VARS["site"];
  8. //$webdir=$HTTP_POST_VARS["webdir"];
  9. $insdir=$HTTP_POST_VARS["insdir"];
  10. function updateConfig($arrVarNames='a000',$arrNewValues=0,$strConfigFile="setup/setting.php")
  11. {
  12. if (count($arrVarNames) == count($arrNewValues)) {
  13. $arrConfigBuffer = NULL;
  14. // buffer the config file!
  15. $fp1 = fopen($strConfigFile,"rb");
  16. $arrNeedle = array(";","\r","\t","\n");
  17. while (!feof($fp1)) {
  18. $strBuffer = fgets($fp1, 4096);
  19. if (stristr($strBuffer,'$') && stristr($strBuffer,'=') && stristr($strBuffer,';')) {
  20. $strBuffer = str_replace($arrNeedle,"",$strBuffer);
  21. $arrTempBuffer = split('=',$strBuffer);
  22. $strVarName = str_replace("\$","",array_shift($arrTempBuffer));
  23. $strCurrValue = implode("=",$arrTempBuffer);
  24. $arrConfigBuffer[trim($strVarName)] = trim($strCurrValue);
  25. }
  26. }
  27. fclose($fp1);
  28. // update the values of the config buffer
  29. if (is_array($arrVarNames)) {
  30. foreach($arrVarNames as $strAssocName) {
  31. $arrConfigBuffer[$strAssocName] = array_shift($arrNewValues);
  32. }
  33. } else {
  34. $arrConfigBuffer[$arrVarNames] = $arrNewValues;
  35. }
  36. //echo "<== REACHED THIS PLACE ==><BR>";
  37. // re-write the file
  38. $fp2 = fopen($strConfigFile,"wb");
  39. fwrite($fp2,"<?php\r\n\r\n");
  40. foreach ($arrConfigBuffer as $key => $value) {
  41. if (stristr($value,' //')) {
  42. $value = str_replace(' //',';/* ',$value);
  43. $value .= ' */';
  44. } elseif ((stristr($value,'/*') && stristr($value,'*/'))) {
  45. $value = str_replace('/*',';/*',$value);
  46. } else {
  47. $value = $value.";";
  48. }
  49. fwrite($fp2,"\$$key = $value\r\n");
  50. }
  51. fwrite($fp2,"\r\n?>");
  52. fclose($fp2);
  53. return 1;
  54. } else {
  55. return FALSE;
  56. }
  57. }
  58. //update variables
  59. function updateVars($arrVarNames='a000',$arrNewValues=0,$strConfigFile="includes/dbvar.php")
  60. {
  61. if (count($arrVarNames) == count($arrNewValues)) {
  62. $arrConfigBuffer = NULL;
  63. // buffer the config file!
  64. $fp1 = fopen($strConfigFile,"rb");
  65. $arrNeedle = array(";","\r","\t","\n");
  66. while (!feof($fp1)) {
  67. $strBuffer = fgets($fp1, 4096);
  68. $arrTempBuffer = split('=',$strBuffer);
  69. $strVarName = array_shift($arrTempBuffer);
  70. $arrConfigBuffer[trim($strVarName)] = trim($strVarName);
  71. echo $arrConfigBuffer[trim($strVarName)]."<br>";
  72. }
  73. fclose($fp1);
  74. // update the values of the config buffer
  75. if (is_array($arrVarNames)) {
  76. foreach($arrVarNames as $strAssocName) {
  77. $arrConfigBuffer[$strAssocName] = array_shift($arrNewValues);
  78. }
  79. } else {
  80. $arrConfigBuffer[$arrVarNames] = $arrNewValues;
  81. }
  82. //echo "<== REACHED THIS PLACE ==><BR>";
  83. // re-write the file
  84. $fp2 = fopen($strConfigFile,"wb");
  85. foreach ($arrConfigBuffer as $key => $value) {
  86. if (stristr($value,' //')) {
  87. $value = str_replace(' //',';/* ',$value);
  88. $value .= ' */';
  89. } elseif ((stristr($value,'/*') && stristr($value,'*/'))) {
  90. $value = str_replace('/*',';/*',$value);
  91. } else {
  92. $value = $value;
  93. }
  94. fwrite($fp2,"$value\r\n");
  95. }
  96. fclose($fp2);
  97. return 1;
  98. } else {
  99. return FALSE;
  100. }
  101. }
  102. function updateVarsite($arrNewValues=0, $strConfigFile="includes/varsite.php")
  103. {
  104. $fp2 = fopen($strConfigFile,"wb");
  105. $value .= $arrNewValues;
  106. fwrite($fp2,"<?php\r\n");
  107. fwrite($fp2,"$value\r\n");
  108. fwrite($fp2,"?>\r\n");
  109. fclose($fp2);
  110. return 1;
  111. }
  112. ////
  113. if ($valid==1) {
  114. $r = @mysql_connect($dbhost,$dbuser,$dbpass);
  115. if ($r=='') {
  116. echo "Cannot connect to server using $dbuser@$dbhost";
  117. } else {
  118. $db = mysql_select_db($dbname);
  119. if ($db=='') {
  120. echo "Cannot connect to database $dbname, I will now create it for you<br>";
  121. $cdb = mysql_query("create database $dbname") or die(mysql_error());
  122. }
  123. $db = mysql_select_db($dbname);
  124. // $s1 = shell_exec("cd $webdir 2>&1 ");
  125. //
  126. //
  127. // if ($s1<>'') {
  128. // echo "Invalid web directory, no directory found moron";
  129. // } else {
  130. echo "Installing now....... ";
  131. $s3 = shell_exec("tar -xzvf bpls.tar.gz 2>&1");
  132. //$s3 = shell_exec("mv bplsline $insdir 2>&1");
  133. //echo "<BR>$s3";
  134. $s3 = shell_exec("mysql -u$dbuser -p$dbpass $dbname<ebpls.sql");
  135. echo "Done....";
  136. $x=0;
  137. while ($x<300) {
  138. $ins = mysql_query("insert into ebpls_buss_taxfeeother
  139. (taxfeeid) values ('')");
  140. $x++;
  141. }
  142. $delins = mysql_query("delete from ebpls_buss_taxfeeother");
  143. $ty = mysql_query("truncate ebpls_user");
  144. $ty = mysql_query("INSERT INTO ebpls_user (id, level, csgroup, username, password, lastname, firstname, designation, email, gsmnum, login, logout, lockout, currthreads, roundrobinflag, dateadded, lastupdated) VALUES (1, '?', NULL, 'ebpls', '°e?w', 'EBPLS', 'EBPLS', '', '', '', '2007-03-07 16:35:31', '2007-03-07 16:35:31', NULL, NULL, NULL, '2006-07-06 09:56:38', '2007-03-07 16:35:31')");
  145. $ty = mysql_query("INSERT INTO ebpls_user (id, level, csgroup, username, password, lastname, firstname, designation, email, gsmnum, login, logout, lockout, currthreads, roundrobinflag, dateadded, lastupdated) VALUES (2, '?', NULL, 'nccfoo', '?]v?kL', 'FOO', 'NCC', '', '', '', '2007-02-01 13:49:49', '2007-01-23 14:01:26', NULL, NULL, NULL, '2006-07-06 09:57:11', '2007-02-01 13:49:49')") or die (mysql_error());
  146. //}
  147. $arrKeys = array(
  148. 'thDbUser',
  149. 'thDbUKey',
  150. 'thDbName',
  151. );
  152. $dbuser1 = "\"$dbuser\"";
  153. $dbpass1 = "\"$dbpass\"";
  154. $dbname1 = "\"$dbname\"";
  155. $arrValues = array(
  156. $dbuser1,
  157. $dbpass1,
  158. $dbname1,
  159. );
  160. updateConfig($arrKeys,$arrValues,"setup/setting.php");
  161. $arrKeys = array(
  162. "define(\"eBPLS_APP_URL\", \"http://192.168.1.104/bpls/\"); // do not include filenames"
  163. );
  164. $xsite = "define(\"eBPLS_APP_URL\", \"".$site."/\"); // do not include filenames";
  165. $arrValues = $xsite;
  166. updateVarsite($arrValues,"includes/varsite.php");
  167. $arrKeys = array(
  168. "dbuser",
  169. "dbpass",
  170. "dbname"
  171. );
  172. $dbuser1 = "'$dbuser'";
  173. $dbpass1 = "'$dbpass'";
  174. $dbname1 = "'$dbname'";
  175. $arrValues = array(
  176. $dbuser1,
  177. $dbpass1,
  178. $dbname1
  179. );
  180. updateConfig($arrKeys,$arrValues,"includes/dbvar.php");
  181. }
  182. }
  183. ?>
  184. <form name=x method=post>
  185. <table border="0" width="100%">
  186. <tr>
  187. <td width="161">&nbsp;</td>
  188. <td>&nbsp;</td>
  189. </tr>
  190. <tr>
  191. <td width="161">&nbsp;</td>
  192. <td>&nbsp;</td>
  193. </tr>
  194. <tr>
  195. <td width="161">Enter BPLS Site:</td>
  196. <td><input type="text" name="site" size="20"></td>
  197. </tr>
  198. <tr>
  199. <td width="161">Enter Database host:</td>
  200. <td><input type="text" name="dbhost" size="20" value='localhost'></td>
  201. </tr>
  202. <tr>
  203. <td width="161">Enter Database Name:</td>
  204. <td><input type="text" name="dbname" size="20"></td>
  205. </tr>
  206. <tr>
  207. <td width="161">Enter Database User:</td>
  208. <td><input type="text" name="dbuser" size="20"></td>
  209. </tr>
  210. <tr>
  211. <td width="161">Enter Database Password:</td>
  212. <td><input type="text" name="dbpass" size="20"></td>
  213. </tr>
  214. <tr>
  215. <td width="161">&nbsp;</td>
  216. <td>&nbsp;</td>
  217. </tr>
  218. <input type="hidden" name="valid" size="20">
  219. <tr>
  220. <td width="161">&nbsp;</td>
  221. <td><input type="button" value="Install" name="B1" onclick='Verifym();'></td>
  222. </tr>
  223. </table>
  224. <script language='javascript'>
  225. function isBlank(_arg)
  226. {
  227. if(_arg == null || _arg == "undefined" || _arg.length == 0)
  228. {
  229. return true;
  230. }
  231. else
  232. {
  233. var cnt = 0;
  234. var _str = "";
  235. for(var i=0;i<_arg.length;i++)
  236. {
  237. if( ! (_arg.charCodeAt(i) == 13 || _arg.charCodeAt(i) == 32))
  238. {
  239. _str += _arg.charAt(i);
  240. }
  241. }
  242. return (_str.length == 0 || _str == "") ? (true) : (false);
  243. }
  244. }
  245. function Verifym()
  246. {
  247. var x = document.x;
  248. if (isBlank(x.site.value)) {
  249. alert ("Please input site. Mutha");
  250. x.site.select();
  251. x.site.focus();
  252. return false;
  253. }
  254. if (isBlank(x.dbhost.value)) {
  255. alert ("Please input database hostname. Mutha");
  256. x.dbhost.select();
  257. x.dbhost.focus();
  258. return false;
  259. }
  260. if (isBlank(x.dbname.value)) {
  261. alert ("Please input database name. Mutha");
  262. x.dbname.select();
  263. x.dbname.focus();
  264. return false;
  265. }
  266. if (isBlank(x.dbuser.value)) {
  267. alert ("Please input database user. Mutha");
  268. x.dbuser.select();
  269. x.dbuser.focus();
  270. return false;
  271. }
  272. if (isBlank(x.dbpass.value)) {
  273. alert ("Please input database password. Mutha");
  274. x.dbpass.select();
  275. x.dbpass.focus();
  276. return false;
  277. }
  278. x.valid.value=1;
  279. x.submit();
  280. }
  281. </script>