74 lines
7.6 KiB
PHP
74 lines
7.6 KiB
PHP
<?php
|
|
function wevia_file_write($msg) {
|
|
$m = mb_strtolower(trim($msg));
|
|
$fp = ['/cr[eé]+\s+(un\s+)?fichier/i','/[eé]cris\s+(un\s+)?fichier/i','/g[eé]n[eè]re\s+(un\s+)?(fichier|html|page)/i','/cr[eé]+\s+(une\s+)?page/i','/d[eé]ploie\s+(un\s+)?(fichier|html|page)/i','/file.?write/i','/write.?file/i','/cr[eé]+.*\.(html|php|json|sh|css|js)/i'];
|
|
$hit = false;
|
|
foreach ($fp as $p) { if (@preg_match($p, $msg)) { $hit = true; break; } }
|
|
if (!$hit) return null;
|
|
$path = null;
|
|
if (preg_match('#(/var/www/html/[a-zA-Z0-9_./-]+)#', $msg, $pm)) $path = $pm[1];
|
|
elseif (preg_match('#([a-zA-Z0-9_-]+\.(html|php|json|css|js|sh))#i', $msg, $pm)) $path = '/var/www/html/' . $pm[1];
|
|
if (!$path) return ['ok'=>false,'error'=>'Aucun chemin detecte'];
|
|
$ok = false;
|
|
foreach (['/var/www/html/','/opt/weval-l99/','/opt/wevia-brain/'] as $px) { if (strpos($path,$px)===0) {$ok=true;break;} }
|
|
if (!$ok) return ['ok'=>false,'error'=>'Chemin non autorise'];
|
|
if (preg_match('/\.\./', $path)) return ['ok'=>false,'error'=>'Path traversal bloque'];
|
|
$ext = pathinfo($path, PATHINFO_EXTENSION);
|
|
$tpl_dir = __DIR__ . '/wevia-templates/';
|
|
$tpl_file = null;
|
|
if (preg_match('/presentation|slides|linkedin|big4|enterprise.*model|entreprise.*model/i', $msg)) {
|
|
$tf = $tpl_dir . 'presentation-4slides.html';
|
|
if (file_exists($tf)) $tpl_file = $tf;
|
|
}
|
|
if ($tpl_file && $ext === 'html') {
|
|
$tpl = file_get_contents($tpl_file);
|
|
$d = [];
|
|
$d['PAGE_TITLE'] = 'WEVIA Enterprise Model';
|
|
$d['S1_LOGO'] = 'W';
|
|
$d['S1_BRAND'] = 'WEVIA EM';
|
|
$d['S1_BRAND_SUB'] = 'ENTERPRISE MODEL';
|
|
$d['S1_COUNTER_VALUE'] = '669';
|
|
$d['S1_COUNTER_LABEL'] = 'Agents IA Autonomes';
|
|
$d['S1_TITLE'] = 'La workforce IA la plus complète.<br><em>17 départements. Un seul cerveau.</em>';
|
|
$d['S1_TAGS'] = '<div class="s1-t gl2"><b>17</b> <span>Depts</span></div><div class="s1-t gl2"><b>93</b> <span>Crons</span></div><div class="s1-t gl2"><b>12</b> <span>LLMs</span></div><div class="s1-t gl2"><b>0€</b> <span>Lock-in</span></div>';
|
|
$d['S2_TITLE'] = 'Architecture SOA - 6 Couches';
|
|
$d['S2_SUBTITLE'] = 'Chaque couche pilotee par des agents specialises';
|
|
$d['S2_LAYERS'] = '<div class="s2-r gl" style="border-left:3px solid var(--cy)"><div class="s2-i">🖥</div><div><div class="s2-nm">Presentation</div><div class="s2-ds">Dashboards - Portails - Chat</div></div><div class="s2-k" style="color:var(--cy)">9 apps</div></div><div class="s2-r gl" style="border-left:3px solid var(--or)"><div class="s2-i">🎯</div><div><div class="s2-nm">Orchestration</div><div class="s2-ds">WEVIA Master - BPMN - 17 Orchestrators</div></div><div class="s2-k" style="color:var(--or)">17 flux</div></div><div class="s2-r gl" style="border-left:3px solid var(--gr)"><div class="s2-i">🤖</div><div><div class="s2-nm">Agents IA</div><div class="s2-ds">Finance - RH - Marketing - Commerce - Supply - Prod</div></div><div class="s2-k" style="color:var(--gr)">669</div></div><div class="s2-r gl" style="border-left:3px solid var(--ac)"><div class="s2-i">🧠</div><div><div class="s2-nm">Intelligence</div><div class="s2-ds">LLM Souverain 0EUR - RAG - KB 2490</div></div><div class="s2-k" style="color:var(--ac)">12 LLMs</div></div><div class="s2-r gl" style="border-left:3px solid var(--t2)"><div class="s2-i">🔌</div><div><div class="s2-nm">Data et Integration</div><div class="s2-ds">API Gateway - ETL - 6.6M contacts</div></div><div class="s2-k" style="color:var(--t2)">302 APIs</div></div><div class="s2-r gl" style="border-left:3px solid var(--pu)"><div class="s2-i">🛡</div><div><div class="s2-nm">Gouvernance</div><div class="s2-ds">Securite - Compliance - NonReg 152/152</div></div><div class="s2-k" style="color:var(--pu)">100%</div></div>';
|
|
$d['S2_SIDEBAR'] = 'GOVERNANCE - SECURITY - COMPLIANCE';
|
|
$d['S3_BRAND'] = 'WEVIA EM';
|
|
$d['S3_SUBTITLE'] = 'VALUE STREAM MAPPING';
|
|
$d['S3_DEPTS'] = "{n:'Finance',c:'#4f7df9',y:.06},{n:'RH',c:'#22d3ee',y:.18},{n:'Marketing',c:'#f59e0b',y:.30},{n:'Commerce',c:'#10b981',y:.42},{n:'Supply Chain',c:'#ef4444',y:.54},{n:'Production',c:'#a78bfa',y:.66},{n:'SI & Data',c:'#4f7df9',y:.78},{n:'QA & Cyber',c:'#f472b6',y:.90}";
|
|
$d['S4_TITLE'] = 'Demarrez par un <em>POC gratuit</em>';
|
|
$d['S4_SUBTITLE'] = 'Choisissez un process metier. Nous deployons nos agents. Vous mesurez impact.';
|
|
$d['S4_CARDS'] = '<div class="s4-c gl"><div class="ic">🎯</div><h3>POC Gratuit</h3><p>1 process, resultats en 2 semaines</p></div><div class="s4-c gl"><div class="ic">🚀</div><h3>MVP - 1 Mois</h3><p>3-5 process, ROI documente</p></div><div class="s4-c gl"><div class="ic">🏢</div><h3>Full Enterprise</h3><p>17 depts, 669 agents, 3 mois</p></div>';
|
|
$d['S4_QUOTE'] = 'Les autres offrent une plateforme pour <b>construire</b> des agents.<br>WEVIA livre une <b>workforce autonome complete</b> - 669 agents prets.';
|
|
$d['S4_CTA_TEXT'] = 'Demander un POC gratuit';
|
|
$d['S4_CTA_URL'] = 'https://weval-consulting.com';
|
|
$d['S4_FOOTER'] = 'WEVAL Consulting - Casablanca - weval-consulting.com';
|
|
$content = $tpl;
|
|
foreach ($d as $key => $val) { $content = str_replace('{{' . $key . '}}', $val, $content); }
|
|
$content = preg_replace('/\{\{[A-Z0-9_]+\}\}/', '', $content);
|
|
if (file_exists($path)) @copy($path, $path . '.bak');
|
|
$w = @file_put_contents($path, $content);
|
|
if ($w === false) return ['ok'=>false,'error'=>'Ecriture echouee'];
|
|
$git = @shell_exec('cd /var/www/html && git add ' . escapeshellarg(basename($path)) . ' 2>&1 && git commit -m ' . escapeshellarg('wevia-master: template ' . basename($path)) . ' 2>&1|tail -3 && git push 2>&1|tail -2');
|
|
return ['ok'=>true,'path'=>$path,'size'=>strlen($content),'bytes'=>$w,'provider'=>'template+defaults','template'=>basename($tpl_file),'git'=>trim($git ?? ''),'message'=>"Fichier cree via template Opus: {$path} ({$w} bytes)"];
|
|
}
|
|
$sp = 'Tu es WEVIA Master. 669 agents, 17 departements, 93 crons, 12 LLMs. Dark theme. Code complet SANS backticks.';
|
|
$ch = curl_init('http://127.0.0.1:4000/v1/chat/completions');
|
|
curl_setopt_array($ch, [CURLOPT_POST=>true, CURLOPT_HTTPHEADER=>['Content-Type: application/json'], CURLOPT_POSTFIELDS=>json_encode(['messages'=>[['role'=>'system','content'=>$sp],['role'=>'user','content'=>"Cree {$path}: {$msg}"]],'max_tokens'=>16000,'stream'=>false]), CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>120]);
|
|
$resp = curl_exec($ch); $hc = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch);
|
|
if ($hc !== 200) return ['ok'=>false,'error'=>'LLM down'];
|
|
$data = @json_decode($resp, true);
|
|
$content = trim($data['choices'][0]['message']['content'] ?? '');
|
|
$content = preg_replace('/^```[a-z]*\n/', '', $content);
|
|
$content = preg_replace('/\n```[\s\S]*$/', '', $content);
|
|
if ($ext === 'html') { $he = strrpos($content, '</html>'); if ($he !== false) $content = substr($content, 0, $he + 7); }
|
|
if (strlen($content) < 50) return ['ok'=>false,'error'=>'Contenu trop court'];
|
|
if (file_exists($path)) @copy($path, $path . '.bak');
|
|
$w = @file_put_contents($path, $content);
|
|
if ($w === false) return ['ok'=>false,'error'=>'Ecriture echouee'];
|
|
$git = @shell_exec('cd /var/www/html && git add ' . escapeshellarg(basename($path)) . ' 2>&1 && git commit -m ' . escapeshellarg('wevia-master: file_write ' . basename($path)) . ' 2>&1|tail -3 && git push 2>&1|tail -2');
|
|
return ['ok'=>true,'path'=>$path,'size'=>strlen($content),'bytes'=>$w,'provider'=>'sovereign','git'=>trim($git ?? ''),'message'=>"Fichier cree: {$path} ({$w} bytes)"];
|
|
}
|