@@ -0,0 +1,163 @@
2// This is part of MoniWiki and it is
3// distributable under GPL see COPYING
5// $Id: virtual.php,v 1.124 2003/12/19 13:48:17 wkpark Exp $
10 * Function - Find virtual sitename if available
12 * @param String virtual host name ( example: wiki.*.kldp.org)
13 * @param String virtual sitename (Sitename for %2)
14 * @return String virtual sitename or null
16function virtual_find_sitename($virtual_host, $virtual_sitename) {
17 // It's basically same with virtual find text dir
18 // Since virtual_sitename should "Sitename for %2"
19 return virtual_find_dir($virtual_host, $virtual_sitename);
23 * Function - General Find virtual directory if available
25 * @param String virtual host name ( example: wiki.*.kldp.org)
26 * @param String virtual directory (/var/%2/dir)
27 * @return String virtual dirrectory or null
29function virtual_find_dir($virtual_host, $virtual_dir) {
30 // No sutable arguments
31 if (!$virtual_host || !$virtual_dir) {
35 // Check if is my host
36 $host = $_SERVER['SERVER_NAME'];
37 if (!virtual_is_my_host($virtual_host, $host)) {
41 // Let's make a translate table
42 $host_arr = split('\.', $host);
43 for ($i=0; $i<count($host_arr); $i++) {
44 $tr_table['%'.$i] = $host_arr[$i];
47 // Replace %1, %2, %3 to real name
48 $dir = strtr($virtual_dir, $tr_table);
53 * Function - Create virtual directory if available
55 * @param String text firectory
56 * @param String Only create if referer is the virtual_ref
57 * @param 0 or 1 Weather copy seed or not
58 * @param String Wiki Seed directory
61function virtual_create_dir($text_dir, $virtual_ref,
62 $is_text_dir=0, $auto_seed=0, $seed_dir="wikiseed") {
65 if (is_dir($text_dir)) {
71 $referer = $_SERVER['HTTP_REFERER'];
72 if (!fnmatch($virtual_ref, $referer)) {
77 //#FIXME: Handle Any errors?
81 // RCS directory to keep RCS files
82 mkdir($text_dir."/RCS");
85 touch(virtual_edit_log($text_dir));
88 // Not auto seed so all set
93 if (!is_dir($seed_dir)) {
98 $handle= opendir($seed_dir);
99 while ($file = readdir($handle)) {
100 // We don't copy directories
101 if (is_dir($seed_dir.'/'.$file)) {
105 //#FIXME: Handle errors?
106 copy($seed_dir.'/'.$file, $text_dir.'/'.$file);
113 * Function - Return edit log for virtual text dire
115 * @param String virtual text_dir
116 * @return String edit log
118function virtual_edit_log($text_dir) {
119 return dirname($text_dir).'/'. basename($text_dir).".editlog";
124 * Function - Check if it is my virtual host
126 * @param String virtual host
127 * @param String hostname
128 * @return true if it is my host. Otherwise false.
130function virtual_is_my_host($virtual_host, $host) {
131 // Tokenize and put the into array
132 $virtual_host_arr = split ('\.', $virtual_host);
133 $host_arr = split("\.", $host);
135 // Diffrent number of array
136 //# FIXME: www.kldp.net.. and www.kld.net have diffrent counter.
139 if (count($virtual_host_arr) != count($host_arr)) {
145 for($i=0; $i< count($host_arr); $i++) {
146 $virtual_one_name = $virtual_host_arr[$i];
147 // We expecting * or real name
148 if ($virtual_one_name == "*") { // Assume match
152 $host_one_name = $host_arr[$i];
155 if ($host_one_name && strcasecmp($virtual_one_name, $host_one_name)) {
160 // Passed all match tests