Ejemplo n.º 1
0
 function install()
 {
     if (version_compare(PHP_VERSION, '5.3.0', '<')) {
         plugin_error(ERROR_PHP_VERSION, ERROR);
         return false;
     }
     if (!extension_loaded('curl')) {
         plugin_error(ERROR_NO_CURL, ERROR);
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 public function update_repo($p_repo)
 {
     $f_hub_root = gpc_get_string('hub_root');
     $f_hub_repoid = gpc_get_string('hub_repoid');
     $f_hub_reponame = gpc_get_string('hub_reponame');
     $f_hub_app_secret = gpc_get_string('hub_app_secret');
     # Update info required for getting the repoid
     $p_repo->info['hub_root'] = $f_hub_root;
     $p_repo->info['hub_reponame'] = $f_hub_reponame;
     $p_repo->info['hub_app_secret'] = $f_hub_app_secret;
     # Getting the repoid from reponame
     if (!is_numeric($f_hub_repoid) && !empty($f_hub_reponame)) {
         $t_hub_reponame_enc = urlencode($f_hub_reponame);
         $t_uri = $this->api_uri($p_repo, "projects/{$t_hub_reponame_enc}");
         $t_member = null;
         $t_json = json_url($t_uri, $t_member);
         $f_hub_repoid = 'Repository Name is invalid';
         if (!is_null($t_json)) {
             if (property_exists($t_json, 'id')) {
                 $f_hub_repoid = (string) $t_json->id;
             }
         }
     }
     $f_master_branch = gpc_get_string('master_branch');
     if (!preg_match('/^(\\*|[a-zA-Z0-9_\\., -]*)$/', $f_master_branch)) {
         plugin_error(self::ERROR_INVALID_PRIMARY_BRANCH);
     }
     # Update other fields
     $p_repo->info['hub_repoid'] = $f_hub_repoid;
     $p_repo->info['master_branch'] = $f_master_branch;
     return $p_repo;
 }
Ejemplo n.º 3
0
function check_environment()
{
    exec('which whois 2>&1', $execout, $return_var);
    $whois_path = $execout[0];
    if ($return_var != 0) {
        plugin_error("whois is not installed in your system.");
    }
}
Ejemplo n.º 4
0
 function notify($msg, $webhook, $channel, $attachment = FALSE)
 {
     if ($this->skip) {
         return;
     }
     if (empty($channel)) {
         return;
     }
     if (empty($webhook)) {
         return;
     }
     $ch = curl_init();
     // @see https://my.slack.com/services/new/incoming-webhook
     // remove istance and token and add plugin_Slack_url config , see configurations with url above
     $url = sprintf('%s', trim($webhook));
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $payload = array('channel' => $channel, 'username' => plugin_config_get('bot_name'), 'text' => $msg, 'link_names' => plugin_config_get('link_names'));
     $bot_icon = trim(plugin_config_get('bot_icon'));
     if (empty($bot_icon)) {
         $payload['icon_url'] = 'https://raw.githubusercontent.com/infojunkie/MantisBT-Slack/master/mantis_logo.png';
     } elseif (preg_match('/^:[a-z0-9_\\-]+:$/i', $bot_icon)) {
         $payload['icon_emoji'] = $bot_icon;
     } elseif ($bot_icon) {
         $payload['icon_url'] = trim($bot_icon);
     }
     if ($attachment) {
         $payload['attachments'] = array($attachment);
     }
     $data = array('payload' => json_encode($payload));
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     $result = curl_exec($ch);
     if ($result !== 'ok') {
         trigger_error($result, E_USER_WARNING);
         plugin_error('ERROR_CURL', E_USER_ERROR);
     }
     curl_close($ch);
 }
Ejemplo n.º 5
0
 public function update_repo($p_repo)
 {
     $f_hub_username = gpc_get_string('hub_username');
     $f_hub_reponame = gpc_get_string('hub_reponame');
     $f_hub_app_client_id = gpc_get_string('hub_app_client_id');
     $f_hub_app_secret = gpc_get_string('hub_app_secret');
     $f_master_branch = gpc_get_string('master_branch');
     if (!preg_match('/^(\\*|[a-zA-Z0-9_\\., -]*)$/', $f_master_branch)) {
         plugin_error(self::ERROR_INVALID_PRIMARY_BRANCH);
     }
     $p_repo->info['hub_username'] = $f_hub_username;
     $p_repo->info['hub_reponame'] = $f_hub_reponame;
     $p_repo->info['hub_app_client_id'] = $f_hub_app_client_id;
     $p_repo->info['hub_app_secret'] = $f_hub_app_secret;
     $p_repo->info['master_branch'] = $f_master_branch;
     return $p_repo;
 }
Ejemplo n.º 6
0
 public function update_config()
 {
     # Prevent more than one SVN class from handling form elements.
     if (!SourceSVNPlugin::$config_form_handled) {
         SourceSVNPlugin::$config_form_handled = true;
         $f_svnpath = gpc_get_string('plugin_SourceSVN_svnpath', '');
         $t_svnpath = config_get('plugin_SourceSVN_svnpath', '');
         $f_svnpath = rtrim($f_svnpath, DIRECTORY_SEPARATOR);
         if ($f_svnpath != $t_svnpath) {
             if (is_blank($f_svnpath)) {
                 config_delete('plugin_SourceSVN_svnpath');
             } else {
                 # be sure that the path is valid
                 if (($t_binary = SourceSVNPlugin::svn_binary($f_svnpath, true)) != 'svn') {
                     config_set('plugin_SourceSVN_svnpath', $f_svnpath);
                 } else {
                     plugin_error('SVNPathInvalid', ERROR);
                 }
             }
         }
         $f_svnargs = gpc_get_string('plugin_SourceSVN_svnargs', '');
         if ($f_svnargs != config_get('plugin_SourceSVN_svnargs', '')) {
             config_set('plugin_SourceSVN_svnargs', $f_svnargs);
         }
         $f_svnssl = gpc_get_bool('plugin_SourceSVN_svnssl', false);
         if ($f_svnssl != config_get('plugin_SourceSVN_svnssl', false)) {
             config_set('plugin_SourceSVN_svnssl', $f_svnssl);
         }
         $f_winstart = gpc_get_bool('plugin_SourceSVN_winstart', false);
         if ($f_winstart != config_get('plugin_SourceSVN_winstart', false)) {
             config_set('plugin_SourceSVN_winstart', $f_winstart);
         }
     }
 }
Ejemplo n.º 7
0
 public function update_repo($p_repo)
 {
     $f_hub_root = gpc_get_string('hub_root');
     $f_hub_repoid = gpc_get_string('hub_repoid');
     $f_hub_reponame = gpc_get_string('hub_reponame');
     # Getting the repoid doesnt seem to work with the latest gitlab - but we can get all the
     # repos the current user can access and go through them to find the correct id
     if (empty($f_hub_repoid)) {
         $f_uri_1 = null;
         $f_uri_2 = null;
         $f_hub_repoid = (string) $this->get_repo_id($p_repo, true, $f_uri_1);
         if (empty($f_hub_repoid)) {
             $f_hub_repoid = (string) $this->get_repo_id($p_repo, false, $f_uri_2);
         }
         if (empty($f_hub_repoid)) {
             plugin_error(plugin_lang_get("error_invalid_repoid") . "\n" . $p_repo->info['hub_root'] . "\n" . $f_uri_1 . "\n" . $f_uri_2 . "\n");
         }
     }
     $f_hub_app_secret = gpc_get_string('hub_app_secret');
     $f_master_branch = gpc_get_string('master_branch');
     if (!preg_match('/^(\\*|[a-zA-Z0-9_\\., -]*)$/', $f_master_branch)) {
         plugin_error(self::ERROR_INVALID_PRIMARY_BRANCH);
     }
     $p_repo->info['hub_root'] = $f_hub_root;
     $p_repo->info['hub_repoid'] = $f_hub_repoid;
     $p_repo->info['hub_reponame'] = $f_hub_reponame;
     $p_repo->info['hub_app_secret'] = $f_hub_app_secret;
     $p_repo->info['master_branch'] = $f_master_branch;
     return $p_repo;
 }