* @version $Revision: 2475 $ * @package Campcaster * @subpackage StorageServer * @copyright 2006 MDLF, Inc. * @license http://www.gnu.org/licenses/gpl.txt * @link http://www.campware.org */ // Do not allow remote execution $arr = array_diff_assoc($_SERVER, $_ENV); if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) { header("HTTP/1.1 400"); header("Content-type: text/plain; charset=UTF-8"); echo "400 Not executable\r\n"; exit(1); } //------------------------------------------------------------------------------ // Install database tables //------------------------------------------------------------------------------ if (!camp_db_table_exists($CC_CONFIG['treeTable'])) { echo " * Creating database table ".$CC_CONFIG['treeTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['treeTable']." ( id int not null PRIMARY KEY, name varchar(255) not null default'', -- parid int, type varchar(255) not null default'', param varchar(255))"; camp_install_query($sql, false); $CC_DBC->createSequence($CC_CONFIG['treeTable']."_id_seq"); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['treeTable']."_id_idx ON ".$CC_CONFIG['treeTable']." (id)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['treeTable']."_name_idx ON ".$CC_CONFIG['treeTable']." (name)"; camp_install_query($sql); } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['treeTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['structTable'])) { echo " * Creating database table ".$CC_CONFIG['structTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['structTable']." ( rid int not null PRIMARY KEY, objid int not null REFERENCES ".$CC_CONFIG['treeTable']." ON DELETE CASCADE, parid int not null REFERENCES ".$CC_CONFIG['treeTable']." ON DELETE CASCADE, level int)"; camp_install_query($sql, false); $CC_DBC->createSequence($CC_CONFIG['structTable']."_id_seq"); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['structTable']."_rid_idx ON ".$CC_CONFIG['structTable']." (rid)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['structTable']."_objid_idx ON ".$CC_CONFIG['structTable']." (objid)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['structTable']."_parid_idx ON ".$CC_CONFIG['structTable']." (parid)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['structTable']."_level_idx ON ".$CC_CONFIG['structTable']." (level)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['structTable']."_objid_level_idx ON ".$CC_CONFIG['structTable']." (objid, level)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['structTable']."_objid_parid_idx ON ".$CC_CONFIG['structTable']." (objid, parid)"; camp_install_query($sql); } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['structTable']."\n"; } // // Insert the RootNode if its not there yet. // $sql = "SELECT * FROM ".$CC_CONFIG['treeTable'] ." WHERE name='".$CC_CONFIG['RootNode']."'" ." AND type='RootNode'"; $row = $CC_DBC->GetRow($sql); if (!PEAR::isError($row) && !$row) { echo " * Creating ROOT NODE in ".$CC_CONFIG['treeTable']."..."; $oid = $CC_DBC->nextId($CC_CONFIG['treeTable']."_id_seq"); if (PEAR::isError($oid)) { echo $oid->getMessage()."\n"; //print_r($oid); exit(); } $CC_DBC->query(" INSERT INTO ".$CC_CONFIG['treeTable']." (id, name, type) VALUES ($oid, '".$CC_CONFIG['RootNode']."', 'RootNode') "); echo "done.\n"; } else { echo " * Skipping: Root node already exists in ".$CC_CONFIG['treeTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['classTable'])) { echo " * Creating database table ".$CC_CONFIG['classTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['classTable']." ( id int not null PRIMARY KEY, cname varchar(20))"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['classTable']."_id_idx ON ".$CC_CONFIG['classTable']." (id)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['classTable']."_cname_idx ON ".$CC_CONFIG['classTable']." (cname)"; camp_install_query($sql); } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['classTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['cmembTable'])) { echo " * Creating database table ".$CC_CONFIG['cmembTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['cmembTable']." ( objid int not null, cid int not null)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['cmembTable']."_idx ON ".$CC_CONFIG['cmembTable']." (objid, cid)"; camp_install_query($sql); } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['cmembTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['subjTable'])) { echo " * Creating database table ".$CC_CONFIG['subjTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['subjTable']." ( id int not null PRIMARY KEY, login varchar(255) not null default'', pass varchar(255) not null default'', type char(1) not null default 'U', realname varchar(255) not null default'', lastlogin timestamp, lastfail timestamp )"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['subjTable']."_id_idx ON ".$CC_CONFIG['subjTable']." (id)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['subjTable']."_login_idx ON ".$CC_CONFIG['subjTable']." (login)"; camp_install_query($sql, false); $CC_DBC->createSequence($CC_CONFIG['subjTable']."_id_seq"); echo "done.\n"; } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['subjTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['smembTable'])) { echo " * Creating database table ".$CC_CONFIG['smembTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['smembTable']." ( id int not null PRIMARY KEY, uid int not null default 0, gid int not null default 0, level int not null default 0, mid int)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['smembTable']."_id_idx ON ".$CC_CONFIG['smembTable']." (id)"; camp_install_query($sql, false); $CC_DBC->createSequence($CC_CONFIG['smembTable']."_id_seq"); echo "done.\n"; } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['smembTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['permTable'])) { echo " * Creating database table ".$CC_CONFIG['permTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['permTable']." ( permid int not null PRIMARY KEY, subj int REFERENCES ".$CC_CONFIG['subjTable']." ON DELETE CASCADE, action varchar(20), obj int, type char(1))"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['permTable']."_permid_idx ON ".$CC_CONFIG['permTable']." (permid)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['permTable']."_subj_obj_idx ON ".$CC_CONFIG['permTable']." (subj, obj)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['permTable']."_all_idx ON ".$CC_CONFIG['permTable']." (subj, action, obj)"; camp_install_query($sql, false); $CC_DBC->createSequence($CC_CONFIG['permTable']."_id_seq"); echo "done.\n"; } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['permTable']."\n"; } if (!camp_db_table_exists($CC_CONFIG['sessTable'])) { echo " * Creating database table ".$CC_CONFIG['sessTable']."..."; $sql = "CREATE TABLE ".$CC_CONFIG['sessTable']." ( sessid char(32) not null PRIMARY KEY, userid int REFERENCES ".$CC_CONFIG['subjTable']." ON DELETE CASCADE, login varchar(255), ts timestamp)"; camp_install_query($sql, false); $sql = "CREATE UNIQUE INDEX ".$CC_CONFIG['sessTable']."_sessid_idx ON ".$CC_CONFIG['sessTable']." (sessid)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['sessTable']."_userid_idx ON ".$CC_CONFIG['sessTable']." (userid)"; camp_install_query($sql, false); $sql = "CREATE INDEX ".$CC_CONFIG['sessTable']."_login_idx ON ".$CC_CONFIG['sessTable']." (login)"; camp_install_query($sql); } else { echo " * Skipping: database table already exists: ".$CC_CONFIG['sessTable']."\n"; } /** * file states: *