From 7fc38bcf657902635a80f7e239c0bf13b397667c Mon Sep 17 00:00:00 2001 From: Paul Baranowski Date: Wed, 9 Mar 2011 19:06:15 -0500 Subject: [PATCH 1/2] Added license info for ecasound to 3rd party software documentation. --- LICENSE_3RD_PARTY | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LICENSE_3RD_PARTY b/LICENSE_3RD_PARTY index 9a89df2d2..892af37a1 100644 --- a/LICENSE_3RD_PARTY +++ b/LICENSE_3RD_PARTY @@ -58,6 +58,10 @@ Non-linked code: * mp3cut from the package poc-streamer + * ecasound 2.7.2 + - Web site: http://www.eca.cx/ecasound/ + - License: GPLv2 + * jQuery - Web site: http://jquery.com/ - License: MIT and GPL. See http://jquery.org/license From ef0bb8ed78ba23641b9c8fcc08db58d182a8c106 Mon Sep 17 00:00:00 2001 From: Paul Baranowski Date: Wed, 16 Mar 2011 13:21:40 -0400 Subject: [PATCH 2/2] Moved all install functions into an AirtimeInstall class. Formatted all the install files according to our code formatting standards. Output more info if something goes wrong during DB create or DB user create. --- install/airtime-install.php | 24 ++- install/airtime-uninstall.php | 47 ++--- install/airtime-upgrade.php | 6 +- install/installInit.php | 325 +++++++++++++++++----------------- utils/CleanStor.php | 4 +- 5 files changed, 205 insertions(+), 201 deletions(-) diff --git a/install/airtime-install.php b/install/airtime-install.php index 984928e74..7402b5355 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -1,7 +1,6 @@ /dev/null"); diff --git a/install/airtime-uninstall.php b/install/airtime-uninstall.php index 5f425610d..181006efd 100644 --- a/install/airtime-uninstall.php +++ b/install/airtime-uninstall.php @@ -18,13 +18,13 @@ require_once(dirname(__FILE__).'/../application/configs/conf.php'); require_once(dirname(__FILE__).'/installInit.php'); // Need to check that we are superuser before running this. -checkIfRoot(); +AirtimeInstall::ExitIfNotRoot(); echo "******************************* Uninstall Begin ********************************".PHP_EOL; //------------------------------------------------------------------------ // Delete the database -// Note: Do not put a call to airtime_db_connect() +// Note: Do not put a call to AirtimeInstall::DbConnect() // before this function, even if you called $CC_DBC->disconnect(), there will // still be a connection to the database and you wont be able to delete it. //------------------------------------------------------------------------ @@ -37,26 +37,29 @@ $command = "sudo -u postgres dropdb {$CC_CONFIG['dsn']['database']} 2> /dev/null // We do this if dropping the database fails above. //------------------------------------------------------------------------ if ($dbDeleteFailed) { - echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL; - airtime_db_connect(true); + echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL; + AirtimeInstall::DbConnect(true); - if (!PEAR::isError($CC_DBC)) { - $sql = "select * from pg_tables where tableowner = 'airtime'"; - $rows = airtime_get_query($sql); + if (!PEAR::isError($CC_DBC)) { + $sql = "select * from pg_tables where tableowner = 'airtime'"; + $rows = $CC_DBC->GetAll($sql); + if (PEAR::isError($result)) { + $rows = array(); + } - foreach ($rows as $row){ - $tablename = $row["tablename"]; - echo " * Removing database table $tablename..."; + foreach ($rows as $row) { + $tablename = $row["tablename"]; + echo " * Removing database table $tablename..."; - if (airtime_db_table_exists($tablename)){ - $sql = "DROP TABLE $tablename CASCADE"; - airtime_install_query($sql, false); - - $CC_DBC->dropSequence($tablename."_id"); - } - echo "done.".PHP_EOL; - } - } + if (AirtimeInstall::DbTableExists($tablename)){ + $sql = "DROP TABLE $tablename CASCADE"; + AirtimeInstall::InstallQuery($sql, false); + + $CC_DBC->dropSequence($tablename."_id"); + } + echo "done.".PHP_EOL; + } + } } //------------------------------------------------------------------------ @@ -66,16 +69,16 @@ echo " * Deleting database user '{$CC_CONFIG['dsn']['username']}'...".PHP_EOL; $command = "sudo -u postgres psql postgres --command \"DROP USER {$CC_CONFIG['dsn']['username']}\" 2> /dev/null"; @exec($command, $output, $results); if ($results == 0) { - echo " * User '{$CC_CONFIG['dsn']['username']}' deleted.".PHP_EOL; + echo " * User '{$CC_CONFIG['dsn']['username']}' deleted.".PHP_EOL; } else { - echo " * Nothing to delete..".PHP_EOL; + echo " * Nothing to delete..".PHP_EOL; } //------------------------------------------------------------------------ // Delete files //------------------------------------------------------------------------ -airtime_uninstall_delete_files($CC_CONFIG['storageDir']); +AirtimeInstall::DeleteFilesRecursive($CC_CONFIG['storageDir']); $command = "python ".__DIR__."/../pypo/install/pypo-uninstall.py"; diff --git a/install/airtime-upgrade.php b/install/airtime-upgrade.php index ebb84a970..7d6fd3bdb 100644 --- a/install/airtime-upgrade.php +++ b/install/airtime-upgrade.php @@ -17,13 +17,13 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) { require_once(dirname(__FILE__).'/installInit.php'); -checkIfRoot(); +AirtimeInstall::ExitIfNotRoot(); echo "******************************** Update Begin *********************************".PHP_EOL; -updateINIKeyValues('../build/build.properties', 'project.home', realpath(__dir__.'/../')); +AirtimeInstall::UpdateIniValue('../build/build.properties', 'project.home', realpath(__dir__.'/../')); echo PHP_EOL."*** Updating Database Tables ***".PHP_EOL; -doctrineMigrateTables(__DIR__); +AirtimeInstall::MigrateTables(__DIR__); echo PHP_EOL."*** Updating Pypo ***".PHP_EOL; system("python ".__DIR__."/../pypo/install/pypo-install.py"); diff --git a/install/installInit.php b/install/installInit.php index 251907cd9..6723b063a 100644 --- a/install/installInit.php +++ b/install/installInit.php @@ -7,190 +7,193 @@ if (!function_exists('pg_connect')) { require_once(dirname(__FILE__).'/../library/pear/DB.php'); require_once(dirname(__FILE__).'/../application/configs/conf.php'); -function airtime_db_table_exists($p_name) -{ - global $CC_DBC; - $sql = "SELECT * FROM ".$p_name; - $result = $CC_DBC->GetOne($sql); - if (PEAR::isError($result)) { - return false; - } - return true; -} +class AirtimeInstall { -function airtime_get_query($sql) -{ - global $CC_DBC; - $result = $CC_DBC->GetAll($sql); - if (PEAR::isError($result)) { - return array(); + static function DbTableExists($p_name) + { + global $CC_DBC; + $sql = "SELECT * FROM ".$p_name; + $result = $CC_DBC->GetOne($sql); + if (PEAR::isError($result)) { + return false; + } + return true; } - return $result; -} -function airtime_install_query($sql, $verbose = true) -{ - global $CC_DBC; - $result = $CC_DBC->query($sql); - if (PEAR::isError($result)) { - echo "Error! ".$result->getMessage()."\n"; - echo " SQL statement was:\n"; - echo " ".$sql."\n\n"; - } else { - if ($verbose) { - echo "done.\n"; + static function InstallQuery($sql, $verbose = true) + { + global $CC_DBC; + $result = $CC_DBC->query($sql); + if (PEAR::isError($result)) { + echo "Error! ".$result->getMessage()."\n"; + echo " SQL statement was:\n"; + echo " ".$sql."\n\n"; + } else { + if ($verbose) { + echo "done.\n"; + } } } -} -function airtime_db_connect($p_exitOnError = true) { - global $CC_DBC, $CC_CONFIG; - $CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); - if (PEAR::isError($CC_DBC)) { - echo $CC_DBC->getMessage().PHP_EOL; - echo $CC_DBC->getUserInfo().PHP_EOL; - echo "Database connection problem.".PHP_EOL; - echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists". - " with corresponding permissions.".PHP_EOL; - if ($p_exitOnError) { + static function DbConnect($p_exitOnError = true) + { + global $CC_DBC, $CC_CONFIG; + $CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); + if (PEAR::isError($CC_DBC)) { + echo $CC_DBC->getMessage().PHP_EOL; + echo $CC_DBC->getUserInfo().PHP_EOL; + echo "Database connection problem.".PHP_EOL; + echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists". + " with corresponding permissions.".PHP_EOL; + if ($p_exitOnError) { + exit(1); + } + } else { + echo "* Connected to database".PHP_EOL; + $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); + } + } + + static function ChangeDirOwnerToWebserver($filePath) + { + global $CC_CONFIG; + $success = chgrp($filePath, $CC_CONFIG["webServerUser"]); + $fileperms=@fileperms($filePath); + $fileperms = $fileperms | 0x0010; // group write bit + $fileperms = $fileperms | 0x0400; // group sticky bit + chmod($filePath, $fileperms); + } + + private static function GenerateRandomString($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') + { + $string = ''; + for ($i = 0; $i < $len; $i++) + { + $pos = mt_rand(0, strlen($chars)-1); + $string .= $chars{$pos}; + } + return $string; + } + + public static function CreateApiKey() + { + $api_key = AirtimeInstall::GenerateRandomString(); + AirtimeInstall::UpdateIniValue(__DIR__.'/../build/airtime.conf', 'api_key', $api_key); + AirtimeInstall::UpdateIniValue(__DIR__.'/../pypo/config.cfg', 'api_key', "'$api_key'"); + } + + public static function ExitIfNotRoot() + { + // Need to check that we are superuser before running this. + if(exec("whoami") != "root"){ + echo "Must be root user.\n"; exit(1); } - } else { - echo "* Connected to database".PHP_EOL; - $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); } -} -function install_setDirPermissions($filePath) { - global $CC_CONFIG; - $success = chgrp($filePath, $CC_CONFIG["webServerUser"]); - $fileperms=@fileperms($filePath); - $fileperms = $fileperms | 0x0010; // group write bit - $fileperms = $fileperms | 0x0400; // group sticky bit - chmod($filePath, $fileperms); -} - -function rand_string($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') -{ - $string = ''; - for ($i = 0; $i < $len; $i++) + public static function UpdateIniValue($filename, $property, $value) { - $pos = mt_rand(0, strlen($chars)-1); - $string .= $chars{$pos}; - } - return $string; -} - -function createAPIKey(){ - - $api_key = rand_string(); - updateINIKeyValues(__DIR__.'/../build/airtime.conf', 'api_key', $api_key); - updateINIKeyValues(__DIR__.'/../pypo/config.cfg', 'api_key', "'$api_key'"); -} - -function checkIfRoot(){ - // Need to check that we are superuser before running this. - if(exec("whoami") != "root"){ - echo "Must be root user.\n"; - exit(1); - } -} - -function updateINIKeyValues($filename, $property, $value){ - $lines = file($filename); - $n=count($lines); - for ($i=0; $i<$n; $i++) { - if (strlen($lines[$i]) > strlen($property)) + $lines = file($filename); + $n=count($lines); + for ($i=0; $i<$n; $i++) { + if (strlen($lines[$i]) > strlen($property)) if ($property == substr($lines[$i], 0, strlen($property))){ $lines[$i] = "$property = $value\n"; } - } - - $fp=fopen($filename, 'w'); - for($i=0; $i<$n; $i++){ - fwrite($fp, $lines[$i]); - } - fclose($fp); -} - -function storageDirectorySetup($CC_CONFIG){ - global $CC_CONFIG, $CC_DBC; - - echo PHP_EOL."*** Directory Setup ***".PHP_EOL; - foreach (array('baseFilesDir', 'storageDir') as $d) { - if ( !file_exists($CC_CONFIG[$d]) ) { - @mkdir($CC_CONFIG[$d], 02775, true); - if (file_exists($CC_CONFIG[$d])) { - $rp = realpath($CC_CONFIG[$d]); - echo "* Directory $rp created".PHP_EOL; - } else { - echo "* Failed creating {$CC_CONFIG[$d]}".PHP_EOL; - exit(1); - } - } elseif (is_writable($CC_CONFIG[$d])) { - $rp = realpath($CC_CONFIG[$d]); - echo "* Skipping directory already exists: $rp".PHP_EOL; - } else { - $rp = realpath($CC_CONFIG[$d]); - echo "* WARNING: Directory already exists, but is not writable: $rp".PHP_EOL; } - $CC_CONFIG[$d] = $rp; + + $fp=fopen($filename, 'w'); + for($i=0; $i<$n; $i++){ + fwrite($fp, $lines[$i]); + } + fclose($fp); } -} -function createAirtimeDatabaseUser(){ - global $CC_CONFIG; - // Create the database user - $command = "sudo -u postgres psql postgres --command \"CREATE USER {$CC_CONFIG['dsn']['username']} " - ." ENCRYPTED PASSWORD '{$CC_CONFIG['dsn']['password']}' LOGIN CREATEDB NOCREATEUSER;\" 2>/dev/null"; - - @exec($command, $output, $results); - if ($results == 0) { - echo "* User {$CC_CONFIG['dsn']['username']} created.".PHP_EOL; - } else { - echo "* User {$CC_CONFIG['dsn']['username']} already exists.".PHP_EOL; + public static function SetupStorageDirectory($CC_CONFIG) + { + global $CC_CONFIG, $CC_DBC; + + echo PHP_EOL."*** Directory Setup ***".PHP_EOL; + foreach (array('baseFilesDir', 'storageDir') as $d) { + if ( !file_exists($CC_CONFIG[$d]) ) { + @mkdir($CC_CONFIG[$d], 02775, true); + if (file_exists($CC_CONFIG[$d])) { + $rp = realpath($CC_CONFIG[$d]); + echo "* Directory $rp created".PHP_EOL; + } else { + echo "* Failed creating {$CC_CONFIG[$d]}".PHP_EOL; + exit(1); + } + } elseif (is_writable($CC_CONFIG[$d])) { + $rp = realpath($CC_CONFIG[$d]); + echo "* Skipping directory already exists: $rp".PHP_EOL; + } else { + $rp = realpath($CC_CONFIG[$d]); + echo "* WARNING: Directory already exists, but is not writable: $rp".PHP_EOL; + } + $CC_CONFIG[$d] = $rp; + } } -} -function createAirtimeDatabase(){ - global $CC_CONFIG; - - $command = "sudo -u postgres createdb {$CC_CONFIG['dsn']['database']} --owner {$CC_CONFIG['dsn']['username']} 2> /dev/null"; - @exec($command, $output, $results); - if ($results == 0) { - echo "* Database '{$CC_CONFIG['dsn']['database']}' created.".PHP_EOL; - } else { - echo "* Database '{$CC_CONFIG['dsn']['database']}' already exists.".PHP_EOL; + public static function CreateDatabaseUser() + { + global $CC_CONFIG; + // Create the database user + $command = "sudo -u postgres psql postgres --command \"CREATE USER {$CC_CONFIG['dsn']['username']} " + ." ENCRYPTED PASSWORD '{$CC_CONFIG['dsn']['password']}' LOGIN CREATEDB NOCREATEUSER;\" 2>/dev/null"; + + @exec($command, $output, $results); + if ($results == 0) { + echo "* User {$CC_CONFIG['dsn']['username']} created.".PHP_EOL; + } else { + echo "* Could not create user {$CC_CONFIG['dsn']['username']}: $output".PHP_EOL; + } } -} -function installPostgresScriptingLanguage(){ - global $CC_DBC; - // Install postgres scripting language - $langIsInstalled = $CC_DBC->GetOne('SELECT COUNT(*) FROM pg_language WHERE lanname = \'plpgsql\''); - if ($langIsInstalled == '0') { - echo "* Installing Postgres scripting language".PHP_EOL; - $sql = "CREATE LANGUAGE 'plpgsql'"; - airtime_install_query($sql, false); - } else { - echo "* Postgres scripting language already installed".PHP_EOL; + public static function CreateDatabase() + { + global $CC_CONFIG; + + $command = "sudo -u postgres createdb {$CC_CONFIG['dsn']['database']} --owner {$CC_CONFIG['dsn']['username']} 2> /dev/null"; + @exec($command, $output, $results); + if ($results == 0) { + echo "* Database '{$CC_CONFIG['dsn']['database']}' created.".PHP_EOL; + } else { + echo "* Could not create database '{$CC_CONFIG['dsn']['database']}': $output".PHP_EOL; + } } -} + public static function InstallPostgresScriptingLanguage() + { + global $CC_DBC; + // Install postgres scripting language + $langIsInstalled = $CC_DBC->GetOne('SELECT COUNT(*) FROM pg_language WHERE lanname = \'plpgsql\''); + if ($langIsInstalled == '0') { + echo "* Installing Postgres scripting language".PHP_EOL; + $sql = "CREATE LANGUAGE 'plpgsql'"; + AirtimeInstall::InstallQuery($sql, false); + } else { + echo "* Postgres scripting language already installed".PHP_EOL; + } + } -function createAirtimeDatabaseTables(){ - // Put Propel sql files in Database - $command = __DIR__."/../library/propel/generator/bin/propel-gen ../build/ insert-sql 2>propel-error.log"; - @exec($command, $output, $results); -} + public static function CreateDatabaseTables() + { + // Put Propel sql files in Database + $command = __DIR__."/../library/propel/generator/bin/propel-gen ../build/ insert-sql 2>propel-error.log"; + @exec($command, $output, $results); + } -function doctrineMigrateTables($dir){ - $command = "php $dir/../library/doctrine/migrations/doctrine-migrations.phar --configuration=$dir/DoctrineMigrations/migrations.xml --db-configuration=$dir/../library/doctrine/migrations/migrations-db.php --no-interaction migrations:migrate"; - system($command); -} + public static function MigrateTables($dir) + { + $command = "php $dir/../library/doctrine/migrations/doctrine-migrations.phar --configuration=$dir/DoctrineMigrations/migrations.xml --db-configuration=$dir/../library/doctrine/migrations/migrations-db.php --no-interaction migrations:migrate"; + system($command); + } -function airtime_uninstall_delete_files($p_path) -{ - $command = "rm -rf $p_path"; - exec($command); -} + public static function DeleteFilesRecursive($p_path) + { + $command = "rm -rf $p_path"; + exec($command); + } + +} \ No newline at end of file diff --git a/utils/CleanStor.php b/utils/CleanStor.php index c9111248d..1b4ed9f97 100644 --- a/utils/CleanStor.php +++ b/utils/CleanStor.php @@ -84,10 +84,10 @@ function airtime_empty_db($db) { global $CC_CONFIG; if (!PEAR::isError($db)) { - if (airtime_db_table_exists($CC_CONFIG['filesTable'])) { + if (AirtimeInstall::DbTableExists($CC_CONFIG['filesTable'])) { echo " * Deleting from database table ".$CC_CONFIG['filesTable']."\n"; $sql = "DELETE FROM ".$CC_CONFIG['filesTable']; - airtime_install_query($sql, false); + AirtimeInstall::InstallQuery($sql, false); } else { echo " * Skipping: database table ".$CC_CONFIG['filesTable']."\n";