示例#1
0
 public function testRunCmd()
 {
     if (!(substr(php_uname(), 0, 7) == "Windows")) {
         $this->assertEquals(0, USVN_ConsoleUtils::runCmd("ls"));
         $this->assertEquals(1, USVN_ConsoleUtils::runCmd("test 1 = 2"));
     }
 }
示例#2
0
文件: Test.php 项目: phpscr/usvn
 private function setConsoleLocale()
 {
     if (PHP_OS == "Linux") {
         USVN_ConsoleUtils::setLocale("en_US.utf8");
     } else {
         USVN_ConsoleUtils::setLocale("en_US.UTF-8");
     }
 }
示例#3
0
 public function testImportHtpasswd()
 {
     file_put_contents('../tests/htpasswd', "noplay:BD3ZmTBhHmWJs\nstem:1YApoa5EK/WFs");
     $message = USVN_ConsoleUtils::runCmdCaptureMessage("php tools/usvn-import-htpasswd.php ../tests/test.ini ../tests/htpasswd", $return);
     $this->assertEquals(0, $return, $message);
     echo $message;
     chdir($this->_path);
     //Else SQLite doesn't work
     $userTable = new USVN_Db_Table_Users();
     $user = $userTable->fetchRow(array('users_login = ?' => "noplay"));
     $this->assertNotNull($user);
     $this->assertEquals("BD3ZmTBhHmWJs", $user->password);
 }
示例#4
0
文件: SVNLog.php 项目: phpscr/usvn
 /**
  * @param string Path to repository
  * @param int Number of revision (0 = no limit)
  * @return array  Key are revision number example:
  *		array(
  *			1 => array("author" => "duponc_j", "msg" => "Test", date=> 1265413),
  *			2 => array("revision" => "crivis_s", "msg" => "Test2", date=>4565654)
  *		)
  *
  * Date are unix timestamp
  */
 public static function log($repository, $limit = 0, $start = 0, $end = 0)
 {
     $repository = USVN_SVNUtils::getRepositoryPath($repository);
     if ($limit) {
         $limit = escapeshellarg($limit);
         $limit = "--limit {$limit}";
     } else {
         $limit = "";
     }
     if ($start) {
         $revision = "-r {$start}";
         if ($end) {
             $revision .= ":{$end}";
         }
     } else {
         $revision = "";
     }
     $message = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe(USVN_SVNUtils::svnCommand("log --xml {$revision} {$limit} {$repository}"), $return);
     if ($return) {
         throw new USVN_Exception(T_("Can't get subversion repository logs: %s"), $message);
     }
     return USVN_SVNLog::parseOutput($message);
 }
示例#5
0
文件: install.php 项目: jiangti/usvn
 public static function check()
 {
     $errors = array('safe_mode' => 'ok', 'svn' => 'ok', 'mod_rewrite' => 'ok', 'mod_dav_svn' => 'ok', 'mod_authz_svn' => 'ok', 'public' => 'ok', 'config' => 'ok');
     if (ini_get('safe_mode')) {
         $errors['safe_mode'] = 'ko';
     }
     if (USVN_ConsoleUtils::runCmd('svn --config-dir /USVN/fake --version')) {
         $errors['svn'] = 'ko';
     }
     if (php_sapi_name() != 'cli') {
         if (function_exists('apache_get_modules') && !in_array('mod_rewrite', apache_get_modules())) {
             $errors['mod_rewrite'] = 'ko';
         }
         if (function_exists('apache_get_modules') && !in_array('mod_dav_svn', apache_get_modules())) {
             $errors['mod_dav_svn'] = 'ko';
         }
         if (function_exists('apache_get_modules') && !in_array('mod_authz_svn', apache_get_modules())) {
             $errors['mod_authz_svn'] = 'ko';
         }
     }
     if (!file_exists(USVN_PUB_DIR) or !is_writable(USVN_PUB_DIR) or !is_readable(USVN_PUB_DIR)) {
         $errors['public'] = 'ko';
     }
     if (!file_exists(USVN_CONFIG_DIR)) {
         if (!@mkdir(USVN_CONFIG_DIR, 0755, true)) {
             $errors['config'] = 'ko';
         }
     }
     if (file_exists(USVN_CONFIG_DIR) and (!is_writable(USVN_CONFIG_DIR) or !is_readable(USVN_CONFIG_DIR))) {
         $errors['config'] = 'ko';
     }
     return $errors;
 }
示例#6
0
文件: SVNUtils.php 项目: jiangti/usvn
 /**
  * List files into Subversion
  *
  * @param string Path to subversion repository
  * @param string Path into subversion repository
  * @return associative array like: array(array(name => "tutu", isDirectory => true))
  */
 public static function listSvn($repository, $path)
 {
     $escape_path = USVN_SVNUtils::getRepositoryPath($repository . '/' . $path);
     $lists = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe(USVN_SVNUtils::svnCommand("ls --xml {$escape_path}"), $return);
     if ($return) {
         throw new USVN_Exception(T_("Can't list subversion repository: %s"), $lists);
     }
     $res = array();
     $xml = new SimpleXMLElement($lists);
     foreach ($xml->list->entry as $list) {
         if ($list['kind'] == 'file') {
             array_push($res, array("name" => (string) $list->name, "isDirectory" => false, "path" => str_replace('//', '/', $path . "/" . $list->name), "size" => $list->size, "revision" => $list->commit['revision'], "author" => $list->commit->author, "date" => $list->commit->date));
         } else {
             array_push($res, array("name" => (string) $list->name, "isDirectory" => true, "path" => str_replace('//', '/', $path . "/" . $list->name . '/')));
         }
     }
     $sortfunc = create_function('$a,$b', 'return (strcasecmp($a["name"], $b["name"]));');
     usort($res, $sortfunc);
     return $res;
 }
