'repos' , 'paths' => 'repo_paths' , 'guests' => 'repo_guests' , 'rights' => 'repo_rights' , 'groups' => 'repo_groups' , 'gr_mem' => 'repo_group_members' , 'stats' => 'repo_stats' , 'tots' => 'repo_tots' , 'xusers' => 'repo_xusers' , 'roots' => 'repo_roots' , 'mods' => 'repo_mods' ) ; function TBL ( $x ) { GLOBAL $TBL_NAMES ; $name = $x ; if ( $TBL_NAMES [ $x ] ) { $name = $TBL_NAMES [ $x ] ; } return Conf ( 'db_pref' ) . $name ; } function _empty ( $x ) { return ( $x == 'EMPTY' ? '' : $x ) ; } function _split ( $v, $n = 0 ) { $res = array () ; $row = preg_split ( '/\s+/', $v, $n, PREG_SPLIT_NO_EMPTY ) ; foreach ( $row as $x ) { $res [] = _empty ( $x ) ; } return $res ; } class Config { # there will be only one instance # access as Conf ( 'key' ) or Conf () -> key function Config () { GLOBAL $CONF_ROOT ; $this -> init () ; $this -> get_conf ( $CONF_ROOT ) ; # order is important here $this -> _make_ldaps () ; $this -> _make_clas_list () ; $this -> _make_clases () ; $this -> _make_trees () ; $this -> _make_creag () ; if ( ! $this -> mail_from_admin ) { $this -> mail_from_admin = $this -> www_contact ; } if ( ! $this -> mail_from_noreply ) { $this -> mail_from_noreply = "svn-no-reply@{$this->www_server}" ; } return $this ; } function __get ( $key ) { if ( ! array_key_exists ( $key, $this ) ) { echo "config key not found ($key)" ; exit ; } return $this -> $key ; } function init () { $this -> db_pref = '' ; $this -> db_owner = '' ; $this -> db_opswd = '' ; $this -> top_head = '' ; $this -> aux_head = '' ; $this -> top_body = '' ; $this -> aux_body = '' ; $this -> top_rules_usage = '' ; $this -> aux_rules_usage = '' ; $this -> top_statistics = '' ; $this -> aux_statistics = '' ; $this -> create_guests = '' ; $this -> motd = '' ; $this -> viewvc = 1 ; $this -> has_groups = 1 ; $this -> file_access = 'svnaccessfile' ; $this -> file_guests = 'guestusers' ; $this -> file_log = 'repocafe_log' ; $this -> cmd_svnadmin = '/usr/bin/svnadmin' ; $this -> cmd_svnlook = '/usr/bin/svnlook' ; $this -> cmd_perl = '/usr/bin/perl' ; $this -> mail_from_admin = '' ; $this -> mail_from_noreply = '' ; $this -> www_scheme = 'https' ; } function get_conf ( $file ) { $this -> ldap = array () ; $this -> bind = array () ; $this -> attr = array () ; $this -> clas = array () ; $this -> tree = array () ; $this -> clas_list = array () ; $lines = file ( $file ) ; if ( $lines === FALSE ) { echo "config ($file) not found" ; exit ; } $txt = '' ; foreach ( $lines as $line ) { if ( ! preg_match ( "/^\s*\n/", $line ) and ! preg_match ( "/^#/", $line ) ) { $txt .= "$line\n" ; } } $txt = preg_replace ( "/\t/" , ' ' , $txt ) ; $txt = preg_replace ( "/^[ +]+/" , '' , $txt ) ; $txt = preg_replace ( "/\n\n\s+/" , ' ' , $txt ) ; $txt = preg_replace ( "/\n\n\+\s+/" , ' ' , $txt ) ; $txt = preg_replace ( "/\n\n\./\n" , "\n" , $txt ) ; $lines = preg_split ( "/\n\n/", $txt, 0, PREG_SPLIT_NO_EMPTY ) ; foreach ( $lines as $line ) { if ( preg_match ( '/^\s*$/', $line ) ) { continue ; } if ( preg_match ( '/^#/', $line ) ) { continue ; } $line = preg_replace ( '/^\s+/', '', $line ) ; $line = preg_replace ( '/\s+$/', '', $line ) ; list ( $key, $val ) = _split ( $line, 2 ) ; if ( $key == 'ldap' or $key == 'tree' or $key == 'bind' or $key == 'attr' ) { $v = _split ( $val ) ; $k = $v [ 0 ] ; if ( $key == 'ldap' ) { $this -> ldap [ $k ] = array ( 'name' => $v [ 0 ] , 'serv' => $v [ 1 ] , 'base' => $v [ 2 ] , 'dscr' => $v [ 3 ] ) ; } elseif ( $key == 'bind' ) { $this -> bind [ $k ] = array ( 'binddn' => $v [ 1 ] , 'bindpw' => $v [ 2 ] ) ; } elseif ( $key == 'attr' ) { $this -> attr [ $k ] = array ( 'login' => $v [ 1 ] , 'uname' => $v [ 2 ] , 'email' => $v [ 3 ] ) ; } elseif ( $key == 'tree' ) { $this -> tree [ $k ] = array ( 'path' => $v [ 0 ] , 'pref' => $v [ 1 ] , 'crea' => $v [ 2 ] ) ; } } elseif ( $key == 'clas' ) { $v = _split ( $val ) ; if ( $v [ 1 ] == 'table' ) { $clas = array ( 'clas' => $v [ 0 ] , 'typ' => $v [ 1 ] , 'table' => $v [ 2 ] , 'login' => $v [ 3 ] , 'paswd' => $v [ 4 ] , 'cname' => $v [ 5 ] , 'dscr' => $v [ 6 ] ) ; } elseif ( $v [ 1 ] == 'ldap' ) { $clas = array ( 'clas' => $v [ 0 ] , 'typ' => $v [ 1 ] , 'tag' => $v [ 2 ] , 'pat' => $v [ 3 ] , 'dscr' => $v [ 4 ] ) ; } $this -> clas [] = $clas ; } elseif ( $key == 'no_viewvc' ) { $this -> viewvc = 0 ; } elseif ( $key == 'no_groups' ) { $this -> has_groups = 0 ; } else { $this -> $key = $val ; } } } function _make_ldaps () { $res = array () ; foreach ( $this -> ldap as $tag => $cnf ) { $serv = $cnf [ 'serv' ] ; $base = $cnf [ 'base' ] ; $dscr = $cnf [ 'dscr' ] ; if ( ! $dscr ) { $dscr = $tag ; } $dscr = preg_replace ( '/_/', ' ', $dscr ) ; $ldap = new LDAP_serv ; $res [ $tag ] = $ldap -> init ( $serv, $base, $dscr ) ; } foreach ( $this -> bind as $tag => $cnf ) { $dn = $cnf [ 'binddn' ] ; $pw = $cnf [ 'bindpw' ] ; if ( ! array_key_exists ( $tag, $res ) ) { html_exit ( "bind : not found ldap '$tag'" ) ; } $res [ $tag ] -> binddn = $dn ; $res [ $tag ] -> bindpw = $pw ; } foreach ( $this -> attr as $tag => $cnf ) { $login = $cnf [ 'login' ] ; $uname = $cnf [ 'uname' ] ; $email = $cnf [ 'email' ] ; if ( ! array_key_exists ( $tag, $res ) ) { html_exit ( "attr : not found ldap '$tag'" ) ; } $res [ $tag ] -> login = $login ; $res [ $tag ] -> uname = $uname ; $res [ $tag ] -> email = $email ; } $this -> ldaps = $res ; } function _make_clas_list () { $res = array () ; foreach ( $this -> clas as $cnf ) { $tab = $cnf ; $clas = $cnf [ 'clas' ] ; $typ = $cnf [ 'typ' ] ; $tag = $cnf [ 'tag' ] ; $dscr = $cnf [ 'dscr' ] ; $dscr = preg_replace ( '/_/', ' ', $dscr ) ; if ( ! $dscr ) { $dscr = $clas ; } $tab [ 'dscr' ] = $dscr ; if ( $typ == 'table' ) { $uclas = new Uclas_table () ; } elseif ( $typ == 'ldap' ) { # check if 'ldap-tag' exists as 'ldap' entry if ( ! array_key_exists ( $tag, $this -> ldaps ) ) { html_exit ( "user clas '$clas' : not found ldap '$tag'" ) ; } $tab [ 'ldap' ] = $this -> ldaps [ $tag ] ; $uclas = new Uclas_ldap () ; } else { html_exit ( "unknown resource type ($typ)" ) ; } $res [] = $uclas -> init ( $tab ) ; } $this -> clas_list = $res ; } function _make_clases () { $res = array () ; foreach ( $this -> clas_list as $idx => $uclas ) { $res [ $uclas -> clas ] = $uclas ; } ksort ( $res ) ; $this -> clases = $res ; } function _make_trees () { $res = array () ; foreach ( $this -> tree as $idx => $cnf ) { $path = $cnf [ 'path' ] ; $pref = $cnf [ 'pref' ] ; $crea = $cnf [ 'crea' ] ; $creas = preg_split ( '/,/', $crea, 0, PREG_SPLIT_NO_EMPTY ) ; foreach ( $creas as $clas ) { if ( ! array_key_exists ( $clas, $this -> clases ) ) { html_exit ( "tree path '$path' : not found clas '$clas'" ) ; } } $tree = new Repo_tree ; $res [ $path ] = $tree -> init ( $path, $pref, $creas ) ; } ksort ( $res ) ; $this -> trees = $res ; } function _make_creag () { $res = array () ; foreach ( _split ( $this -> create_guests ) as $idx => $clas ) { if ( ! $this -> clases [ $clas ] ) { html_exit ( "_make_create_guests : clas ($clas) not found" ) ; } $res [ $clas ] = $this -> clases [ $clas ] ; } ksort ( $res ) ; $this -> creag = $res ; } function have_guests () { return array_key_exists ( G_CLASS (), $this -> clases ) ; } function dump () { foreach ( $this as $key => $val ) { if ( $key == 'clas_list' ) { foreach ( $val as $idx => $uclas ) { $uclas -> dmp () ; } } elseif ( $key == 'trees' ) { foreach ( $val as $path => $tree ) { $tree -> dmp () ; } } elseif ( is_array ( $val ) ) { echo "$key =
\n" ; foreach ( $val as $k1 => $v1 ) { if ( is_array ( $v1 ) ) { echo "-- $key -> $k1 =
\n" ; foreach ( $v1 as $k2 => $v2 ) { echo "---- $key -> $k1 -> $k2 = $v2
\n" ; } } else { echo "-- $k1 = $v1
\n" ; } } } else { echo "$key = $val
\n" ; } } } } function get_config () { global $CONFIG ; $CONFIG = new Config () ; } function Conf ( $key = '' ) { global $CONFIG ; return $key ? $CONFIG -> $key : $CONFIG ; } function _conf ( $x, $y = '' ) { $res = Conf ( $x ) ; if ( $y ) { $res .= $y ; } return $res ; } function DIR_ADMIN ( $x = '' ) { return _conf ( 'dir_admin', $x ) ; } function DIR_DATA ( $x = '' ) { return _conf ( 'dir_data' , $x ) ; } function DIR_WWW ( $x = '' ) { return _conf ( 'dir_www' , $x ) ; } function NEW_COMMIT_HOOK () { return DIR_ADMIN ( '/new-commit-hook' ) ; } function MK_GUEST_LIST () { return DIR_ADMIN ( '/mk_guest_list' ) ; } function REPO_DIR () { return DIR_DATA ( '/repos' ) ; } function ARCH_DIR () { return DIR_DATA ( '/archive' ) ; } function REPO_HOME_URL () { return sprintf ( '%s://%s/', _conf ( 'www_scheme' ), _conf ( 'www_server' ) ) ; } function GUEST_LIST () { return DIR_DATA ( '/admin/' . Conf ( 'file_guests' ) ) ; } function SVN_ACC_FILE () { return DIR_DATA ( '/admin/' . Conf ( 'file_access' ) ) ; } function LOG_FILE () { return DIR_DATA ( '/logs/' . Conf ( 'file_log' ) ) ; } function SVN_ADMIN_CMD () { return Conf ( 'cmd_svnadmin' ) ; } function SVN_LOOK_CMD () { return Conf ( 'cmd_svnlook' ) ; } function PG_CONNECT_STRING () { return sprintf ( "host='%s' dbname='%s' user='%s' password='%s'" , addslashes ( Conf ( 'db_host' ) ) , addslashes ( Conf ( 'db_name' ) ) , addslashes ( Conf ( 'db_user' ) ) , addslashes ( Conf ( 'db_pswd' ) ) ) ; } function DB_CONNECT_STRING () { return PG_CONNECT_STRING () ; } # dump () ; ?>