This file is indexed.

/usr/share/fusionforge/plugins/scmhook/cronjobs/updateScmRepo.php is in fusionforge-plugin-scmhook 6.0.3+20151023-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/php
<?php
/**
 * Copyright 2011, Franck Villaume - Capgemini
 * Copyright 2012-2013, Franck Villaume - TrivialDev
 * Copyright 2013, Benoit Debaenst - TrivialDev
 *
 * This file is part of FusionForge. FusionForge is free software;
 * you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or (at your option)
 * any later version.
 *
 * FusionForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 * main cronjob for scmhook plugin
 */

require dirname(__FILE__).'/../../env.inc.php';
require_once $gfcommon.'include/pre.php';
require_once $gfcommon.'include/cron_utils.php';
require_once $gfplugins.'scmhook/common/scmhookPlugin.class.php';

// if you want debug output, uncomment the verbose variable.
//$verbose = true;

############
###### START

$res = db_query_params('SELECT systask_id, group_id, user_name FROM systasks
	JOIN users ON (systasks.user_id = users.user_id)
	WHERE systasks.status=$1 AND systask_type=$2',
	array('WIP', 'SCMHOOK_UPDATE'));
while ($task = db_fetch_array($res)) {
	$group_id = $task['group_id'];
	$user_name = $task['user_name'];
	// Run as the requesting user to avoid symlinks attacks
	if (util_sudo_effective_user($user_name, 'install_hooks', array($group_id)) == false) {
		cron_debug("ERROR scmhook: couldn't run install_hooks as user $user_name");
	}
}

$group = null;  // pass info to library/ scripts
function install_hooks($params) {
	global $group, $gfplugins;

	$group_id = $params[0];
	// get the list of project to be updated
	$res = db_query_params('SELECT groups.group_id, groups.scm_box, plugin_scmhook.hooks
			FROM groups, plugin_scmhook
			WHERE groups.status = $1
			AND plugin_scmhook.id_group = groups.group_id
			AND plugin_scmhook.need_update = $2
			AND groups.use_scm = $3
            AND group_id = $4',
		array('A', 1, 1, $group_id));

	if (! $res) {
		cron_debug("FATAL Database Query Failed: " . db_error());
	}

	$scmhookPlugin = new scmhookPlugin;
	while ($row = db_fetch_array($res)) {
		$group_id = $row['group_id'];
		$scm_box = $row['scm_box'];
		$scmtype = '';
		// find the scm type of the project
		$listScm = $scmhookPlugin->getListLibraryScm();
		$group = group_get_object($group_id);
		for ($i = 0; $i < count($listScm); $i++) {
			if ($group->usesPlugin($listScm[$i])) {
				$scmtype = $listScm[$i];
				continue;
			}
		}
		$returnvalue = true;
		// call the right cronjob in the library
		switch ($scmtype) {
		case 'scmsvn':
			cron_debug("INFO start updating hooks for project ".$group->getUnixName());
			require_once $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
			$scmsvncronjob = new ScmSvnUpdateScmRepo();
			$params = array();
			$params['group_id'] = $group_id;
			$params['hooksString'] = $row['hooks'];
			$params['scm_root'] = forge_get_config('repos_path', 'scmsvn') . '/' . $group->getUnixName();
			if ($scmsvncronjob->updateScmRepo($params)) {
				$res_update = db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $group_id));
				if (!$res_update) {
					$returnvalue = false;
				}
			}
			break;

		case 'scmhg':
			cron_debug("INFO start updating hooks for project ".$group->getUnixName());
			require_once $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
			$scmhgcronjob = new ScmHgUpdateScmRepo();
			$params = array();
			$params['group_id'] = $group_id;
			$params['hooksString'] = $row['hooks'];
			$params['scm_root'] = forge_get_config('repos_path', 'scmhg') . '/' . $group->getUnixName();
			if ($scmhgcronjob->updateScmRepo($params)) {
				$res_update = db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $group_id));
				if (!$res_update) {
					$returnvalue = false;
				}
			}
			break;

		case 'scmgit':
			cron_debug("INFO start updating hooks for project ".$group->getUnixName());
			require_once $gfplugins.'scmhook/library/'.$scmtype.'/cronjobs/updateScmRepo.php';
			$scmgitcronjob = new ScmGitUpdateScmRepo();
			$params = array();
			$params['group_id'] = $group_id;
			$params['hooksString'] = $row['hooks'];
			$params['scm_root'] = forge_get_config('repos_path', 'scmgit') . '/' . $group->getUnixName() . '/' . $group->getUnixName() . '.git' ;
			if ($scmgitcronjob->updateScmRepo($params)) {
				$res_update = db_query_params('UPDATE plugin_scmhook set need_update = $1 where id_group = $2', array(0, $group_id));
				if (!$res_update) {
					$returnvalue = false;
				}
			}
			break;

		default:
			cron_debug("WARNING No scm plugin found for this project ".$group->getUnixName()." or no cronjobs for this type");
			$returnvalue = false;
			break;
		}
		
		if ($returnvalue) {
			cron_debug("INFO hooks updated for project ".$group->getUnixName());
		} else {
			cron_debug("ERROR Unable to update hooks for project ".$group->getUnixName());
		}
	}
}

cron_debug("INFO end of updateScmRepo main cronjob");

// Local Variables:
// mode: php
// c-file-style: "bsd"
// End: