From: paulr Date: Tue, 19 Apr 2011 17:50:05 +0000 (+1000) Subject: file datastore work X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=38f5cf40e82e0d3cc9bcc52cf5710f883dd3447a;p=glcas.git file datastore work --- diff --git a/doc/globals.txt b/doc/globals.txt new file mode 100644 index 0000000..e77fa2d --- /dev/null +++ b/doc/globals.txt @@ -0,0 +1,8 @@ +$BASE_URLS["ypc"]["base"] = "ypc"; // ap for apt-proxy +$BASE_URLS["ypc"]["function"] = "yp_contentUrlsCtl"; + +$MENU_ITEMS["yp"]["title"] = "YUM Proxy"; +$MENU_ITEMS["yp"]["link"] = "/ypc/proxycontrol"; + +$GLOBAL_BASE_URL="/src/eclipse-workspace/glcas/www/"; +$DB_URL="sqlite:$BASE_DIR/var/ds_store.db"; diff --git a/lib/lib.php b/lib/lib.php index 2a5ace8..e446b09 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -3,8 +3,13 @@ require_once("config.php"); require_once("wsdl.php"); + // first and foremost, load the plugins $basedir = dirname(__FILE__); + +// we load this first +if(file_exists("$basedir/plugins/www.php")) require_once("$basedir/plugins/www.php"); + if(is_dir("$basedir/plugins")) { $dh = opendir("$basedir/plugins"); if($dh) { diff --git a/lib/plugins/aptproxy.php b/lib/plugins/aptproxy.php index 65d0c0d..161ade2 100644 --- a/lib/plugins/aptproxy.php +++ b/lib/plugins/aptproxy.php @@ -1,6 +1,32 @@ "; +} + +function ap_leftMenu() +{ + echo "i am a ap leftmenu"; +} + + ?> \ No newline at end of file diff --git a/lib/plugins/datastore.php b/lib/plugins/datastore.php index ccaca5c..16ae107 100644 --- a/lib/plugins/datastore.php +++ b/lib/plugins/datastore.php @@ -4,7 +4,7 @@ global $BASE_URLS, $MENU_ITEMS, $GLOBAL_BASE_URL; $BASE_URLS["ds"]["base"] = "ds"; // ap for apt-proxy $BASE_URLS["ds"]["function"] = "ds_contentUrls"; // the page builder function for us $MENU_ITEMS["ds"]["title"] = "DataStores"; -$MENU_ITEMS["ds"]["link"] = "$GLOBAL_BASE_URL/ds/control"; +$MENU_ITEMS["ds"]["link"] = "/ds/control"; function ds_contentPane() @@ -28,11 +28,64 @@ function ds_contentUrls() function ds_createDS($ds_name, $store_location) { + db_createTable("datastores", "dsname", "dslocation"); + db_createTable("datastores_files", "dsname", "fileowner", "filename", "dsfname"); + $data = db_selectData("datastores", "dsname", "$ds_name"); + if(isset($data[0]["dsname"])) return false; + + db_insertData("datastores", "$ds_name", "$store_location"); +} + +function ds_listDS() +{ + return db_selectData("datastores"); +} + +function ds_deleteFile($ds_name, $file_name, $file_tag) +{ + $dlk = db_selectData("datastores_files", "filename", $file_name); + $afname = ""; + foreach($dlk as $kmm) { + if($kmm["fileowner"] == $file_tag) { + // we got ya + $afname = $kmm["dsfname"]; + if(file_exists($afname)) unlink($afname); + echo "name was: $afname\n"; + } + } + echo "now delete name was: $afname\n"; + if($afname != "") db_deleteData("datastores_files", "dsfname", $afname); +} + +// returns a file name to the location a file can be created +function ds_fileds($ds_name, $file_name, $file_tag) +{ + + $data = db_selectData("datastores", "dsname", "$ds_name"); + + $dtime = time(); + $made_file_name = "$dtime-".md5($file_name)."-".basename($file_name); + + $act_fname = $data[0]["dslocation"]."/".basename($made_file_name); + + db_insertData("datastores_files", "$ds_name", "$file_tag", "$file_name", "$act_fname"); + + return $act_fname; } -function ds_fileds($ds_name, $file_id, $file_name) +function ds_getFileList($ds_name, $file_tag) +{ + $list = db_selectData("datastores_files", "fileowner", "$file_tag"); + + return $list; +} + + +function ds_deleteDS($ds_name) { + db_deleteData("datastores", "dsname", "$ds_name"); + db_deleteData("datastores_files", "dsname", $ds_name); } function ds_downloadAndStore($ds_name, $file_id, $file_name, $file_url) diff --git a/lib/plugins/db.php b/lib/plugins/db.php index f19a1fa..1906157 100644 --- a/lib/plugins/db.php +++ b/lib/plugins/db.php @@ -29,6 +29,8 @@ function db_createTable($tablename) { $db = db_getDB(); + if(db_tableExists($tablename)) return true; + $sql = "create table \"$tablename\" (\"".$tablename."_id\" INTEGER PRIMARY KEY AUTOINCREMENT"; for($i=1; $i < func_num_args(); $i++) { $colname = func_get_arg($i); @@ -54,11 +56,13 @@ function db_insertData($tablename) $db->query($sql); } -function db_selectData($tablename, $column, $value) +function db_selectData($tablename, $column="", $value="") { $db = db_getDB(); - $sql = "select * from \"$tablename\" where $column like '%$value%'"; + if($column != "") $extra = " where $column like '%$value%'"; + else $extra = ""; + $sql = "select * from \"$tablename\"$extra"; $res = $db->query($sql); $data = $res->fetchAll(); @@ -69,7 +73,8 @@ function db_deleteData($tablename, $column, $value) { $db = db_getDB(); - $sql = "delete from \"$tablename\" where column_$column like '%$value%'"; + $sql = "delete from \"$tablename\" where $column like '%$value%'"; + //echo "Sql is $sql\n"; return $db->query($sql); } diff --git a/lib/plugins/www.php b/lib/plugins/www.php index 1738c23..d060677 100644 --- a/lib/plugins/www.php +++ b/lib/plugins/www.php @@ -4,24 +4,32 @@ global $BASE_URLS; $BASE_URLS["wp"]["base"] = ""; $BASE_URLS["wp"]["function"] = "wp_pageBuilder"; +$MENU_ITEMS["wp"]["title"] = "Home"; +$MENU_ITEMS["wp"]["link"] = "/"; function goWebProcessor($calls) { if(isset($calls["needs_base_page"])) { if($calls["needs_base_page"] == true) { // build page - echo "here base\n"; + // echo "here base\n"; www_basePage($calls); } else { $func = $calls["page_builder"]; $func(); } } else { - echo "here base 2\n"; www_basePage($calls); } } +function wp_pageBuilder() +{ + $calls["needs_base_page"] = true; + + return $calls; +} + function www_basePage($calls) { @@ -95,11 +103,14 @@ function www_top() echo "

Welcome to GLCAS

"; echo ""; - global $MENU_ITEMS; + global $MENU_ITEMS, $GLOBAL_BASE_URL; foreach($MENU_ITEMS as $mes) { $mtext = $mes["title"]; - $mlink = $mes["link"]; - echo ""; + $mlink = "$GLOBAL_BASE_URL/".$mes["link"]; + // remove the excess /'s + $mlink2 = preg_replace("/\/[\/]+/", "/", $mlink); + //echo "went from $mlink to $mlink2\n"; + echo ""; } echo "
$mtext$mtext
"; diff --git a/lib/plugins/yumproxy.php b/lib/plugins/yumproxy.php index 5db52a0..68c8768 100644 --- a/lib/plugins/yumproxy.php +++ b/lib/plugins/yumproxy.php @@ -6,7 +6,7 @@ $BASE_URLS["ypc"]["function"] = "yp_contentUrlsCtl"; // the page builder functio $BASE_URLS["ypr"]["base"] = "ypr"; // ap for apt-proxy $BASE_URLS["ypr"]["function"] = "yp_contentUrlsPrx"; // the page builder function for us $MENU_ITEMS["yp"]["title"] = "YUM Proxy"; -$MENU_ITEMS["yp"]["link"] = "$GLOBAL_BASE_URL/ypc/proxycontrol"; +$MENU_ITEMS["yp"]["link"] = "/ypc/proxycontrol"; function yp_contentPane() @@ -27,4 +27,17 @@ function yp_contentUrlsCtl() return $calls; } + +function yp_contentUrlsPrx() +{ + $calls["needs_base_page"] = false; + $calls["page_builder"] = "yp_proxyPageBuilder"; + + return $calls; +} + +function yp_proxyPageBuilder() +{ + echo "I write the songs that make the whole world sing"; +} ?> \ No newline at end of file diff --git a/unittests/datastores.php b/unittests/datastores.php new file mode 100644 index 0000000..f5313c4 --- /dev/null +++ b/unittests/datastores.php @@ -0,0 +1,62 @@ + \ No newline at end of file