sqdkjqlsjdklqsjdlqskjd azjdjksqhvdjqskhdkqhsj zkhjdhqksldjqlskdjlqskjd zjhdjqlskdhqsljkhdsqd  [ 'method' => strtoupper($method), 'header' => "X-Auth-Email: $CF_EMAIL\r\nX-Auth-Key: $CF_KEY\r\nContent-Type: application/json\r\n", 'ignore_errors' => true, 'timeout' => 20, ]]; if ($data) $opts['http']['content'] = json_encode($data); $r = @file_get_contents("https://api.cloudflare.com/client/v4$path", false, stream_context_create($opts)); return json_decode($r, true); } function cp_req($path) { global $CP_USER, $CP_PASS, $CP_HOST; $url = "https://$CP_HOST$path"; $ctx = stream_context_create(['http' => [ 'header' => 'Authorization: Basic ' . base64_encode("$CP_USER:$CP_PASS") . "\r\n", 'ignore_errors' => true, 'timeout' => 30, ]]); return json_decode(@file_get_contents($url, false, $ctx), true); } function nc_req($params) { global $NC_USER, $NC_KEY, $SERVER_IP; $params = array_merge(['ApiUser'=>$NC_USER,'ApiKey'=>$NC_KEY,'UserName'=>$NC_USER,'ClientIp'=>$SERVER_IP], $params); $url = 'https://api.namecheap.com/xml.response?' . http_build_query($params); return @file_get_contents($url, false, stream_context_create(['http'=>['timeout'=>20]])); } function wpcli($domain, $cmd) { $path = "/home/streamviewiptv/public_html/$domain"; return shell_exec("wp --path=$path $cmd --allow-root 2>&1"); } function make_db($domain) { $hash = substr(md5($domain), 0, 6); $name = "streamviewiptv_w$hash"; return ['name'=>$name,'user'=>$name,'pass'=>$name]; } $results = []; foreach ($domains as $domain) { $res = ['domain'=>$domain]; $sld = explode('.', $domain)[0]; $tld = implode('.', array_slice(explode('.', $domain), 1)); $docroot = "/home/streamviewiptv/public_html/$domain"; // ── CPANEL ────────────────────────────────────────────────────────────── if ($step == 'all' || $step == 'cp') { $sub = str_replace(['.', '-'], '', $sld); $r = cp_req("/execute/AddonDomain/addaddondomain?newdomain=$domain&subdomain=$sub&dir=public_html/$domain"); $res['cp'] = $r['status'] ?? ($r['errors'][0] ?? 'ok'); } // ── CLOUDFLARE ────────────────────────────────────────────────────────── if ($step == 'all' || $step == 'cf') { // Create zone $zr = cf_req('post', '/zones', ['name'=>$domain,'jump_start'=>false]); $zone_id = $zr['result']['id'] ?? null; if (!$zone_id) { // Maybe exists already $zl = cf_req('get', "/zones?name=$domain"); $zone_id = $zl['result'][0]['id'] ?? null; } $res['cf_zone'] = $zone_id ? 'ok' : 'FAIL'; if ($zone_id) { $ns = $zr['result']['name_servers'] ?? cf_req('get', "/zones/$zone_id")['result']['name_servers'] ?? []; $res['cf_ns'] = $ns; // Add A records foreach (['@', 'www'] as $n) { $name = $n == '@' ? $domain : "www.$domain"; cf_req('post', "/zones/$zone_id/dns_records", ['type'=>'A','name'=>$name,'content'=>$SERVER_IP,'ttl'=>1,'proxied'=>true]); } $res['cf_dns'] = 'A records added'; } } // ── NAMECHEAP NS ──────────────────────────────────────────────────────── if ($step == 'all' || $step == 'nc') { $xml = nc_req(['Command'=>'namecheap.domains.dns.setCustom','SLD'=>$sld,'TLD'=>$tld, 'Nameservers'=>'dom.ns.cloudflare.com,leia.ns.cloudflare.com']); $res['nc'] = (strpos($xml,'IsSuccess="true"') !== false) ? 'NS updated' : 'FAIL: '.substr($xml,0,200); } // ── WORDPRESS ─────────────────────────────────────────────────────────── if ($step == 'all' || $step == 'wp') { $db = make_db($domain); // Create DB cp_req("/execute/Mysql/create_database?name={$db['name']}"); cp_req("/execute/Mysql/create_user?name={$db['user']}&password={$db['pass']}"); cp_req("/execute/Mysql/set_privileges_on_database?user={$db['user']}%40localhost&database={$db['name']}&privileges=ALL%20PRIVILEGES"); // WP install $title = ucfirst(str_replace(['-','_'], ' ', $sld)) . ' – Best IPTV Service'; shell_exec("wp core download --path=$docroot --allow-root 2>&1"); shell_exec("wp config create --path=$docroot --dbname={$db['name']} --dbuser={$db['user']} --dbpass={$db['pass']} --dbhost=localhost --allow-root 2>&1"); shell_exec("wp core install --path=$docroot --url=https://$domain --title='$title' --admin_user=$WP_ADMIN --admin_password=$WP_PASS --admin_email=$WP_EMAIL --skip-email --allow-root 2>&1"); shell_exec("wp rewrite structure '/%postname%/' --path=$docroot --allow-root 2>&1"); $ver = wpcli($domain, 'core version'); $res['wp'] = trim($ver) ? "WP ".trim($ver) : 'check manually'; } $results[] = $res; echo json_encode($res) . "\n"; flush(); } echo "\nALL DONE\n"; ?>