function xmlHttpsReq($xml,$type){ $ch = curl_init('https://IP_:/mobile_request/'.$type.'.aspx?admin'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); $data=curl_exec($ch); $result=substr($data,0,strpos($data,'</Root>')+7); if( curl_errno($ch) != 0 ) { die('CURL_error: ' . curl_errno($ch) . ', ' . curl_error($ch)); }; curl_close($ch); return $result; }
function getUserList() { $data=xmlHttpsReq('<commands><command name="Get" table="User" /></commands>','get'); $xml = new SimpleXMLElement($data); foreach ($xml->command->user as $user) { $usr[]=$user; } return $usr; }
function getUser($ID) { $data=xmlHttpsReq('<commands><command name="Get" table="User"><item><id>'.$ID.'</id></item></command></commands>','get'); $xml = new SimpleXMLElement($data); return $xml->command->user; }
function setUser($arr) { $converter = new Array2XML(); $obj = $converter->convert($arr); $data=xmlHttpsReq('<commands><command name="Edit" table="User">'.$obj.'</command></commands>','set'); $xml = new SimpleXMLElement($data); return $xml->command->item->result; }
class Array2XML { private $writer; private $rootName = 'item'; function __construct() { $this->writer = new XMLWriter(); } public function convert($data) { $this->writer->openMemory(); $this->writer->startElement($this->rootName); if (is_array($data)) { $this->getXML($data); } $this->writer->endElement(); return $this->writer->outputMemory(); } public function setVersion($version) { $this->version = $version; } public function setEncoding($encoding) { $this->encoding = $encoding; } public function setRootName($rootName) { $this->rootName = $rootName; } private function getXML($data) { foreach ($data as $key => $val) { if (is_numeric($key)) { $key = 'key'.$key; } if (is_array($val)) { $this->writer->startElement($key); $this->getXML($val); $this->writer->endElement(); } else { $this->writer->writeElement($key, $val); } } } }
mysql_connect(HOST,USERNAME,PASSWORD); mysql_select_db(DBNAME); // RTU $allusers = getUserList(); // LanBilling $res = mysql_query("SELECT CASE WHEN blk_req != 0 AND blk_req = blocked THEN 'true' WHEN blk_req != 0 AND blocked = 0 THEN 'false' ELSE 'none' END AS blk, login FROM vgroups WHERE blk_req != 0"); while ($row=mysql_fetch_array($res)) { unset($user); foreach($allusers as $allusr) { if($allusr->id==$row['login']) { $user=$allusr; break; } } if (($user)&&($row['blk']!='none')) { if(setUser(array('id'=>$user->id,'guid'=>$user->guid,'enabled'=>$row['blk']))=='true') $ids[] = $row['vg_id']; // RTU LanBilling } else $ids[] = $row['vg_id']; } // if (count(@$ids)>0) { $sql = 'UPDATE vgroups SET blocked = IF(blk_req = blocked, 0, blk_req), blk_req = 0, blk_req_user = "" WHERE vg_id IN (' . implode(',', $ids) . ')'; mysql_query($sql); }
Source: https://habr.com/ru/post/126412/
All Articles