diff --git a/www/Git_Access.txt b/www/Git_Access.txt new file mode 100644 index 0000000000000000000000000000000000000000..9596c5a62bb9c6fe3c3e6a6dd499b1a3eaf3ebba --- /dev/null +++ b/www/Git_Access.txt @@ -0,0 +1,35 @@ +// AsciiDoc file + + +Git anonymous access +-------------------- + + + +To access SFLphone's git repository (read-only): + +--------------------------------------------- +git clone git://sflphone.org/git/sflphone.git +--------------------------------------------- + + + + + +Git developer's access +---------------------- + +Run: + +-------------------------------------------------------------- +ssh-kengen -C sflphone_org@sflphone.org +cat ~/.ssh/id_rsa.pub +-------------------------------------------------------------- + +and transmit us the content of the `id_rsa.pub` file, for shared-key +authentication. Then: + +-------------------------------------------------------------- +git clone git+ssh://sflphone_org@sflphone.org/git/sflphone.git +-------------------------------------------------------------- + diff --git a/www/config.inc.php b/www/config.inc.php new file mode 100644 index 0000000000000000000000000000000000000000..6633c38a8a56807ce228784080759d977c6abc72 --- /dev/null +++ b/www/config.inc.php @@ -0,0 +1,20 @@ +<?php + +/** + * SFLphone website configuration file + */ + + +/** Git repository */ +$GIT_REPOS = '../.git'; + +/** Use the branch for fetching latest revs. of pages */ +$USE_BRANCH = 'master'; + +/** Cache path */ +$CACHE_PATH = 'cache'; + +/** File prefix (inside the git trees) */ +$PREFIX = 'www'; + +?> \ No newline at end of file diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000000000000000000000000000000000000..6cb9af5e604a83e46f2b0faa4768f28af75520f3 --- /dev/null +++ b/www/index.php @@ -0,0 +1,10 @@ +<?php + +include('sflphone.funcs.php'); + + + + + + +?> \ No newline at end of file diff --git a/www/sflphone.funcs.php b/www/sflphone.funcs.php new file mode 100644 index 0000000000000000000000000000000000000000..cf270356aa86353197971bcb963538b094fbc16d --- /dev/null +++ b/www/sflphone.funcs.php @@ -0,0 +1,196 @@ +<?php + +/** + * Copyright (C) 2007 - Savoir-Faire Linux Inc. + * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> + * + * LICENCE: GPL + */ + + +require_once('config.inc.php'); + + +/** + * Helper functions to translate AsciiDoc files into HTML, display + * them and cache them. + */ + + +/** + * Show page, compile it if new, cache it. + * + * @return HTML content + */ +function show_page($page) { + // Compile it + + // Get the latest HASH for that page. + $hash = get_git_hash($page); + + $cnt = get_cache_hash($hash); + + if (!$cnt) { + $cnt = compile_page($hash, $page /* for ref only */); + + put_cache_hash($hash, $cnt); + + return $cnt; + } + + return $cnt; + +} + + +/** + * Create the Cache dir if it doesn't exist. + */ +function check_cache_path() { + global $CACHE_PATH; + + if (!file_exists($CACHE_PATH)) { + mkdir($CACHE_PATH); + } +} + + +/** + * Check if the cache dir if this object was cached, if so, return it. + * + * @return mixed NULL or the content of the cache + */ +function get_cache_hash($hash) { + global $CACHE_PATH; + + $fn = $CACHE_PATH.'/'.$hash.'.cache'; + + if (file_exists($fn)) { + return file_get_contents($fn); + } + + return NULL; +} + + +/** + * Write content to cache (identified by $hash) + */ +function put_cache_hash($hash, $content) { + global $CACHE_PÂTH; + + $fn = $CACHE_PATH.'/'.$hash.'.cache'; + + file_put_contents($fn, $content); + + return true; +} + + +/** + * Just compile the page + * + * @return string Content of the compiled page. + */ +function compile_page($hash, $page) { + global $GIT_REPOS; + + $output = ''; + + $p = popen("GIT_DIR=".$GIT_REPOS." git-show $hash | asciidoc -", 'r'); + + if (!$p) { + return "Unable to compile file: $page ($hash)\n"; + } + + while (!feof($p)) { + $output .= fread($p); + } + pclose($p); + + return $output; +} + + +/** + * Retrieve file from git's object-ocean + * + * UNUSED + */ +function get_git_file_content($file) { + $hash = get_git_hash($file); + + $content = get_git_hash_content($hash); + + return $content; +} + + +/** + * Retrieve hash's content from git's object-ocean + * + * UNUSED + */ +function get_git_hash_content($hash) { + global $GIT_REPOS; + + $content = exec("GIT_DIR=".$GIT_REPOS." git-show $hash"); + + return $content; +} + +/** + * Get the file's SHA-1 hash, for the latest revision on USE_BRANCH + * + * Used for comparison of cached/to cache/cache filename. + * + * @return string SHA-1 hash + */ +function get_git_hash($file) { + global $USE_BRANCH, $GIT_REPOS; + + $output = array(); + + $string = exec("GIT_DIR=".$GIT_REPOS." git-ls-tree $USE_BRANCH \"".git_filename($file)."\"", $output); + + if (count($output)) { + $fields = explode(' ', $output[0]); + + if ($fields[1] == 'blob') { + // Return the HASH + return $fields[2]; + } + } + + return NULL; +} + +/** + * Get file name (parsed and clear for git-ls-tree) + * + * @return string Parsed file name + */ +function git_filename($file) { + global $PREFIX; + // remove all '//', for '/', remove the trailing '/' at the beginning + // add the PREFIX + + $out = $PREFIX . '/' . $file; + + $out = str_replace('//', '/', $out); + $out = str_replace('//', '/', $out); // In case there are 3 in a row + + $out = ltrim($out, '/'); + + return $out; +} + + + + +/** Check cache path right away, at each run. */ + +check_cache_path(); + + +?> \ No newline at end of file