]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - settings/add-plugin.php
fd265719c4b06784347a61bab4f51d01ca48df5e
[irc/unrealircd/unrealircd-webpanel.git] / settings / add-plugin.php
1 <?php
2
3 require_once "../inc/common.php";
4 require_once "../inc/header.php";
5 require_once "../Classes/class-plugin-git.php";
6
7 if (!current_user_can(PERMISSION_MANAGE_PLUGINS))
8 die("Access denied");
9
10 $p = new PluginRepo();
11 ?>
12
13 <h2>Add New Plugin</h2>
14 <br>
15
16 <?php
17 if ($p) {
18 echo "
19 Welcome to our lively plugins hub, where creativity takes center stage.<br>
20 We've got two fantastic plugins to kick things off (one practical, one for a playful twist).<br>
21 Join us on this exciting journey and unlock new possibilities for your website!<br><br>";
22 $p->do_list();
23 } else {
24 echo "Oops! Could not find plugins list. This is an upstream error, which means there is nothing wrong<br>
25 on your panel, it just means we can't check the plugins information webpage for some reason.<br>
26 Nothing to worry about! Try again later!";
27 }
28 require_once "../inc/footer.php";
29
30 ?>
31
32 <script>
33
34 const ibtns = document.querySelectorAll(".btn-install-plugin");
35 ibtns.forEach((ib) => {
36 ib.addEventListener('click', (e) => {
37 console.log("Button clicked! " +ib.innerHTML);
38 if (ib.innerHTML !== "Install" && ib.innerHTML !== "Uninstall") // some point between, don't do anything
39 {}
40 else if (ib.innerHTML == "Install") // install button pressed!
41 {
42 let req = requestInstall(ib.id.slice(0,-7))
43 if (req == true)
44 {
45 ib.classList.replace("btn-primary", "btn-secondary");
46 ib.innerHTML = "Installing...";
47 }
48 else
49 {
50 let uhoh = new bsModal("Error", "Could not install: "+req, "", null, false, true);
51 }
52 }
53 else if (ib.innerHTML == "Uninstall")
54 {
55 let req = requestInstall(ib.id.slice(0,-7), true); // true = uninstall
56 if (req == true)
57 {
58 ib.classList.replace("btn-outline-danger", "btn-secondary");
59 ib.innerHTML = "Uninstalling...";
60 }
61 else
62 {
63 let uhoh = new bsModal("Error", "Could not uninstall: "+req, "", null, false, true);
64 }
65 }
66 });
67 })
68 const installed = document.querySelectorAll(".installed");
69 installed.forEach((el) => {
70 let btn = document.getElementById(el.id + 'install');
71 btn.classList.replace("btn-primary", "btn-outline-danger");
72 btn.innerHTML = "Uninstall";
73 });
74
75 function requestInstall(name, uninstall = false)
76 {
77 let inst = (uninstall) ? "uninstall" : "install";
78 var xhr = new XMLHttpRequest();
79
80 xhr.onload = function() {
81 if (xhr.status === 200) {
82 var response = JSON.parse(xhr.responseText);
83 console.log(response.success);
84 let install_button = document.getElementById(name+'install');
85 if (response.success !== undefined)
86 {
87 if (install_button)
88 {
89 install_button.innerHTML = (inst == "uninstall") ? "Install" : "Uninstall";
90 install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-primary' : 'btn-outline-danger');
91 let icomplete = bsModal(((inst == "uninstall") ? "Uninstall" : "Install") + " Plugin", response.success,"<div id=\""+name+"closebtn\" class=\"btn btn-danger\">Close</div>", null, true, true, false);
92 let closebtn = document.getElementById(name+"closebtn");
93 closebtn.addEventListener('click', e => {
94 location.reload();
95 });
96 }
97 }
98 else
99 {
100 if (install_button)
101 {
102 install_button.innerHTML = (inst == "uninstall") ? "Uninstall" : "Install";
103 install_button.classList.replace('btn-secondary', (inst == "uninstall") ? 'btn-outline-danger' : 'btn-primary');
104 let icomplete = bsModal(((inst == "uninstall") ? "Uninstall" : "Install") + " Plugin", response.error,"", null, false, true);
105 let closebtn = document.getElementById(name+"closebtn");
106 closebtn.addEventListener('click', e => {
107 location.reload();
108 });
109 }
110 }
111 }
112 };
113
114 xhr.open('GET', BASE_URL + 'api/plugin.php?'+inst+'=' + name, true);
115 xhr.send();
116 return true;
117 }
118
119 function create_info_modal(modname)
120 {
121 fetch(BASE_URL + 'api/plugin.php')
122 .then(response => response.json()) // Parse the response as JSON
123 .then(data => {
124 for (let i = 0; data[i]; i++)
125 {
126 if (data[i].name == modname)
127 {
128 const modal = bsModal(
129 "<i>Information about " + data[i].title + "</i>", // title
130 "<div class=\"" + data[i].name + "_screenshots\"><i class=\"fa fa-spinner\" aria-hidden=\"true\"></i></div><div class=\"" + data[i].name + "_description\"><i class=\"fa fa-spinner\" aria-hidden=\"true\"></i></div>",
131 "<div id=\""+modname+"closebtn\" class=\"btn btn-danger\">Close</div>", null, true, true, false
132 );
133 let modalclose = document.getElementById(modal);
134 modalclose.addEventListener('click', (e) => {
135 $("#"+modal).modal('hide');
136 });
137 console.log(modal + '-body');
138 boobs = document.getElementById(modal + '-body');
139 boobs.innerHTML = data[i].description;
140 }
141 }
142 })
143 .catch(error => {
144 // Handle any errors that occur during the request
145 console.error('Error:', error);
146 });
147 }
148
149 const infoButtons = document.querySelectorAll('.more-info');
150 infoButtons.forEach((el) => {
151 el.addEventListener('click', (event) => {
152 create_info_modal(el.id);
153
154 });
155 });
156 </script>