- 1
IT Оффтоп #199
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
IT Оффтоп #199
#169: https://govnokod.ru/28628 https://govnokod.xyz/_28628
#170: https://govnokod.ru/28653 https://govnokod.xyz/_28653
#171: (vanished) https://govnokod.xyz/_28665
#172: https://govnokod.ru/28675 https://govnokod.xyz/_28675
#173: https://govnokod.ru/28681 https://govnokod.xyz/_28681
#174: https://govnokod.ru/28689 https://govnokod.xyz/_28689
#175: https://govnokod.ru/28696 https://govnokod.xyz/_28696
#176: https://govnokod.ru/28703 https://govnokod.xyz/_28703
#177: https://govnokod.ru/28709 https://govnokod.xyz/_28709
#178: https://govnokod.ru/28716 https://govnokod.xyz/_28716
#179: https://govnokod.ru/28726 https://govnokod.xyz/_28726
#180: https://govnokod.ru/28734 https://govnokod.xyz/_28734
#181: https://govnokod.ru/28739 https://govnokod.xyz/_28739
#182: https://govnokod.ru/28749 https://govnokod.xyz/_28749
#183: https://govnokod.ru/28777 https://govnokod.xyz/_28777
#184: https://govnokod.ru/28790 https://govnokod.xyz/_28790
#185: https://govnokod.ru/28794 https://govnokod.xyz/_28794
#186: https://govnokod.ru/28815 https://govnokod.xyz/_28815
#187: https://govnokod.ru/28833 https://govnokod.xyz/_28833
#188: https://govnokod.ru/28837 https://govnokod.xyz/_28837
#189: https://govnokod.ru/28840 https://govnokod.xyz/_28840
#190: https://govnokod.ru/28875 https://govnokod.xyz/_28875
#191: https://govnokod.ru/28878 https://govnokod.xyz/_28878
#192: https://govnokod.ru/28886 https://govnokod.xyz/_28886
#193: https://govnokod.ru/28911 https://govnokod.xyz/_28911
#194: https://govnokod.ru/28914 https://govnokod.xyz/_28914
#195: https://govnokod.ru/28917 https://govnokod.xyz/_28917
#196: https://govnokod.ru/28925 https://govnokod.xyz/_28925
#197: https://govnokod.ru/28935 https://govnokod.xyz/_28935
#198: https://govnokod.ru/28938 https://govnokod.xyz/_28938
0
#!/bin/sh
$1 echo Pituh
$1 false && echo Kurochka
$ pituh.sh
Выводит:
Pituh
$ pituh.sh :
Выводит:
Kurochka
+2
package main
import (
"io"
"fmt"
"log"
"bytes"
"strings"
"net/http"
"net/http/httputil"
"net/url"
)
func UpdateResponse(r *http.Response) error {
for k, v := range r.Header {
newValue := strings.Replace(v[0], "umnico.com", "umnico.*****.ru", -1)
r.Header[k][0] = newValue
}
b, err := io.ReadAll(r.Body)
if(err == nil) {
bodyText := strings.Replace(string(b), "://umnico.com", "://umnico.*****.ru", -1);
if(strings.Contains(bodyText, "</head><body>")) {
injectedStyle := `<style>
.nav-menu.hidden, .widget__preview-container--tech-support {
display: none !important;
}
</style>`
bodyText = strings.Replace(bodyText, "</head><body>", injectedStyle + "</head><body>", -1);
}
if(strings.Contains(bodyText, "</body></html>")) {
injectedScript := `<script>
fetch('/api/user').then((response) => {
return response.json().then((data) => {
//alert(data.user.id);
if(data.user.id != 12345) {
const style = document.createElement('style');
style.textContent = '.im__chat-buttons{display:none!important;}';
document.head.appendChild(style);
}
return true;
}).catch((err) => {
console.log(err);
})
});
var currentDialogId = 0;
function checkDialogControls() {
if(location.pathname.indexOf('app/deals/inbox/details/') > 0 || location.pathname.indexOf('app/deals/active/details/') > 0) {
if(location.pathname.indexOf('app/deals/active/details/') > 0) {
var dialogId = location.pathname.split('app/deals/active/details/')[1];
} else {
var dialogId = location.pathname.split('app/deals/inbox/details/')[1];
}
var chatIndicator = document.querySelector('.im-aside-section.im-aside-section__toolbox');
if(chatIndicator != null) {
var injectedControls = document.querySelector('.im-aside-section.injected-controls');
if(injectedControls == null) {
chatIndicator.insertAdjacentHTML('afterend', '<div class="im-aside-section injected-controls"><div><button type="button" class="button" style="width:100%;" onclick="window.parent.postMessage(\'openBookingModalByUmnicoId('+dialogId+')\', \'*\');">Оформить бронь</button></div><div style="margin-top:5px;"><button type="button" class="button button_attention" style="width:100%;" onclick="window.parent.postMessage(\'openLeadTaskModalByUmnicoId('+dialogId+')\', \'*\');">Задача</button></div></div>');
} else {
if(currentDialogId != dialogId) {
injectedControls.remove();
}
}
currentDialogId = parseInt(dialogId);
}
}
}
setInterval(checkDialogControls, 100);
</script>`
bodyText = strings.Replace(bodyText, "</body></html>", injectedScript + "</body></html>", -1);
}
if(strings.Contains(bodyText, "window.location.hostname != \"localhost\"")) {
bodyText = strings.Replace(bodyText, "window.location.hostname != \"localhost\"", "window.location.hostname != \"localhost\" && window.location.hostname != \"umnico.*****.ru\"", -1);
}
buf := bytes.NewBufferString(bodyText)
r.Body = io.NopCloser(buf)
r.Header["Content-Length"] = []string{fmt.Sprint(buf.Len())}
}
return nil
}
func main() {
target, err := url.Parse("https://umnico.com:443")
if err != nil {
log.Fatal(err)
}
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.ModifyResponse = UpdateResponse
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
req.Host = req.URL.Host
proxy.ServeHTTP(w, req)
})
err = http.ListenAndServe("127.0.0.1:8803", nil)
if err != nil {
panic(err)
}
}
Мой код для проксирования одного из SaaS-сервисов, с целью встраивания в интерфейс последнего кастомных кнопок. Взглянул спустя пару месяцев и ужаснулся.