PageRenderTime 26ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/grammafone/install.php

https://github.com/benbruscella/Grammafone
PHP | 377 lines | 346 code | 24 blank | 7 comment | 13 complexity | e2562e77b1f13cbed48372726e301a6e MD5 | raw file
  1. <?php
  2. include("lib/config.inc.php");
  3. include("lib/database.php");
  4. function installed(){
  5. $query = "SELECT user_id FROM mp3act_users";
  6. $result = @mysql_query($query);
  7. if(@mysql_num_rows($result) > 0){
  8. echo "<strong class='error'>It appears that you have already installed mp3act on this computer.</strong><br/><br/>";
  9. echo "<a href=\"$GLOBALS[http_url]$GLOBALS[uri_path]/\">Login to your mp3act server</a><br/>";
  10. return TRUE;
  11. }
  12. return FALSE;
  13. }
  14. ?>
  15. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  16. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  17. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  18. <head>
  19. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  20. <title><?php echo $GLOBALS['server_title']; ?> | Install Page</title>
  21. </head>
  22. <style>
  23. body{
  24. padding: 22px;
  25. margin:0;
  26. color: #333;
  27. background: #F0F0F0;
  28. text-align: center;
  29. font: 18px Times;
  30. }
  31. h2{
  32. font-size: 100%;
  33. margin:0;
  34. padding: 0 0 5px 0;
  35. }
  36. ul{
  37. list-style-type: none;
  38. }
  39. a{
  40. color: blue;
  41. }
  42. a:hover{
  43. /*color: #fff;
  44. background: #F21518;
  45. text-decoration: none;*/
  46. color: #F21518;
  47. }
  48. img{
  49. border: 0;
  50. }
  51. input,select{
  52. border: 1px solid #ccc;
  53. background: #f3f3f3;
  54. color: #333;
  55. font-size: 100%;
  56. padding: 2px 3px;
  57. }
  58. select{
  59. padding: 2px 0 2px 3px;
  60. }
  61. input:focus{
  62. border: 1px solid #999;
  63. background: #fff;
  64. color: #000;
  65. }
  66. input.btn{
  67. background: #244A79;
  68. color: #fff;
  69. padding: 2px;
  70. border-color: #0E2F58;
  71. font: normal 14px sans-serif;
  72. }
  73. input.btn:hover{
  74. background: #0E2F58;
  75. }
  76. .clear{
  77. clear: both;
  78. }
  79. .error{
  80. color: #E63838;
  81. font-weight: bold;
  82. }
  83. p#error{
  84. color: #f20000;
  85. font-weight: bold;
  86. }
  87. p.pad{
  88. padding: 0px 18px;
  89. }
  90. .right{
  91. float: right;
  92. }
  93. #wrap{
  94. background: #fff;
  95. border: 1px solid #ccc;
  96. text-align: left;
  97. padding: 0px;
  98. margin:0;
  99. }
  100. #header{
  101. position: relative;
  102. background: #0E2F58;
  103. height: 50px;
  104. color: #fff;
  105. padding: 15px 0 0px 15px;
  106. }
  107. #header h1{
  108. color: #9ABEE5;
  109. padding: 0;
  110. margin:0;
  111. font-size: 150%;
  112. }
  113. #topinfo{
  114. font-size: 90%;
  115. color: #666;
  116. text-align: left;
  117. padding: 0 0 4px 0;
  118. }
  119. </style>
  120. <body>
  121. <?php
  122. $step = 1;
  123. if(isset($_GET['step']))
  124. $step = $_GET['step'];
  125. ?>
  126. <div id="topinfo">
  127. <div class="right">Installation Page</div>
  128. <strong>mp3act music box v1.2</strong>
  129. </div>
  130. <div id="wrap">
  131. <div id="header">
  132. <h1>mp3act Quick Install - Step <?php echo $step; ?></h1>
  133. </div>
  134. <p class='pad'>
  135. <?php
  136. switch($step){
  137. case 1:
  138. if(databaseConnect()){
  139. if(!installed()){
  140. echo "<strong>Welcome to the mp3act installation page</strong><br/><br/>";
  141. echo "This is a very simple and easy installation. You'll be enjoying your music in no time at all. I swear.<br/><br/>";
  142. echo "<a href='install.php?step=2'>Proceed to Step 2 &raquo;</a>";
  143. }
  144. }
  145. else{
  146. echo "<strong class='error'>Unable to establish MySQL connection to database '".$GLOBALS[db_name]."'</strong><br/>";
  147. echo "Please make sure you have created the database and that the database settings in 'mp3act.conf' are correct.";
  148. }
  149. break;
  150. // Test to see if DB and user are set in conf file
  151. // Test DB connection
  152. // If good install Tables
  153. // Give instructions for setting permissions and external programs
  154. // mpg123, lame, Amazon API, php bin
  155. case 2:
  156. databaseConnect();
  157. if(!installed()){
  158. $querys['albums'] = "CREATE TABLE grammafone_albums (
  159. album_id int(11) NOT NULL auto_increment,
  160. album_name varchar(255) NOT NULL default '',
  161. artist_id int(255) NOT NULL default '0',
  162. album_genre varchar(50) default NULL,
  163. album_year smallint(6) NOT NULL default '0',
  164. album_art text NOT NULL,
  165. PRIMARY KEY (album_id)
  166. ) TYPE=MyISAM";
  167. $querys['artists'] = "CREATE TABLE grammafone_artists (
  168. artist_id int(11) NOT NULL auto_increment,
  169. artist_name varchar(255) default NULL,
  170. prefix varchar(7) NOT NULL default '',
  171. PRIMARY KEY (artist_id)
  172. ) TYPE=MyISAM";
  173. $querys['current'] = "CREATE TABLE grammafone_currentsong (
  174. song_id int(11) NOT NULL default '0',
  175. pl_id int(11) NOT NULL default '0',
  176. random tinyint(3) NOT NULL default '0'
  177. ) TYPE=MyISAM";
  178. $querys['playlist'] = "CREATE TABLE grammafone_playlist (
  179. pl_id int(11) NOT NULL auto_increment,
  180. song_id int(11) default NULL,
  181. user_id int(11) NOT NULL default '0',
  182. private tinyint(4) NOT NULL default '0',
  183. PRIMARY KEY (pl_id)
  184. ) TYPE=MyISAM";
  185. $querys['playlists'] = "CREATE TABLE grammafone_saved_playlists (
  186. playlist_id int(11) NOT NULL auto_increment,
  187. user_id int(11) default NULL,
  188. private tinyint(3) default NULL,
  189. playlist_name varchar(255) default NULL,
  190. playlist_songs text,
  191. date_created datetime default NULL,
  192. time int(11) default NULL,
  193. songcount smallint(8) default NULL,
  194. PRIMARY KEY (playlist_id)
  195. ) TYPE=MyISAM";
  196. $querys['songs'] = "CREATE TABLE grammafone_songs (
  197. song_id int(11) NOT NULL auto_increment,
  198. artist_id int(11) NOT NULL default '0',
  199. album_id int(11) NOT NULL default '0',
  200. date_entered datetime default NULL,
  201. name varchar(255) default NULL,
  202. track smallint(6) NOT NULL default '0',
  203. length int(11) NOT NULL default '0',
  204. size int(11) NOT NULL default '0',
  205. bitrate smallint(6) NOT NULL default '0',
  206. type varchar(4) default NULL,
  207. numplays int(11) NOT NULL default '0',
  208. filename text,
  209. random tinyint(4) NOT NULL default '0',
  210. PRIMARY KEY (song_id)
  211. ) TYPE=MyISAM";
  212. $querys['stats'] = "CREATE TABLE grammafone_stats (
  213. num_artists smallint(5) unsigned NOT NULL default '0',
  214. num_albums smallint(5) unsigned NOT NULL default '0',
  215. num_songs mediumint(8) unsigned NOT NULL default '0',
  216. num_genres tinyint(3) unsigned NOT NULL default '0',
  217. total_time varchar(12) NOT NULL default '0',
  218. total_size varchar(10) NOT NULL default '0'
  219. ) TYPE=MyISAM";
  220. $querys['logins'] ="CREATE TABLE grammafone_logins (
  221. login_id int(11) NOT NULL auto_increment,
  222. user_id int(11) default NULL,
  223. date int(11) default NULL,
  224. md5 varchar(100) NOT NULL default '',
  225. PRIMARY KEY (login_id)
  226. ) TYPE=MyISAM";
  227. $querys['users'] = "CREATE TABLE grammafone_users (
  228. user_id int(11) NOT NULL auto_increment,
  229. username varchar(100) NOT NULL default '',
  230. firstname varchar(100) NOT NULL default '',
  231. lastname varchar(100) NOT NULL default '',
  232. password varchar(255) NOT NULL default '',
  233. accesslevel tinyint(4) NOT NULL default '0',
  234. date_created datetime NOT NULL default '0000-00-00 00:00:00',
  235. active tinyint(4) NOT NULL default '0',
  236. email varchar(255) NOT NULL default '',
  237. default_mode varchar(50) NOT NULL default '',
  238. default_bitrate int(11) NOT NULL default '0',
  239. default_stereo varchar(50) NOT NULL default '',
  240. md5 varchar(255) NOT NULL default '',
  241. last_ip varchar(50) NOT NULL default '',
  242. last_login datetime default NULL,
  243. theme_id smallint(6) NOT NULL default '1',
  244. as_username varchar(20) NOT NULL default '',
  245. as_password varchar(30) NOT NULL default '',
  246. as_lastresult varchar(255) NOT NULL default '',
  247. as_type tinyint(4) NOT NULL default '0',
  248. PRIMARY KEY (user_id)
  249. ) TYPE=MyISAM";
  250. $querys['audioscrobbler'] = "CREATE TABLE IF NOT EXISTS grammafone_audioscrobbler (
  251. as_id int(11) NOT NULL auto_increment,
  252. user_id int(11) NOT NULL default '0',
  253. song_id int(11) NOT NULL default '0',
  254. as_timestamp varchar(100) NOT NULL default '',
  255. PRIMARY KEY (as_id)
  256. ) TYPE=MyISAM";
  257. $querys['settings'] = "CREATE TABLE grammafone_settings (
  258. id int(3) NOT NULL auto_increment,
  259. version varchar(15) NOT NULL default '',
  260. invite_mode tinyint(4) NOT NULL default '0',
  261. upload_path varchar(255) NOT NULL default '',
  262. amazonid varchar(255) NOT NULL default '',
  263. downloads tinyint(4) NOT NULL default '0',
  264. sample_mode tinyint(2) NOT NULL default '0',
  265. mp3bin varchar(100) NOT NULL default '',
  266. lamebin varchar(100) NOT NULL default '',
  267. phpbin varchar(100) NOT NULL default '',
  268. PRIMARY KEY (id)
  269. ) TYPE=MyISAM";
  270. $querys['settingsinfo'] = "INSERT INTO `grammafone_settings` VALUES (NULL,'1.2',0, '', '', 0,0,'','','')";
  271. echo "<strong>Creating mp3act Database Tables....</strong><br/><br/>";
  272. // CREATE TABLES
  273. $error = 0;
  274. foreach($querys as $key=>$query){
  275. if(mysql_query($query)){
  276. }
  277. else{
  278. $error = 1;
  279. }
  280. }
  281. if(!$error){
  282. echo "<strong>mp3act Databases Installed Successfully</strong<br/><br/>";
  283. }
  284. echo "<a href='install.php?step=3'>Proceed to Step 3 &raquo;</a>";
  285. }
  286. break;
  287. case 3:
  288. databaseConnect();
  289. if(!installed()){
  290. ?>
  291. <strong class='error'>Take a Moment to Configure Your mp3act Installation.</strong><br/> You don't have to set these now. They are accessible from the Admin menu. However some of the options are neccessary for some features to work.<br/>
  292. <form method='post' action="install.php?step=4">
  293. <p class='pad'>
  294. <strong>Invitation for Registration</strong><br/>(Users are required to be invited to register)<br/><select name='invite'><option value='0' >Not Required</option><option value='1'>Required</option></select><br/><br/>
  295. <strong>Sample Mode</strong><br/>(play 1/4 of each song)<br/><select name='sample_mode'><option value='0'>Sample Mode OFF</option><option value='1' >Sample Mode ON</option></select><br/><br/>
  296. <strong>Music Downloads</strong><br/>(Rules for Users Downloading Music)<br/><select name='downloads'><option value='0' >Not Allowed</option><option value='1' >Allowed for All</option><option value='2' >Allowed with Permission</option></select><br/><br/>
  297. <strong>Amazon API Key</strong><br/>(needed for downloading Album Art) <a href='http://www.amazon.com/webservices/' target='_new'>Obtain Key</a><br/><input type='text' size='30' name='amazonid' /><br/><br/>
  298. <strong>Path to MP3 Player</strong><br/>(ex. /usr/bin/mpg123)<br/><input type='text' size='30' name='mp3bin' /><br/><br/>
  299. <strong>Path to Lame Encoder</strong><br/>(ex. /usr/bin/lame)<br/><input type='text' size='30' name='lamebin' /><br/><br/>
  300. <strong>Path to PHP-CLI Binary</strong><br/>(ex. /usr/bin/php)<br/><input type='text' size='30' name='phpbin' /><br/><br/>
  301. <input type='submit' value='save settings and continue &raquo;' class='btn' />
  302. </p>
  303. </form>
  304. <?php
  305. }
  306. break;
  307. case 4:
  308. databaseConnect();
  309. if(!installed()){
  310. $query = "UPDATE mp3act_settings SET invite_mode=$_POST[invite],sample_mode=$_POST[sample_mode],downloads=$_POST[downloads],amazonid=\"$_POST[amazonid]\",mp3bin=\"$_POST[mp3bin]\",lamebin=\"$_POST[lamebin]\",phpbin=\"$_POST[phpbin]\" WHERE id=1";
  311. mysql_query($query);
  312. echo "<strong>Settings Saved....</strong><br/><br/>";
  313. echo "<strong>Installation Successful!</strong><br/><br/>";
  314. if(!ini_get('allow_url_fopen')){
  315. echo "<strong class='error'>WARNING: </strong>Need to Set allow_url_fopen to 'On' in your php.ini file.<br/><br/>";
  316. }
  317. if(!is_writable($GLOBALS['abs_path']."/art/")){
  318. echo "<strong class='error'>WARNING: </strong>The /art/ directory is currently not writable. Please change the permissions on this directory if you wish to use Album Art.<br/><br/>";
  319. }
  320. echo "<a href=\"$GLOBALS[http_url]$GLOBALS[uri_path]/\">Login to your new mp3act server</a><br/>";
  321. $random_password = substr(md5(uniqid(microtime())), 0, 6);
  322. $query = "INSERT INTO `mp3act_users` VALUES (NULL, 'admin', 'Admin', 'User', PASSWORD(\"$random_password\"), 10, NOW(), 1, '', 'streaming', 0, 's', '21232f297a57a5a743894a0e4a801fc3', '', '0000-00-00 00:00:00', 1,'','','',0)";
  323. mysql_query($query);
  324. echo "<br/><strong>Username:</strong> Admin<br/><strong>Password:</strong> $random_password (Please change this password as soon as you login.)<br/><br/>";
  325. echo "To add music to the database, choose the 'Admin' tab and click on 'Add Music to Database'";
  326. }
  327. break;
  328. } // END SWITCH
  329. ?>
  330. </p>
  331. </div>
  332. </body>
  333. </html>