示例#7
0
文件: index.php 项目: jiangti/usvn
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
require_once USVN_APP_DIR . '/functions.php';
require_once USVN_APP_DIR . '/install/install.php';
$GLOBALS['language'] = 'en_US';
if (file_exists(USVN_CONFIG_FILE)) {
    try {
        $config = new USVN_Config_Ini(USVN_CONFIG_FILE, 'general');
        if (isset($config->translation->locale)) {
            $GLOBALS['language'] = $config->translation->locale;
        }
        if (isset($config->timezone)) {
            date_default_timezone_set($config->timezone);
        }
        if (isset($config->system->locale)) {
            USVN_ConsoleUtils::setLocale($config->system->locale);
        }
        if (isset($config->database->adapterName)) {
            Zend_Db_Table::setDefaultAdapter(Zend_Db::factory($config->database->adapterName, $config->database->options->toArray()));
            Zend_Db_Table::getDefaultAdapter()->getProfiler()->setEnabled(true);
            USVN_Db_Table::$prefix = $config->database->prefix;
        }
        Zend_Registry::set('config', $config);
    } catch (Exception $e) {
    }
}
USVN_Translation::initTranslation($GLOBALS['language'], USVN_LOCALE_DIRECTORY);
$installSteps = array(1 => 'System Check', 2 => 'Language Selection', 3 => 'License Agreement', 4 => 'USVN Configuration', 5 => 'Database Installation', 6 => 'Administrator User Creation', 7 => 'Check for a Newer Version', 8 => 'Installation is over');
//------------------------------------------------------------------------------------------------
include 'views/head.html';
try {
示例#8
0
 /**
  * Display a file using appropriate highlighting
  *
  * @return void
  */
 public function commitAction()
 {
     include_once 'geshi/geshi.php';
     $this->view->project = $this->_project;
     $config = new USVN_Config_Ini(USVN_CONFIG_FILE, USVN_CONFIG_SECTION);
     $project_name = str_replace(USVN_URL_SEP, '/', $this->_project->name);
     $local_project_path = USVN_SVNUtils::getRepositoryPath($config->subversion->path . "/svn/" . $project_name . "/");
     $commit = $this->getRequest()->getParam('commit');
     $base = $commit - 1;
     $cmd = USVN_SVNUtils::svnCommand("log --non-interactive --revision {$commit} {$local_project_path}");
     $log = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
     if (!$return) {
         $cmd = USVN_SVNUtils::svnCommand("diff --non-interactive --revision " . ($commit - 1) . ":{$commit} {$local_project_path}");
         $diff = USVN_ConsoleUtils::runCmdCaptureMessageUnsafe($cmd, $return);
         if (!$return) {
             $diff = explode("\n", $diff);
             array_pop($diff);
             // Skip the final "\n"
             $file = NULL;
             $count = 0;
             $indiff = FALSE;
             $tab_diff = array();
             $tab_index = NULL;
             foreach ($diff as $line) {
                 if (strpos($line, 'Index: ') === 0) {
                     $file = substr($line, 7);
                     $tab_diff[$file] = array();
                     $indiff = FALSE;
                 } elseif (!$indiff) {
                     if (preg_match('#^@@ \\-([0-9]+)(,([0-9]+))? \\+([0-9]+)(,([0-9]+))? @@$#', $line, $tmp)) {
                         $tab_index = count($tab_diff[$file]);
                         $tab_diff[$file][$tab_index] = array($base => array('begin' => $tmp[1], 'end' => empty($tmp[3]) ? $tmp[1] : $tmp[3], 'content' => array()), $commit => array('begin' => $tmp[4], 'end' => empty($tmp[6]) ? $tmp[4] : $tmp[6], 'content' => array()), 'common' => array());
                         $count = 0;
                         $indiff = TRUE;
                     }
                 } else {
                     $diff_char = substr($line, 0, 1);
                     if ($diff_char == '\\') {
                         continue;
                     }
                     $line = htmlentities(substr($line, 1));
                     if ($diff_char == '-') {
                         $tab_diff[$file][$tab_index][$base]['content'][$count++] = $line;
                     } elseif ($diff_char == '+') {
                         $tab_diff[$file][$tab_index][$commit]['content'][$count++] = $line;
                     } else {
                         $tab_diff[$file][$tab_index]['common'][$count++] = $line;
                     }
                 }
             }
             $this->view->diff = $tab_diff;
             $this->view->commit = $commit;
             $this->view->base = $base;
             unset($tab_diff);
             $log = explode("\n", $log);
             if (preg_match('#^r[0-9]* \\| (.*) \\| ([0-9-]+ [0-9:]+) [^\\|]* \\| ([0-9]*)[^\\|]*$#', $log[1], $tmp)) {
                 $this->view->author = $tmp[1];
                 $this->view->date = $tmp[2];
                 $this->view->log = NULL;
                 for ($i = 0; $i < $tmp[3]; ++$i) {
                     $this->view->log .= ($this->view->log != NULL ? "\n" : '') . $log[3 + $i];
                 }
             }
         } else {
             throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message);
         }
     } else {
         throw new USVN_Exception(T_("Can't read from subversion repository.\nCommand:\n%s\n\nError:\n%s"), $cmd, $message);
     }
 }
示例#9
0
 /**
  * Run a cmd and return result
  *
  * @param string command line
  * @return int programm return code
  */
 public static function runCmd($command)
 {
     USVN_ConsoleUtils::prepareLang();
     ob_start();
     system($command . " 2>&1", $return);
     ob_end_clean();
     USVN_ConsoleUtils::restoreLang();
     return $return;
 }