-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.php
More file actions
154 lines (144 loc) · 7.19 KB
/
github.php
File metadata and controls
154 lines (144 loc) · 7.19 KB
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
<?php
include('includes/load.php');
if($_POST) {
$db = getMySQL();
$name = $db->escape_string($_POST['name']);
$repo = explode("@", $_POST['repo']);
$repoid = intval($repo[0]);
$reponame = $db->escape_string($repo[1]);
if($repoid == '-1' || $reponame == '-1') {
$repoid = "NULL";
$reponame = "NULL";
}else {
$j = json_encode(["name"=>"web", "active"=>true, "events"=>["push"], "config"=>["url"=>"http://punchio.shdwlf.com/webhook.php","content_type"=>"json"]]);
$a = explode("/", $reponame);
$owner = $a[0];
$repo = $a[1];
$token = $db->query("SELECT * FROM github WHERE accountowner={$_SESSION['user']->id}")->fetch_object()->access_token;
$ch = curl_init("https://api.github.com/repos/$owner/$repo/hooks?access_token=$token");
$result = curl_exec($ch);
curl_close($ch);
$q = json_decode($result, true);
$added = false;
foreach($q as $k=>$v) {
if($v["config"]["url"] == "http://punchio.shdwlf.com/webhook.php") {
$added = true;
}
}
if(!$added) {
$ch = curl_init("https://api.github.com/repos/$owner/$repo/hooks?access_token=$token");
curl_setopt($ch, CURLOPT_POSTFIELDS, $j);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'User-Agent: curl'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
}
$reponame = "'".$reponame."'";
}
$id = intval($_GET['proj']);
$db->query("UPDATE projects SET projectname='$name', githubrepo=$repoid, githubname=$reponame WHERE projectid=$id");
header('location: /github.php?proj='.$id);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>PunchIO</title>
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<body>
<?php getNavbar(); ?>
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">GitHub Association</div>
<div class="panel-body">
<?php
$db = getMySQL();
$resx = $db->query("SELECT * FROM github WHERE accountowner={$_SESSION["user"]->id}");
if($resx->num_rows) {
//Added
$d = $resx->fetch_object();
echo "<a style='cursor: pointer;' class='btn btn-success form-control'>{$d->username} linked!</a>";
}else {
//Not added
echo "<a href='/includes/oauth.php?action=login' class='btn btn-danger form-control'>Connect Your Github Account!</a>";
}
?>
</div>
</div>
</div>
<div class="col-md-8">
<div class="panel panel-default">
<div class="panel-heading">Projects</div>
<div class="panel-body">
<?php
$db = getMySQL();
$id = intval($_GET['proj']);
$res = $db->query("SELECT * FROM projects WHERE projectowner={$_SESSION['user']->id} AND projectid=$id");
$dat = $res->fetch_object();
?>
<table class="table">
<form method="post" action="github.php?proj=<?php echo $_GET['proj']; ?>">
<tr>
<td style="vertical-align: middle;">Project Name</td>
<td><input class="form-control" type="text" autocomplete="off" value="<?php echo $dat->projectname; ?>" name="name"></td>
</tr>
<tr>
<td style="vertical-align: middle;">GitHub Repository</td>
<td>
<?php
if($resx->num_rows) {
?>
<select class="form-control" name="repo">
<option value="-1@-1">No Repository</option>
<?php
$r = $db->query("SELECT * FROM github WHERE accountowner={$_SESSION['user']->id}");
if($r->num_rows) {
$data = $r->fetch_object();
$username = $data->username;
$token = $data->access_token;
$d = getSslPage("https://api.github.com/user/repos?access_token=$token&type=owner");
$j = json_decode($d, true);
foreach($j as $k=>$v) {
echo "<option value='{$v['id']}@{$v['full_name']}'>{$v['full_name']}</option>";
}
}
?>
</select>
<?php
}else {
echo "<center>You must link your GitHub account first!</center>";
}
?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" class="btn btn-success pull-right"></td>
</tr>
</form>
</table>
</div>
</div>
</div>
</div>
</div> <!-- /container -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script>
<?php
$rid = $dat->githubrepo;
$rnam = $dat->githubname;
$i = $rid.'@'.$rnam;
?>
$(function() {$('select option[value="<?php echo $i; ?>"]').attr('selected', 'selected');});
</script>
</body>
</html>