<?php
require __DIR__.'/NativeGate.php';$good=['SELECT COUNT(*) AS tp_count FROM `ydy_nutrition` WHERE is_del = 1','SELECT a.*,b.name as set_name FROM `ydy_nutrition` a LEFT JOIN `ydy_nutrition_set` b ON b.uuid=a.set_uuid WHERE a.name LIKE ? LIMIT 1','SHOW COLUMNS FROM `ydy_nutrition`','SHOW COLUMNS FROM `ydy_config`','CALL SP_TABLEDEF(?, ?)',NRGate::$bootstrap];foreach($good as $s)NRGate::sql($s);
$bound=[':where_AND_status'=>['value'=>1,'type'=>PDO::PARAM_INT]];foreach(['morning_start','morning_end','noon_start','noon_end','night_start','night_end']as $i=>$k)$bound[':where_AND_config_key_in_'.($i+1)]=['value'=>$k,'type'=>PDO::PARAM_STR];NRGate::binds(NRGate::$bootstrap,$bound,null);NRGate::binds('CALL SP_TABLEDEF(?, ?)',['1'=>['value'=>'ZHCT_APP','type'=>2],'2'=>['value'=>'YDY_CONFIG','type'=>2]],null);
$bad=['UPDATE ydy_nutrition SET fat=0','INSERT INTO ydy_nutrition VALUES (1)','DELETE FROM ydy_nutrition','SELECT * FROM ydy_staff','SELECT * FROM ydy_nutrition; DELETE FROM ydy_user','SELECT * FROM ydy_nutrition INTO OUTFILE x','SELECT SLEEP(1) FROM ydy_nutrition','CALL anything(?,?)','SELECT * FROM ydy_nutrition -- x','SELECT * FROM ydy_config',str_replace('`config_key`,`config_value`','*',NRGate::$bootstrap),NRGate::$bootstrap.'; SELECT 1'];$n=0;foreach($bad as $s){try{NRGate::sql($s);throw new LogicException('Accepted readonly escape');}catch(RuntimeException $e){$n++;}}
foreach(['key','type','extra']as $bad){$b=$bound;if($bad==='key')$b[':where_AND_config_key_in_1']['value']='secret';if($bad==='type')$b[':where_AND_status']['type']=2;if($bad==='extra')$b['extra']=['value'=>1,'type'=>1];try{NRGate::binds(NRGate::$bootstrap,$b,null);throw new LogicException('Accepted config escape');}catch(RuntimeException $e){$n++;}}
foreach([['OTHER','YDY_CONFIG'],['ZHCT_APP','YDY_STAFF']]as $b){try{NRGate::binds('CALL SP_TABLEDEF(?, ?)',['1'=>['value'=>$b[0],'type'=>2],'2'=>['value'=>$b[1],'type'=>2]],null);throw new LogicException('Accepted schema escape');}catch(RuntimeException $e){$n++;}}
echo json_encode(['positive'=>8,'negative'=>$n,'HTTP'=>0,'DB_connections'=>0,'DML'=>0]),"\n";
