Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.46 KB | None | 0 0
  1. <?php
  2. /*
  3. * Tracker Suite v0.1
  4. * Requires: PHP & MySQL
  5. * ---------
  6. * Most hosting providers will usually say if they have PHP or not.
  7. * If you want to locally host it, I recommend LAMP for Linux, or Xampp for winblows.
  8. *
  9. */
  10.  
  11. /* README
  12. * The user and password you define below shouldn't already exist. These will be created.
  13. * You will be prompted once to provide a username and password that can create a user
  14. * and delegate privileges.
  15. */
  16.  
  17. // MySQL defines:
  18. $SQL_HOSTNAME = "localhost";
  19. $SQL_DBNAME = "tracker102";
  20. $SQL_USER = "tracker102";
  21. $SQL_PASS = "lawLingbawling";
  22.  
  23.  
  24. // Functions
  25.  
  26. function check_for_db($_host,$_user,$_pass,$_dbname) {
  27.     $link = mysqli_connect($_host,$_user,$_pass,$_dbname);
  28.     if(!$link) {
  29.         echo "<div class='track_error'>MySQL connect error (" . mysqli_connect_errno() . ") : " . mysqli_connect_error() . ".</div></br></br>";
  30.         return mysqli_connect_errno();
  31.     }
  32.     else {
  33.         return 0;
  34.     }
  35. }
  36.  
  37. function tracker_setup($setup_host, $setup_user, $setup_pass, $setup_dbname) {
  38.     if ( isset($_POST['_sqluser']) && isset($_POST['_sqlpass']) && isset($_POST['_sqlhost']) ) {
  39.         $setuplink = mysqli_connect($_POST['_sqlhost'], $_POST['_sqluser'], $_POST['_sqlpass']);
  40.         if ( !$setuplink ) {
  41.             echo "<div class='track_error'>MySQL connect error (" . mysqli_connect_errno() . ") : " . mysqli_connect_error() . ".</br></br>";
  42.             echo "<b>Press the back button and please correct the error.</b></br>";
  43.             return mysqli_connect_errno();
  44.         }
  45.        
  46.         echo "Attempting to create user...</br>";
  47.         if ( mysqli_query($setuplink, "CREATE USER '{$setup_user}'@'{$setup_host}' IDENTIFIED BY '{$setup_pass}'") == FALSE ) {
  48.             echo "<div class='track_error'>User creation failed</br>" . mysqli_error($setuplink) . "</div>";
  49.             return -1;
  50.         }
  51.         echo "<div class='track_success'>User created successfully!</div></br>Attempting to create database...</br>";
  52.         if ( mysqli_query($setuplink, "CREATE DATABASE {$setup_dbname}") == FALSE ) {
  53.             echo "<div class='track_error'>Database creation failed!</br>" . mysqli_error($setuplink) . "</div>";
  54.             return -1;
  55.         }
  56.         echo "<div class='track_success'>Database created successfully!</div></br>Attempting to grant permissions to the new user...</br>";
  57.         if ( mysqli_real_query($setuplink, "GRANT ALL ON {$setup_dbname}.* TO {$setup_user}@{$setup_host}") == FALSE ) {
  58.             echo "<div class='track_error'>Granting permissions to '{$setup_user}' failed!</br>" . mysqli_error($setuplink) . "</div>";
  59.             return -1;
  60.         }
  61.         echo "<div class='track_success'>All queries are successful!</br>You can now create a new tracker using the nav bar at the top of the page.</div>";
  62.     }
  63.     else {
  64.         echo "
  65.         <b>Please enter existing account details that can setup a database, create users, and delegate privileges.</br>
  66.         This will use a personal account only once to create a user and a database just for interacting with software and the databases it creates.</br>
  67.         </b>
  68.         *Make sure you have correctly set your MySQL defines in the source code before attempting this.</br></br>
  69.         <form action='' method='POST'>
  70.         Username <input type='text' name='_sqluser' /></br>
  71.         Password <input type='password' name='_sqlpass' /></br>
  72.         Hostname <input type='text' name='_sqlhost' /></br>
  73.         <input type='submit' />
  74.         </form>
  75.         ";
  76.     }
  77. }
  78.  
  79.  
  80. ?>
  81.  
  82. <html>
  83. <head>
  84. <title>Tracker Suite</title>
  85. <style>
  86. html, body {
  87.     margin:0;
  88.     padding:0;
  89. }
  90.  
  91. body {
  92.    
  93. }
  94.  
  95. header {
  96.     display:block;
  97.     padding:1%;
  98.     text-align:center;
  99.     font-size: 2em;
  100.     font-weight:bold;
  101.     border-bottom:2px double black;
  102. }
  103.  
  104. nav {
  105.     display:block;
  106.     padding:0.2%;
  107.     font-size:1.1em;
  108.     border-bottom:2px double black;
  109. }
  110.  
  111. .nav_button {
  112.     padding-right:4%;
  113.     padding-left:4%;
  114.     margin-right:0.1%;
  115.     margin-left:0.1%;
  116.     background-color:blue;
  117.     color:black;
  118.     border:1px solid black;
  119.     text-decoration:none;
  120. }
  121.  
  122. .nav_button:hover {
  123.     background-color:gray;
  124.     text-decoration:underline;
  125. }
  126.  
  127. article {
  128.     margin:0.5%;
  129.     padding:0.5%;
  130.     height:80%;
  131.     border:2px double black;
  132.    
  133. }
  134.  
  135. footer {
  136.     position:absolute;
  137.     width:100%;
  138.     bottom:0;
  139.     left:0;
  140.     text-align:center;
  141.     font-size:12px;
  142.     background-color:gray;
  143.     border-top:1px solid black;
  144. }
  145.  
  146. .nav_button, article {
  147.         /* Firefox Curved Borders */
  148.     -moz-border-radius:3px;
  149.         /* Chrome Curved Borders */
  150.     border-radius:3px;
  151. }
  152.  
  153. .track_error {
  154.     display: block;
  155.     padding: 0.5%;
  156.     width: 99%;
  157.     background-color:black;
  158.     color:red;
  159.     font-weight:bold;
  160.     font-size:16px;
  161.     border-bottom:1px solid black;
  162.     text-align: center;
  163. }
  164.  
  165. .track_success {
  166.     display:block;
  167.     color:brightgreen;
  168.     background-color:lightblue;
  169.     font-weight:bold;
  170.     width: 50%;
  171.     text-align:center;
  172. }
  173. </style>
  174. </head>
  175. <body>
  176.     <header>Tracker Suite</header>
  177.     <nav><a class="nav_button" href="?action=new">New</a><a class="nav_button" href="?action=load">Load</a></nav>
  178.     <article>
  179.     <?php
  180.         $x = check_for_db($SQL_HOSTNAME, $SQL_USER, $SQL_PASS, $SQL_DBNAME);
  181.         if( $x != 0 ) {
  182.             // If it is a permission error, then that account is most likely not set up.
  183.             if ( $x == 1045 || $x == 1046 ) {
  184.                 tracker_setup($SQL_HOSTNAME, $SQL_USER, $SQL_PASS, $SQL_DBNAME);
  185.             }
  186.             else {
  187.                 // I have no idea what happened, so let them fix / deal with it. :)
  188.                 die("Please address the error above.");
  189.             }
  190.         }
  191.         else {
  192.             if($_GET['action'] == "new") {
  193.                 echo "blah blah mooose</br></br></br>";
  194.             }
  195.             elseif($_GET['action'] == "load") {
  196.                 // load a selection
  197.             }
  198.         }
  199.     ?>
  200.     </article>
  201.     <footer>Tracker Suite || Code and design by Machiavelli @ breakingsec.org</footer>
  202. </body>
  203. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement