| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627 |
- <?php
- namespace MGModule\DNSManager2\controllers\addon\clientarea;
- use Exception;
- use MGModule\DNSManager2 as main;
- use MGModule\DNSManager2\helpers\custom\ClientFilesManage;
- use MGModule\DNSManager2\mgLibs\custom;
- use MGModule\DNSManager2\mgLibs\custom\AjaxResponse;
- use MGModule\DNSManager2\mgLibs\custom\dns\record\Record;
- use MGModule\DNSManager2\mgLibs\custom\dns\utils\IP;
- use MGModule\DNSManager2\mgLibs\custom\dns\utils\ReverseDNSHelper;
- use MGModule\DNSManager2\mgLibs\custom\helpers\RecordSetHelper;
- use MGModule\DNSManager2\mgLibs\custom\helpers\ZoneLogger\Manager as ZoneLoggerManager;
- use MGModule\DNSManager2\mgLibs\custom\manager\BlockerHelper;
- use MGModule\DNSManager2\mgLibs\custom\manager\ClientHelper;
- use MGModule\DNSManager2\mgLibs\custom\manager\GlobalSettingHelper;
- use MGModule\DNSManager2\mgLibs\custom\manager\LogHelper;
- use MGModule\DNSManager2\mgLibs\custom\manager\ZoneCreator;
- use MGModule\DNSManager2\mgLibs\custom\manager\ZoneRemover;
- use MGModule\DNSManager2\mgLibs\custom\relateditem\RelatedItem;
- use MGModule\DNSManager2\mgLibs\custom\reverse\IPHelper;
- use MGModule\DNSManager2\mgLibs\lang;
- use MGModule\DNSManager2\mgLibs\MySQL\query;
- use MGModule\DNSManager2\models\custom\globalsetting\GlobalSettingEnum;
- use MGModule\DNSManager2\models\custom\package\setting\PackageSettingEnum;
- use MGModule\DNSManager2\models\custom\reverse;
- use MGModule\DNSManager2\models\custom\server\setting\ServerSettingEnum;
- use MGModule\DNSManager2\models\custom\set;
- use MGModule\DNSManager2\models\custom\status;
- use MGModule\DNSManager2\models\custom\task;
- use MGModule\DNSManager2\models\custom\zone\Zone;
- use WHMCS\Database\Capsule as DB;
- //TODO: (nie miałem gdzie dodać) Synchronizacja rdnsów (w obie strony, porównywac rekordy z serverem)
- //TODO: edit zone -> records encode itp
- //TODO: ogarnąć ten bajzel w kontrolerach
- class dashboard extends main\mgLibs\process\abstractController
- {
- private $set_form = array(
- 'edit' => false,
- 'name' => '',
- 'count' => 0,
- );
- public function __construct($input)
- {
- parent::__construct($input);
- if($_REQUEST['mg-action'] == 'manageRDNS' && GlobalSettingHelper::getSetting(GlobalSettingEnum::RDNS_IN_CLIENTAREA) == GlobalSettingEnum::CLIENTAREA_RNDS_BLOCK)
- {
- redir('m=DNSManager2');
- }
- }
- function indexHTML($input, $vars = array())
- {
- $this->redirectIfIsOnlyRDNSforCA();
- $helper = new ClientHelper($_SESSION['uid']);
- $groups = $helper->getGroups();
- $groups_info = array();
- foreach($groups as $key => $group)
- {
- $sum = array();
- $zones_count = 0;
- foreach($group as $key2 => $zone)
- {
- if($zone['zone_id'])
- {
- $check = $helper::getServerStatusByZoneId($zone['zone_id']);
- $group[$key2]['server_status'] = $check['status'];
- $zones_count++;
- }
- $sum[$zone['type'] .'::'.$zone['relid']] = $zone['zones_available'];
- }
- $groups_info[$key]['zones_available'] = array_sum($sum);
- $groups_info[$key]['zones_count'] = $zones_count;
- $groups_info[$key]['type'] = $zone['type'];
- $groups_info[$key]['relid'] = $zone['relid'];
- $groups_info[$key]['full'] = $groups_info[$key]['zones_available'] <= $groups_info[$key]['zones_count'];
- $obGroup = new \stdClass();
- $obGroup->group = $group;
- $obGroup->product_group_name = $zone['product_group_name'];
- $obGroup->product_name = $zone['product_name'];
- $obGroup->product_id = $zone['product_id'];
- $obGroup->domain = $zone['domain'];
- $obGroup->groupKey = $key;
- $groups[$key] = $obGroup;
- }
- unset($key);
- usort($groups, $this->arraySortByValue('domain'));
- if($groups[0]->groupKey === 'Other')
- {
- $groups[] = $groups[0];
- unset($groups[0]);
- }
- $vars['groups'] = $groups;
- $vars['groups_info'] = $groups_info;
- $vars['manage_rdns'] = $this->getRDNSStatus();
- $vars['manageRecordsSets'] = GlobalSettingHelper::getSetting(GlobalSettingEnum::LINK_TO_DNS_SETS_MANAGER, true);
- $vars['clientarea_import_export'] = GlobalSettingHelper::getSetting(GlobalSettingEnum::LINK_TO_CLIENTAREA_IMPORT_EXPORT, true);
- $vars['showProductName'] = GlobalSettingHelper::getSetting(GlobalSettingEnum::SHOW_PRODUCT_NAME, false);
- return [
- 'tpl' => 'dashboard',
- 'vars' => $vars
- ];
- }
- /**
- * @return bool
- */
- private function getRDNSStatus()
- {
- if( GlobalSettingHelper::getSetting(GlobalSettingEnum::RDNS_IN_CLIENTAREA, true) !== 'clientarea_rdns_allow' )
- {
- return false;
- }
- $rdnsPossibleToAdd = (bool)count($this->getUserPackageItems($_SESSION['uid']));
- $rdnsAlreadyCreated = (bool)query::query("SELECT COUNT(`id`)
- FROM `dns_manager2_reverse`
- WHERE `clientid` = :clientid", ['clientid' => $_SESSION['uid']])->fetchColumn();
- if(!$rdnsAlreadyCreated && !$rdnsPossibleToAdd)
- {
- return false;
- }
- return true;
- }
- public function addZoneJSON($input, $vars = array())
- {
- //TODO: sytuacje gdy ip nie jest konieczne w module + default ip
- $vars = IPHelper::getIPsArray($_SESSION['uid'], $input['type'], $input['relid']);
- $vars['ipmanager'] = !empty($vars['pools']);
- $vars['type'] = $input['type'];
- $vars['relid'] = $input['relid'];
- $vars['custom_ip'] = IPHelper::isCustomIPEnabledForZoneCreate();
- $helper = new ClientHelper($_SESSION['uid']);
- $allowed_ips = $helper->getPackageAllowedIps(intval($vars['relid']), intval($vars['type']));
- $vars['allowed_ips'] = IP::getAvailableIpList(json_decode($allowed_ips['allowed_ips']));
- $vars['allowed_ips_flag'] = is_array($vars['allowed_ips']) && !empty($vars['allowed_ips']) && $vars['allowed_ips'][0] != null;
- $ip_blacklist = $helper->getPackageIpBlacklist(intval($vars['relid']), intval($vars['type']));
- $vars['ip_blacklist'] = IP::getAvailableIpList(json_decode($ip_blacklist['ip_blacklist']));
- $vars['ip_blacklist_flag'] = is_array($vars['ip_blacklist']) && !empty($vars['ip_blacklist']) && $vars['allowed_ips'][0] != null;
- if($input['type'] != main\models\custom\zone\ZoneTypeEnum::DOMAIN)
- {
- $vars['is_not_domain'] = true;
- }
- $vars['is_ip_required'] = true;
- $groupMainDomain = custom\helpers\ZoneSettings::getOneDomain($vars['relid'], $vars['type']);
- if($groupMainDomain)
- {
- $simulateCreation = new ZoneCreator($groupMainDomain->domain, $vars['type'], $vars['relid'], false, $groupMainDomain->clientID());
- if ($simulateCreation->server) {
- $vars['is_ip_required'] = $simulateCreation->server->getModule()->isIPRequired();
- }
- }
- if($input['type'] == '0' && $input['relid'] == '0')
- {
- $vars['custom_ip'] = 1;
- $creator = new ZoneCreator('', $input['type'], $input['relid'], false, $_SESSION['uid']);
- }
- else
- {
- $creator = new ZoneCreator('', $input['type'], $input['relid']);
- }
- $defaultSets = $creator->getPackage()->getAdminSets();
- $adminSets = set\Repository::factory()->adminOnly()->get();
- foreach ($adminSets as $key => $value) {
- if( !in_array( $value->id, $defaultSets))
- {
- unset($adminSets[$key]);
- }
- }
- $vars['zoneDomainItems'] = custom\helpers\ZoneSettings::getProperlyItems($_SESSION['uid'], $vars['relid'], $vars['type']);
- $vars['adminSets'] = $adminSets;
- $vars['allowManageRecordsSets'] = GlobalSettingHelper::getSetting(GlobalSettingEnum::LINK_TO_DNS_SETS_MANAGER, true);
- $vars['recordSets'] = set\Repository::factory()->byUserId((int)$_SESSION['uid'])->get();
- $vars['allowManageRecordsSets'] = (count($vars['recordSets']) > 0 || count($vars['adminSets']) > 0) ? $vars['allowManageRecordsSets'] : false;
- return AjaxResponse::I()->modal('add-zone', $vars)->toArray();
- }
- public function addZoneSaveJSON($input, $vars = array())
- {
- $helper = new ClientHelper($_SESSION['uid']);
- if(!$helper->canUserCreatesNewZonesIn($input['type'], $input['relid'])) {
- return AjaxResponse::I()->addError('you_cant_add_new_zones_within_this_group')->toArray();
- }
- if(GlobalSettingHelper::getSetting(GlobalSettingEnum::OWNED_DOMAINS_ONLY) == 'on' && !in_array($input['zone_name'], $helper->getClientDomains())) {
- return AjaxResponse::I()->addError('you_cant_use_domain_that_does_not_belong_to_you')->toArray();
- }
- $zoneName = $input['zone_name'];
- $blockerHelper = new BlockerHelper();
- $isBlocked = false;
- $allowedIps = json_decode($helper->getPackageAllowedIps($input['relid'],$input['type'])['allowed_ips']);
- $ipBlacklist = json_decode($helper->getPackageIpBlacklist($input['relid'],$input['type'])['ip_blacklist']);
- if($input['is_ip_required']) {
- if (is_array($allowedIps) && !empty($allowedIps)) {
- if (!in_array($input['zone_ip'], $allowedIps)) return AjaxResponse::I()->addError('not_allowed_ip')->toArray();
- }
- if (in_array($input['zone_ip'], $ipBlacklist))
- return AjaxResponse::I()->addError('ip_on_blacklist')->toArray();
- }
- if(!$blockerHelper->isLoggedUserExcluded()) {
- $rules = $blockerHelper->getRules();
- foreach($rules as $rule) {
- $rule = trim($rule);
- if($blockerHelper->isRecordBlocked($rule, $zoneName)) {
- $isBlocked = true;
- break;
- }
- }
- }
- if($isBlocked) {
- return AjaxResponse::I()->addError('value_is_blocked')->toArray();
- }
- if(strpos($input['zone_ip'], 'block') !== false) {
- list($str,$pool,$mask) = explode('|',$input['zone_ip']);
- $ip = new IP($input['zone_ip_from_block']);
- if(!$ip->isInNetwork($pool, $mask)) {
- return AjaxResponse::I()->addError('ip_is_not_belongs_to_selected_block')->toArray();
- }
- $input['zone_ip'] = $input['zone_ip_from_block'];
- }
- // $ip_array = IPHelper::getIPsArray($_SESSION['uid'], $input['type'], $input['relid']);
- // if(!in_array($input['zone_ip'], $ip_array['all_ips']) && !empty($input['zone_ip'])) {
- // return AjaxResponse::I()->addError('you_cant_use_ip_that_not_belongs_to_you')->toArray();
- // }
- if(!custom\helpers\ZoneSettings::isDomainClient($input['zone_name'], $input['type'], $input['relid'], $_SESSION['uid']))
- {
- return AjaxResponse::I()->addError('zone_does_not_belongToYou')->toArray();
- }
- try
- {
- $ip = new IP($input['zone_ip']);
- if(!empty($input['zone_ip']) && (!$ip->isValid() || $input['type'] != '0' || $input['relid'] != '0'))
- {
- IPHelper::validateIfClientCanUseIP($_SESSION['uid'], $input['type'], $input['relid'], $input['zone_ip'], true);
- }
- $creator = new ZoneCreator($input['zone_name'], $input['type'], $input['relid'], $input['zone_ip'], $_SESSION['uid']);
- $creator->setZoneLoggerManager(new ZoneLoggerManager($_SESSION['uid']));
- $packageID = $creator->getPackage()->id;
- $limitCheck = main\mgLibs\custom\helpers\RecordSetHelper::checkAllowedRecordsLimits($packageID, $input['recordSet']);
- if(!$limitCheck)
- {
- return AjaxResponse::I()->addError('you_have_exceeded_limit')->toArray();
- }
- $ret = $creator->create($input['recordSet']);
- if(is_string($ret))
- {
- return AjaxResponse::I()->addRawError($ret)->toArray();
- }
- AjaxResponse::I()->addInfo('zone_created_successfully');
- }
- catch(Exception $exc)
- {
- AjaxResponse::I()->addRawError($exc->getMessage());
- }
- return AjaxResponse::I()->refreshPage($this->indexHTML($input))->toArray();
- }
- public function removeZoneJSON($input, $vars = array()) {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- if(!$helper->isZoneOwnedByClient($zone)) {
- return AjaxResponse::I()->addError('you_cant_remove_this_zone_because_it_is_not_belongs_to_you')->toArray();
- }
- if($zone->is_locked){
- return AjaxResponse::I()->addError('you_cannot_edit_zone_that_is_not_your_own_zone')->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addError('you_cannot_remove_this_zone_because_server_is_not_active')->toArray();
- }
- try {
- ZoneRemover::removeZone($zone);
- main\mgLibs\custom\helpers\StatusHelper::removeZoneStatus($input['id']);
- $zoneLoggerManager = new ZoneLoggerManager($_SESSION['uid']);
- $zoneLoggerManager->logTerminateZoneAction($zone);
- // LogHelper::addSuccessLogUsingZone('Remove Zone', '', $zone);
- } catch (Exception $exc) {
- LogHelper::addFailLogUsingZone('Remove Zone', $exc->getMessage(), $zone);
- throw $exc;
- }
- AjaxResponse::I()->refreshPage($this->indexHTML($input));
- AjaxResponse::I()->addInfo('zone_removed_successfully');
- return AjaxResponse::I()->toArray();
- }
- public function createZoneJSON($input, $vars = array())
- {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- if(!$helper->isZoneOwnedByClient($zone))
- {
- return AjaxResponse::I()->addError('you_cant_create_this_zone_because_it_is_not_belongs_to_you')->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addError('you_cannot_create_this_zone_because_server_is_not_active')->toArray();
- }
- try
- {
- $zoneLogger = new main\mgLibs\custom\helpers\ZoneLogger\Manager($_SESSION['uid']);
- $module = $zone->getModule();
- if(!$module->zoneExists())
- {
- $module->activateZone();
- $zoneLogger->logCreateZoneAction($zone);
- }
- $setHelper = new main\mgLibs\custom\helpers\RecordSetHelper($zone, $zoneLogger);
- $setHelper->addRecordSet();
- $zone->setThatExist();
- // LogHelper::addSuccessLogUsingZone('Add Zone', '', $zone);
- }
- catch(Exception $exc)
- {
- LogHelper::addFailLogUsingZone('Add Zone', $exc->getMessage(), $zone);
- throw $exc;
- }
- AjaxResponse::I()->refreshPage($this->indexHTML($input));
- AjaxResponse::I()->addInfo('zone_created_successfully');
- return AjaxResponse::I()->toArray();
- }
- private function checkWhmcsProductStatus($type, $relid)
- {
- switch($type)
- {
- case 1:
- $status = main\mgLibs\MySQL\query::select(array('status'), 'tbldomains', array('id' => $relid))->fetchAll();
- $status = $status[0]['status'];
- break;
- case 2:
- $status = main\mgLibs\MySQL\query::select(array('domainstatus'), 'tblhosting', array('id' => $relid))->fetchAll();
- $status = $status[0]['domainstatus'];
- break;
- case 3:
- $status = main\mgLibs\MySQL\query::select(array('status'), 'tblhostingaddons', array('id' => $relid))->fetchAll();
- $status = $status[0]['status'];
- break;
- default:
- $status = 'Active';
- break;
- }
- return strtolower($status);
- }
- public function editZoneHTML($input, $vars = array())
- {
- $this->redirectIfIsOnlyRDNSforCA();
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- $whmcsOrderStatus = $this->checkWhmcsProductStatus($zone->type, $zone->relid) == 'active' ? false : true;
- if($this->isTransferAndShouldBeAbleToEdit($zone))
- {
- $whmcsOrderStatus = false;
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$helper->isZoneOwnedByClient($zone))
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_it_is_not_belongs_to_you');
- }
- elseif(!$checkServer['status'])
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_server_is_not_active');
- }elseif ($zone->is_locked){
- $vars['error'] = lang::T('You cannot edit this zone because it\'s locked');
- }elseif ($whmcsOrderStatus)
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_order_is_not_active');
- }
- else
- {
- $module = $zone->getModule();
- if(!$module->zoneExists())
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_it_is_terminated_on_server');
- $zone->setThatNotExist();
- }
- else
- {
- $vars['zone_name'] = $zone->name;
- $vars['zoneid'] = $zone->id;
- $vars['ttl_disabled'] = !$module->isTTLEnabled();
- $vars['records'] = $module->getRecords();
- $vars['records'] = array_merge($vars['records'], $this->getPTRRecords($zone));
- $soaList = array();
- $limits = $this->getPackageRecordsLimits($zone);
- foreach($vars['records'] as $key => &$record)
- {
- if(!isset($limits[$record->type]) ){
- unset($vars['records'][$key]);
- }
- $record->encode();
- if($record->type === 'SOA' && array_key_exists('SOA', $limits))
- {
- $soaList[] = $record;
- unset($vars['records'][$key]);
- }
- }
- usort($vars['records'], $this->arraySortByValue('type'));
- foreach($soaList as $soaRecord)
- {
- array_unshift($vars['records'] , $soaRecord);
- }
- $rep = status\Repository::factory()->setFilter('relid', $zone->id)->get();
- if(!$rep)
- {
- $status = 'pending';
- }
- else
- {
- $status = $rep[0]->status;
- }
- $status = main\mgLibs\custom\helpers\StatusHelper::parseStatus($status);
- $soaAlert = GlobalSettingHelper::getSetting(GlobalSettingEnum::SOA_IS_NOT_NS_STATUS);
- $domainAvailableAlert = GlobalSettingHelper::getSetting(GlobalSettingEnum::WHOIS_MISSING_STATUS);
- $activeAlert = GlobalSettingHelper::getSetting(GlobalSettingEnum::IS_OK_STATUS);
- $pendingAlert = GlobalSettingHelper::getSetting(GlobalSettingEnum::IS_PENDING_STATUS);
- if($status == 'pending' && $pendingAlert == 'on')
- {
- $vars['tpl'] = 'pending';
- }
- elseif($status == 'notRegistered' && $domainAvailableAlert == 'on')
- {
- $vars['tpl'] = 'notRegistered';
- }
- elseif($status == 'soaWarning' && $soaAlert == 'on')
- {
- $vars['tpl'] = 'soaWarning';
- }
- elseif($status == 'active' && $activeAlert == 'on')
- {
- $vars['tpl'] = 'active';
- }
- else
- {
- $vars['tpl'] = 'standard';
- }
- $content = main\mgLibs\custom\helpers\StatusHelper::loadStatusContent($vars['tpl']);
- $recordLimits = $this->getPackageRecordsLimits($zone);
- array_walk($recordLimits, function (&$limit) use ($recordLimits){
- if ((int)$limit === -1 && isset($recordLimits['total']))
- {
- $limit = $recordLimits['total'];
- }
- });
- $vars['available_record_types'] = $module->getAvailableRecordTypes();
- $vars['content'] = html_entity_decode(str_replace('{$domain}', $zone->name, $content));
- $vars['counter'] = 0;
- $vars['zone_name'] = $zone->name;
- $vars['id'] = $zone->id;
- $vars['records_count'] = $this->countRecords($vars['records']);
- $vars['limits'] = $recordLimits;
- $vars['enable_dnssec'] = $zone->getServer()->getSettings(ServerSettingEnum::ENABLE_DNSSEC) == 'on' && $module->isDNSSECSupported();
- $showNameservers = GlobalSettingHelper::getSetting(GlobalSettingEnum::SHOW_NAMESERVERS);
- $vars['nameservers'] = $showNameservers == 'on' ? $module->getNameServers(false) : [];
- }
- }
- $vars['show_full_record_name'] = GlobalSettingHelper::getSetting(GlobalSettingEnum::SHOW_FULL_RECORD_NAME);
- return array(
- 'tpl' => 'edit',
- 'vars' => $vars
- );
- }
- private function getPTRRecords($zone) {
- $out = array();
- foreach(reverse\Repository::factory()->from($zone->getServer()->id, $zone->name)->byClientID($zone->clientid)->get() as $data) {
- $ptr = new main\mgLibs\custom\dns\record\Record();
- $ptr->name = ReverseDNSHelper::reverseRecordName($data->ip) . '.' . $data->name;
- $ptr->type = 'PTR';
- $ptr->ttl = $data->ttl;
- $ptr->ip = $data->ip;
- $ptr->createRDATAObject('PTR');
- $ptr->rdata->setFirstProperty(empty($data->sub)?$data->from:$data->sub . '.' . $data->from);
- $out[] = $ptr;
- }
- return $out;
- }
- private function getPackageRecordsLimits(Zone $zone) {
- $package = $zone->getPackage();
- if($package == false) {
- return array('total' => 0);
- }
- $out = unserialize($package->getSettings(PackageSettingEnum::ALLOWED_RECORD_TYPES))?:array();
- $out['total'] = $this->getTotalRecordsLimit($zone);
- if(isset($out['PTR'])) {
- if($zone->getServer()->getSettings(ServerSettingEnum::ALLOW_RDNS) == 'on') {
- if($out['PTR'] > 1 && !($zone->getServer()->getSettings(ServerSettingEnum::ALLOW_MULTIPLE_PTR) == 'on')) {
- $out['PTR'] = 1;
- }
- } else {
- unset($out['PTR']);
- }
- }
- return $out;
- }
- private function countRecords($records) {
- $records_count = array();
- foreach($records as $record) {
- $records_count[$record->type]++;
- }
- $records_count['total'] = array_sum($records_count);
- return $records_count;
- }
- private function getTotalRecordsLimit(Zone $zone) {
- return $zone->getPackageItem()->limit;
- }
- public function editZoneJSON($input, $vars = array()) {
- return AjaxResponse::I()->refreshPage($this->editZoneHTML($input))->toArray();
- }
- public function removeRecordJSON($input, $vars = array()) {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- if(!$helper->isZoneOwnedByClient($zone)) {
- return AjaxResponse::I()->addError('you_cant_remove_this_record_because_it_is_not_belongs_to_one_of_your_zones')->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addError('you_cannot_edit_this_zone_because_server_is_not_active')->toArray();
- }
- try {
- $record_data = array_pop($input['record']);
- if(empty($record_data))
- {
- $record_data = array_pop($input['edit_record']);
- }
- $module = $zone->getModule();
- if (strtoupper($record_data['type']) == 'PTR') { // REVERSE RECORD
- $ip = $record_data['ip'];
- $record = reverse\Repository::factory()->fromIP($zone->getServer()->id, $ip)->one();
- if ($record === FALSE || $record->from != $zone->name) {
- return AjaxResponse::I()->addError('you_cannot_remove_record_that_is_not_belongs_to_you')->toArray();
- }
- $module->removeRDNS($ip);
- $record->delete();
- } else {
- $record = $this->createRecordFromInputData($record_data);
- $module->deleteRecord($record);
- }
- $zoneLoggerManager = new ZoneLoggerManager($_SESSION['uid']);
- $zoneLoggerManager->logRemoveRecordFromZone($zone, $record);
- } catch (Exception $exc) {
- LogHelper::addFailLogUsingZone('Edit Zone', $exc->getMessage(), $zone);
- throw $exc;
- }
- AjaxResponse::I()->addInfo('record_removed_successfully');
- AjaxResponse::I()->refreshPage($this->editZoneHTML($input));
- return AjaxResponse::I()->toArray();
- }
- private function createRecordFromInputData($input) {
- $record = Record::tryToCreateFromArray($input);
- $record->rdata->setDataFromArray($input['field']);
- $record->decode();
- return $record;
- }
- public function addRecordJSON($input, $vars = array()) {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- $vars = IPHelper::getIPsArray($_SESSION['uid'], $zone->type, $zone->relid);
- $vars['ipmanager'] = !empty($vars['pools']);
- $vars['zone_id'] = $zone->id;
- $vars['available_record_types'] = $zone->getModule()->getAvailableRecordTypes();
- $vars['custom_ip'] = IPHelper::isCustomIPEnabled();
- $vars['ttl_enabled'] = $zone->getModule()->isTTLEnabled();
- $helper = new ClientHelper($_SESSION['uid']);
- if($vars['recordsAllowedIp']) {
- $allowedIps = $helper->getPackageAllowedIps(intval($zone->relid), intval($zone->type));
- $allowedIps = IP::getAvailableIpList(json_decode($allowedIps['allowed_ips']));
- $vars['allowed_ipv4'] = IP::getOnlyIpv4($allowedIps);
- $vars['allowed_ipv4_flag'] = is_array($vars['allowed_ipv4']) && !empty($vars['allowed_ipv4']) && $vars['allowed_ipv4'][0] != null;
- $vars['allowed_ipv6'] = IP::getOnlyIpv6($allowedIps);
- $vars['allowed_ipv6_flag'] = is_array($vars['allowed_ipv6']) && !empty($vars['allowed_ipv6']) && $vars['allowed_ipv6'][0] != null;
- }
- if($vars['recordsBlacklist']) {
- $ipBlacklist = $helper->getPackageIpBlacklist(intval($zone->relid), intval($zone->type));
- $ipBlacklist = IP::getAvailableIpList(json_decode($ipBlacklist['ip_blacklist']));
- $vars['ipv4_blacklist'] = IP::getOnlyIpv4($ipBlacklist);
- $vars['ipv4_blacklist_flag'] = is_array($vars['ipv4_blacklist']) && !empty($vars['ipv4_blacklist']) && $vars['ipv4_blacklist'][0] != null;
- $vars['ipv6_blacklist'] = IP::getOnlyIpv6($ipBlacklist);
- $vars['ipv6_blacklist_flag'] = is_array($vars['ipv6_blacklist']) && !empty($vars['ipv6_blacklist']) && $vars['ipv6_blacklist'][0] != null;
- }
- $limits = $this->getPackageRecordsLimits($zone);
- foreach($vars['available_record_types'] as $k => $record) {
- if(!isset($limits[$record]) || $input['records'][$record] >= $limits[$record] && (int)$limits[$record] !== -1)
- unset($vars['available_record_types'][$k]);
- }
- return AjaxResponse::I()->modal('add-record', $vars)->toArray();
- }
- public function addRecordSaveJSON($input, $vars = array()) {
- if(empty($input['type'])) {
- return AjaxResponse::I()->addError('choose_record_type')->toArray();
- }
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- if(!$helper->isZoneOwnedByClient($zone)) {
- return AjaxResponse::I()->addError('you_cannot_add_record_to_zone_that_is_not_yours')->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addError('you_cannot_edit_this_zone_because_server_is_not_active')->toArray();
- }
- $ipBlacklist = IP::getAvailableIpList(json_decode($helper->getPackageIpBlacklist(intval($zone->relid), intval($zone->type))['ip_blacklist']));
- if($input['type'] === 'PTR')
- $ip = $input['ip'];
- else
- $ip = $input['field']['address'];
- if($ip && !empty($ipBlacklist) && in_array($ip, $ipBlacklist) && $ipBlacklist[0] != null)
- return AjaxResponse::I()->addError('ip_on_blacklist')->toArray();
- $blockerHelper = new BlockerHelper();
- $isBlocked = false;
- if(!$blockerHelper->isLoggedUserExcluded()) {
- $rules = $blockerHelper->getRules();
- foreach($rules as $rule) {
- $rule = trim($rule);
- if($blockerHelper->isRecordBlocked($rule, $input['name'])) {
- $isBlocked = true;
- break;
- }
- }
- }
- if($isBlocked) {
- return AjaxResponse::I()->addError('value_is_blocked')->toArray();
- }
- $module = $zone->getModule();
- try {
- $limits = $this->getPackageRecordsLimits($zone);
- $count = $this->countRecords($module->getRecords());
- if((isset($limits[$input['type']])
- && (int)$limits[$input['type']] !== -1
- && $count[$input['type']] >= $limits[$input['type']])
- || $limits['total'] <= $count['total'] ) {
- return AjaxResponse::I()->addError('you_cant_add_this_record_because_you_reach_limit')->toArray();
- }
- if(strtoupper($input['type']) == 'PTR') {
- if(strpos($input['ip'], 'block') !== false) {
- list($str,$pool,$mask) = explode('|',$input['ip']);
- $ip = new IP($input['ip_from_block']);
- if(!$ip->isInNetwork($pool, $mask)) {
- return AjaxResponse::I()->addError('ip_is_not_belongs_to_selected_block')->toArray();
- }
- $input['ip'] = $input['ip_from_block'];
- }
- $ip = $input['ip'];
- // if(empty($ip)) {
- // return AjaxResponse::I()->addError('ip_cannot_be_empty')->toArray();
- // }
- //
- // $ip_array = IPHelper::getIPsArray($_SESSION['uid'], $zone->type, $zone->relid);
- // if(!in_array($ip, $ip_array['all_ips'])) {
- // return AjaxResponse::I()->addError('you_cant_use_ip_that_not_belongs_to_you')->toArray();
- // }
- IPHelper::validateIfClientCanUseIP($_SESSION['uid'], $zone->type, $zone->relid, $ip);
- $input['subdomain'] = trim($input['subdomain']);
- $name = !empty($input['subdomain'])?$input['subdomain'].'.'.$zone->name: $zone->name;
- $record = new main\mgLibs\custom\reverse\ReverseDNS($zone);
- $record->setDomain($name);
- $record->setIP($ip);
- $record->setTTL($input['ttl']);
- $record->create();
- } else {
- $record = $this->createRecordFromInputData($input);
- $record->encode();
- $record->nameToAbsolute($zone->name);
- if($record->validateName() !== true) {
- return AjaxResponse::I()->addError($record->validateName())->toArray();
- }
- try {
- $record->rdata->validate();
- } catch (Exception $e) {
- return AjaxResponse::I()->addError($e->getMessage())->toArray();
- }
- $module->addRecord($record);
- }
- $zoneLoggerManager = new ZoneLoggerManager($_SESSION['uid']);
- $zoneLoggerManager->logAddRecordToZone($zone, $record);
- // LogHelper::addSuccessLogUsingZone('Edit Zone', '', $zone);
- AjaxResponse::I()->addInfo('new_record_added_to_zone');
- return $this->editZoneJSON($input, $vars);
- }
- catch (custom\dns\exceptions\DNSSubmoduleHiddenException $exc )
- {
- LogHelper::addFailLogUsingZone('Edit Zone', $exc->getMessage(), $zone);
- return AjaxResponse::I()->addRawError('Problem while validating zone by bind. Please contact administrator')->toArray();
- }
- catch (Exception $exc) {
- LogHelper::addFailLogUsingZone('Edit Zone', $exc->getMessage(), $zone);
- return AjaxResponse::I()->addRawError($exc->getMessage())->toArray();
- }
- }
- private function createReverseIP(Zone $zone, $ip, $ttl, $sub = '') {
- $reverse = new reverse\Reverse();
- $reverse->serverid = $zone->getServer()->id;
- $reverse->from = $zone->name;
- $reverse->sub = $sub;
- $reverse->name = ReverseDNSHelper::reverseZoneName($ip);
- $reverse->created_at= date('Y-m-d H:i:s');
- $reverse->ip = $ip;
- $reverse->ttl = $ttl;
- $reverse->clientid = $zone->clientid;
- $reverse->save();
- }
- public function getRecordRdataJSON($input, $vars = array()) {
- $zone = new Zone($input['zone_id']);
- $class = '\MGModule\DNSManager2\mgLibs\custom\dns\record\type\\' . $input['type'];
- if(class_exists($class)) {
- $obj = new $class();
- $vars['record_fields'] = get_object_vars($obj);
- $vars['record_type'] = $input['type'];
- $packageSettings = $zone->getPackage()->getSettings('default_ttl');
- $packageSettings = unserialize($packageSettings);
- $vars['ttl_default_value'] = $packageSettings[$input['type']];
- if(empty($vars['ttl_default_value']))
- $vars['ttl_default_value'] = 14440;
- if($input['type'] == 'PTR') {
- $vars['value'] = $zone->name;
- }
- $settingRepo = new main\models\custom\package\setting\Repository();
- $vars['recordsAllowedIp'] = $settingRepo->byKey('records_allowed_ip')->get()[0] == 'on';
- $vars['recordsBlacklist'] = $settingRepo->byKey('records_blacklist')->get()[0] == 'on';
- $helper = new ClientHelper($_SESSION['uid']);
- if($vars['recordsAllowedIp']) {
- $allowedIps = $helper->getPackageAllowedIps(intval($zone->relid), intval($zone->type));
- $allowedIps = IP::getAvailableIpList(json_decode($allowedIps['allowed_ips']));
- $vars['allowed_ipv4'] = IP::getOnlyIpv4($allowedIps);
- $vars['allowed_ipv4_flag'] = is_array($vars['allowed_ipv4']) && !empty($vars['allowed_ipv4']) && $vars['allowed_ipv4'][0] != null;
- $vars['allowed_ipv6'] = IP::getOnlyIpv6($allowedIps);
- $vars['allowed_ipv6_flag'] = is_array($vars['allowed_ipv6']) && !empty($vars['allowed_ipv6']) && $vars['allowed_ipv6'][0] != null;
- }
- if($vars['recordsBlacklist']) {
- $ipBlacklist = $helper->getPackageIpBlacklist(intval($zone->relid), intval($zone->type));
- $ipBlacklist = IP::getAvailableIpList(json_decode($ipBlacklist['ip_blacklist']));
- $vars['ipv4_blacklist'] = IP::getOnlyIpv4($ipBlacklist);
- $vars['ipv4_blacklist_flag'] = is_array($vars['ipv4_blacklist']) && !empty($vars['ipv4_blacklist']) && $vars['ipv4_blacklist'][0] != null;
- $vars['ipv6_blacklist'] = IP::getOnlyIpv6($ipBlacklist);
- $vars['ipv6_blacklist_flag'] = is_array($vars['ipv6_blacklist']) && !empty($vars['ipv6_blacklist']) && $vars['ipv6_blacklist'][0] != null;
- }
- AjaxResponse::I()->html = main\mgLibs\smarty::I()->view('record-rdata',
- $vars,
- main\addon::getModuleTemplatesDir().DS.'pages' . DS . main\addon::I()->page);
- AjaxResponse::I()->ttl = $vars['ttl_default_value'];
- } else {
- AjaxResponse::I()->addRawError(main\mgLibs\lang::T('cannot_find_class'). ' ' .$class);
- }
- return AjaxResponse::I()->toArray();
- }
- public function editZoneSaveJSON($input, $vars = array())
- {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- if(!$helper->isZoneOwnedByClient($zone))
- {
- return AjaxResponse::I()->addError('you_cannot_edit_zone_that_is_not_your_own_zone')->toArray();
- }
- if($zone->is_locked) return AjaxResponse::I()->addError('you_cannot_edit_zone_that_is_not_your_own_zone')->toArray();
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addError('you_cannot_edit_this_zone_because_server_is_not_active')->toArray();
- }
- try
- {
- $blockerHelper = new BlockerHelper();
- $isBlocked = false;
- if(!$blockerHelper->isLoggedUserExcluded()) {
- $rules = $blockerHelper->getRules();
- foreach($input['edit_record'] as $singleRecord){
- foreach($rules as $rule) {
- $rule = trim($rule);
- if($blockerHelper->isRecordBlocked($rule, $singleRecord['name'])) {
- $isBlocked = true;
- break;
- }
- }
- }
- }
- if($isBlocked) {
- return AjaxResponse::I()->addError('value_is_blocked')->toArray();
- }
- $module = $zone->getModule();
- $module->moduleConvertInputFormData($input);
- $oldRecords = RecordSetHelper::formatRecordsToIndexById($module->getRecords());
- if(!$module->customEditRecords($input))
- {
- foreach ($input['edit_record'] as $counter => $record_data)
- {
- $record = $this->createRecordFromInputData($record_data);
- $record->encode();
- $record->nameToAbsolute($zone->name);
- $module->editRecord($record);
- $editRecordHelper = new custom\helpers\ZoneLogger\Actions\EditRecord($record, $oldRecords[$record->line]);
- $zoneLoggerManager = new ZoneLoggerManager($_SESSION['uid']);
- $zoneLoggerManager->logEditRecordsInZone($zone, $editRecordHelper);
- }
- }
- }
- catch(Exception $exc)
- {
- LogHelper::addFailLogUsingZone('Edit Zone', $exc->getMessage(), $zone);
- throw $exc;
- }
- AjaxResponse::I()->addInfo('changes_saved');
- AjaxResponse::I()->refreshPage($this->editZoneHTML($input));
- return AjaxResponse::I()->toArray();
- }
- private function formatRecordsToIndexById($records = [])
- {
- $out = [];
- foreach ($records as $record)
- {
- $out[$record->line] = $record;
- }
- return $out;
- }
- private function getPTRLimits() {
- $helper = new ClientHelper($_SESSION['uid']);
- $groups = $helper->getGroups();
- $limit = 0;
- foreach($groups as $item) {
- $ptr = $this->getPTRLimitForGroup($item);
- if($ptr)
- {
- $limit += (int)$ptr * (int)$item[0]['zones_available'];
- }
- }
- return $limit;
- }
- private function getPTRLimitForGroup($group)
- {
- $relateditem = new RelatedItem($group[0]['type'], $group[0]['relid'], $_SESSION['uid']);
- $package = $relateditem->getPackage();
- if($package == false) {
- return FALSE;
- }
- $package_setting = unserialize($package->getSettings(PackageSettingEnum::ALLOWED_RECORD_TYPES));
- return $package_setting['PTR'];
- }
- private function countPTR() {
- return query::query("SELECT COUNT(*)
- FROM dns_manager2_reverse
- WHERE clientid = :userid",
- array('userid' => $_SESSION['uid']))->fetchColumn();
- // return query::query("SELECT COUNT(*)
- // FROM tblhosting
- // INNER JOIN dns_manager2_reverse ON dns_manager2_reverse.ip = tblhosting.dedicatedip OR tblhosting.assignedips LIKE CONCAT('%', dns_manager2_reverse.ip, '%')
- // WHERE userid = :userid AND domainstatus IN ('Active')
- // GROUP BY dns_manager2_reverse.id",
- // array('userid' => $_SESSION['uid']))->fetchColumn();
- }
- private function getUserPackageItems($userid) {
- $helper = new ClientHelper($userid);
- $groups = $helper->getGroups();
- $out = array();
- foreach($groups as $name => $group) {
- $ptr = $this->getPTRLimitForGroup($group);
- if(!$ptr)
- {
- continue;
- }
- $item = current($group);
- $out[] = array(
- 'name' => $name,
- 'type' => $item['type'],
- 'relid' => $item['relid']
- );
- }
- foreach($out as $k => $item) {
- $ip_array = IPHelper::getIPsArray($userid, $item['type'], $item['relid']);
- if(!IPHelper::isCustomIPEnabled()) {
- if((IPHelper::isSubnetCustomIPEnabled() && empty($ip_array['pools']) && empty($ip_array['all_ips']))
- || (!IPHelper::isSubnetCustomIPEnabled() && empty($ip_array['all_ips']))) {
- unset($out[$k]);
- }
- }
- }
- return $out;
- }
- public function generateLinks( $vars, $page, $limit )
- {
- $page++;
- $recordsCount = query::query("SELECT COUNT(id) AS recordsCount
- FROM dns_manager2_reverse
- WHERE clientid = :clientid",
- ['clientid' => $_SESSION['uid']])->fetch()['recordsCount'];
- $pages = ceil($recordsCount / $limit);
- if ( !$recordsCount || ceil($recordsCount / $limit) === 1 )
- {
- $vars['prev'] = 1;
- $vars['page'] = 1;
- $vars['next'] = 1;
- $vars['links'] = [];
- }
- else
- {
- $vars['prev'] = ($page - 1 > 0) ? $page - 1 : 1;
- $vars['page'] = $page;
- $vars['next'] = $page + 1 <= ceil($recordsCount / $limit) ? $page + 1 : ceil($recordsCount / $limit);
- $linksToBeDisplayed = 3;
- $rangeMin = $page - $linksToBeDisplayed > 0 ? $page - $linksToBeDisplayed : 0;
- $rangeMax = $page + $linksToBeDisplayed < $pages ? $page + $linksToBeDisplayed : $pages;
- $linksCount = 0;
- $start = floor($linksToBeDisplayed / 2);
- $start = ($page - $start) >= 1 ? $page-$start : 1 ;
- for ( $i = $start; $i <= $pages; $i++ )
- {
- if ( ($linksCount < $linksToBeDisplayed) && $i >= $rangeMin && $i <= $rangeMax )
- {
- $vars['links'][] = $i;
- $linksCount++;
- }
- }
- }
- return $vars;
- }
- public function manageRDNSHTML($input, $vars = array()) {
- $page = isset( $_GET['page']) && ((int)$_GET['page'] - 1) >= 0 ? (int)$_GET['page'] - 1 : 0;
- $limit = isset($_GET['limit']) ? (int)$_GET['limit'] : 15;
- $offset = $page * $limit;
- $vars = $this->generateLinks($vars, $page, $limit);
- $data = query::query("SELECT *
- FROM dns_manager2_reverse
- WHERE clientid = :clientid
- LIMIT :offset,:limit", ['clientid' => $_SESSION['uid'], 'offset' => $offset, 'limit' => $limit])->fetchAll();
- $vars['ptrs'] = $data;
- $vars['limit'] = $this->getPTRLimits();
- $vars['counter'] = 1;
- $query = htmlspecialchars_decode($_SERVER['QUERY_STRING']);
- $vars['query'] = 'index.php?'.preg_replace('/&page=\w+/', '', $query);
- return array(
- 'tpl' => 'manage-rdns'
- ,'vars' => $vars
- );
- }
- public function manageRDNSJSON($input, $vars = array()) {
- return AjaxResponse::I()->refreshPage($this->manageRDNSHTML($input))->toArray();
- }
- public function addRDNSJSON($input, $vars = array()) {
- $vars['items'] = $this->getUserPackageItems($_SESSION['uid']);
- return AjaxResponse::I()->modal('add-rdns', $vars)->toArray();
- }
- public function getRDNSDataJSON($input, $vars = array()) {
- $vars = IPHelper::getIPsArray($_SESSION['uid'], $input['type'], $input['relid']);
- foreach($vars['ips'] as $ip) {
- try {
- $relateditem = new RelatedItem($input['type'], $input['relid'], $_SESSION['uid']);
- $package = $relateditem->getPackage();
- if($package == false) {
- throw new Exception('No package found');
- }
- $server = $package->getFirstActiveServer();
- if($server == false) {
- throw new Exception('No active server related to this item');
- }
- if(reverse\Reverse::byServerIDAndIP($server->id, (string) $ip) !== false) {
- throw new Exception('IP already taken', 103);
- }
- }
- catch(Exception $e) {
- $vars['blocked_ips'][$ip] = $ip;
- }
- }
- $vars['any_pool'] = !empty($vars['pools']);
- $vars['custom_ip'] = IPHelper::isCustomIPEnabled();
- AjaxResponse::I()->html = main\mgLibs\smarty::I()->view('rdns-data',
- $vars,
- main\addon::getModuleTemplatesDir().DS.'pages' . DS . main\addon::I()->page);
- return AjaxResponse::I()->toArray();
- }
- public function addRDNSSaveJSON($input, $vars = array()) {
- $helper = new ClientHelper($_SESSION['uid']);
- list($type, $relid) = explode('::', $input['item']);
- $relateditem = new RelatedItem($type, $relid, $_SESSION['uid']);
- $package = $relateditem->getPackage();
- if($package == false) {
- return AjaxResponse::I()->addRawError('No package found')->toArray();
- }
- $server = $package->getFirstActiveServer();
- if($server == FALSE) {
- return AjaxResponse::I()->addError('no_active_server_related_to_this_item')->toArray();
- }
- $module = $server->getModule();
- if($server->getSettings(ServerSettingEnum::ALLOW_RDNS) != 'on' || !$module->isRDNSSupported()) {
- return AjaxResponse::I()->addError('rnds_disabled')->toArray();
- }
- try {
- $package_settings = unserialize($package->getSettings(PackageSettingEnum::ALLOWED_RECORD_TYPES));
- $ptrLimit = $package_settings['PTR'];
- $count = $this->countPTR();
- if($count >= $ptrLimit) {
- return AjaxResponse::I()->addError('you_cant_add_this_record_because_you_reach_limit')->toArray();
- }
- if(strpos($input['ip'], 'block') !== false) {
- list($str,$pool,$mask) = explode('|',$input['ip']);
- $ip = new IP($input['ip_from_block']);
- if(!$ip->isInNetwork($pool, $mask)) {
- return AjaxResponse::I()->addError('ip_is_not_belongs_to_selected_block')->toArray();
- }
- $input['ip'] = $input['ip_from_block'];
- }
- $ip = $input['ip'];
- $field = $input['field'];
- $rdata = isset($field['ptrdname']) ? $field['ptrdname'] : reset($field);
- $blockerHelper = new BlockerHelper();
- $isBlocked = false;
- if(!$blockerHelper->isLoggedUserExcluded()) {
- $rules = $blockerHelper->getRules(true);
- foreach($rules as $rule) {
- $rule = trim($rule);
- if($blockerHelper->isRecordBlocked($rule, $rdata)) {
- $isBlocked = true;
- break;
- }
- }
- }
- if($isBlocked) {
- return AjaxResponse::I()->addError('value_is_blocked')->toArray();
- }
- // $ip_array = IPHelper::getIPsArray($_SESSION['uid'], $type, $relid);
- // if(!in_array($ip, $ip_array['all_ips'])) {
- // return AjaxResponse::I()->addError('you_cant_use_ip_that_not_belongs_to_you')->toArray();
- // }
- IPHelper::validateIfClientCanUseIP($_SESSION['uid'], $type, $relid, $ip);
- $reverse = new main\mgLibs\custom\reverse\ReverseDNS();
- $reverse->setServer($server);
- $reverse->setClientID($_SESSION['uid']);
- $reverse->setIP($ip);
- $reverse->setTTL($input['ttl']);
- $reverse->setDomain($input['field']['ptrdname']);
- $reverse->setType($type);
- $reverse->setRelId($relid);
- $reverse->create();
- $zoneLogger = new ZoneLoggerManager($_SESSION['uid']);
- $zoneLogger->logAddRdns($reverse);
- AjaxResponse::I()->addInfo('new_record_added_to_zone');
- return $this->manageRDNSJSON($input, $vars);
- } catch (Exception $exc) {
- return AjaxResponse::I()->addRawError($exc->getMessage())->toArray();
- }
- }
- public function removeRDNSJSON($input, $vars = array()) {
- $reverse = new reverse\Reverse($input['rid']);
- if ($reverse->clientid != $_SESSION['uid']) {
- return AjaxResponse::I()->addError('you_cannot_remove_record_that_is_not_belongs_to_you')->toArray();
- }
- try {
- $helper = new main\mgLibs\custom\reverse\ReverseDNS($reverse);
- $helper->remove();
- } catch (Exception $e) {
- return AjaxResponse::I()->addRawError($e->getMessage())->toArray();
- }
- AjaxResponse::I()->addInfo('record_removed_successfully');
- AjaxResponse::I()->refreshPage($this->manageRDNSHTML($input));
- return AjaxResponse::I()->toArray();
- }
- public function editRDNSJSON($input, $vars = array()) {
- $reverse = new reverse\Reverse($input['rid']);
- $vars['rdata'] = $reverse->getFullDomain();
- $vars['rid'] = $input['rid'];
- $vars['ee'] = isset($input['ee']);
- return AjaxResponse::I()->modal('edit-rdns', $vars)->toArray();
- }
- public function editRDNSSaveJSON($input, $vars = array()) {
- $reverse = new reverse\Reverse($input['rid']);
- if ($reverse->clientid != $_SESSION['uid']) {
- return AjaxResponse::I()->addRawError('...')->toArray();
- }
- try {
- $rdata = $input['rdata'];
- $blockerHelper = new BlockerHelper();
- $isBlocked = false;
- if(!$blockerHelper->isLoggedUserExcluded()) {
- $rules = $blockerHelper->getRules(true);
- foreach($rules as $rule) {
- $rule = trim($rule);
- if($blockerHelper->isRecordBlocked($rule, $rdata)) {
- $isBlocked = true;
- break;
- }
- }
- }
- if($isBlocked) {
- return AjaxResponse::I()->addError('value_is_blocked')->toArray();
- }
- $helper = new main\mgLibs\custom\reverse\ReverseDNS($reverse);
- $helper->setDomain($input['rdata']);
- $helper->update();
- } catch (Exception $e) {
- return AjaxResponse::I()->addRawError($e->getMessage())->toArray();
- }
- return AjaxResponse::I()->refreshPage($this->manageRDNSHTML($input))->addInfo('RDNSchanged')->toArray();
- }
- public function dnsSecHTML($input, $vars = array())
- {
- $this->redirectIfIsOnlyRDNSforCA();
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- $module = $zone->getModule();
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$helper->isZoneOwnedByClient($zone))
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_it_is_not_belongs_to_you');
- }
- elseif(!$checkServer['status'])
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_server_is_not_active');
- }
- elseif(! ($zone->getServer()->getSettings(ServerSettingEnum::ENABLE_DNSSEC) == 'on' && $module->isDNSSECSupported()))
- {
- $vars['error'] = lang::T('dnssec_is_disabled');
- }
- else
- {
- if(!$module->zoneExists())
- {
- $vars['error'] = lang::T('you_cannot_edit_this_zone_because_it_is_terminated_on_server');
- }
- else
- {
- $vars['is_signed'] = $module->isSigned();
- $vars['keys'] = array();
- $keys = $module->getSignKeys();
- if(method_exists($keys, 'hasKeys') && $keys->hasKeys())
- {
- $vars['keys']['keys'] = array_merge($keys->getKsk(), $keys->getCsk(), $keys->getZsk());
- $vars['keys']['ds'] = $keys->getDs();
- }
- }
- }
- $vars['zone_name'] = $zone->name;
- $vars['zoneid'] = $zone->id;
- return array
- (
- 'tpl' => 'dnssec',
- 'vars' => $vars
- );
- }
- public function disableDnssecJSON($input, $vars = array())
- {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- $module = $zone->getModule();
- if(!$helper->isZoneOwnedByClient($zone))
- {
- return AjaxResponse::I()->addRawError(lang::T('you_cannot_edit_this_zone_because_it_is_not_belongs_to_you'))->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addRawError(lang::T('you_cannot_edit_this_zone_because_server_is_not_active'))->toArray();
- }
- if(! ($zone->getServer()->getSettings(ServerSettingEnum::ENABLE_DNSSEC) == 'on' && $module->isDNSSECSupported()))
- {
- return AjaxResponse::I()->addRawError(lang::T('dnssec_is_disabled'));
- }
- try
- {
- $module->unsign();
- }
- catch(Exception $e)
- {
- return AjaxResponse::I()->addRawError($e->getMessage())->toArray();
- }
- return AjaxResponse::I()->refreshPage($this->dnsSecHTML($input))->addInfo('DNSSECDisabledSuccess')->toArray();
- }
- public function enableDnssecJSON($input, $vars = array())
- {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- $module = $zone->getModule();
- if(!$helper->isZoneOwnedByClient($zone))
- {
- return AjaxResponse::I()->addRawError(lang::T('you_cannot_edit_this_zone_because_it_is_not_belongs_to_you'))->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addRawError(lang::T('you_cannot_edit_this_zone_because_server_is_not_active'))->toArray();
- }
- if(! ($zone->getServer()->getSettings(ServerSettingEnum::ENABLE_DNSSEC) == 'on' && $module->isDNSSECSupported()))
- {
- return AjaxResponse::I()->addRawError(lang::T('dnssec_is_disabled'));
- }
- try
- {
- $module->sign();
- }
- catch(Exception $e)
- {
- return AjaxResponse::I()->addRawError($e->getMessage())->toArray();
- }
- return AjaxResponse::I()->refreshPage($this->dnsSecHTML($input))->addInfo('DNSSECEnableSuccess')->toArray();
- }
- public function rectifyDnssecJSON($input, $vars = array())
- {
- $helper = new ClientHelper($_SESSION['uid']);
- $zone = new Zone($input['zone_id']);
- $module = $zone->getModule();
- if(!$helper->isZoneOwnedByClient($zone))
- {
- return AjaxResponse::I()->addRawError(lang::T('you_cannot_edit_this_zone_because_it_is_not_belongs_to_you'))->toArray();
- }
- $checkServer = $helper::getServerStatusByZoneId($zone->id);
- if(!$checkServer['status'])
- {
- return AjaxResponse::I()->addRawError(lang::T('you_cannot_edit_this_zone_because_server_is_not_active'))->toArray();
- }
- if(! ($zone->getServer()->getSettings(ServerSettingEnum::ENABLE_DNSSEC) == 'on' && $module->isDNSSECSupported()))
- {
- return AjaxResponse::I()->addRawError(lang::T('dnssec_is_disabled'));
- }
- try
- {
- $module->rectify();
- }
- catch(Exception $e)
- {
- return AjaxResponse::I()->addRawError($e->getMessage())->toArray();
- }
- return AjaxResponse::I()->refreshPage($this->dnsSecHTML($input))->addInfo('DNSSECRectifySuccess')->toArray();
- }
- public function arraySortByValue($key)
- {
- return function ($obA, $obB) use ($key)
- {
- return strnatcmp($obA->$key, $obB->$key);
- };
- }
- /* DNS Sets */
- public function listJSON($input, $vars = array())
- {
- $query = "SELECT dns_manager2_set.id AS id, dns_manager2_set.default AS def, dns_manager2_set.idu AS idu, dns_manager2_set.name AS name, COUNT(DISTINCT(dns_manager2_setrecord.id)) AS dnsrecords
- FROM dns_manager2_set
- LEFT JOIN dns_manager2_setrecord ON dns_manager2_setrecord.setid = dns_manager2_set.id
- LEFT JOIN dns_manager2_packageset ON dns_manager2_packageset.setid = dns_manager2_set.id
- LEFT JOIN dns_manager2_package ON dns_manager2_package.defaultset = dns_manager2_set.id
- WHERE idu = ".$_SESSION['uid']."
- GROUP BY dns_manager2_set.id";
- $columns = array('name','dnsrecords','idu','def');
- $helper = new main\mgLibs\custom\RawQueryTableHelper($query, $input, $columns);
- $vars = $helper->getDataTableArray();
- foreach($helper->get() as $set)
- {
- $vars['data'][] = $this->dataTablesParseRow('set-row', array('set' => $set));
- }
- return $vars;
- }
- public function addSetJSON($input, $vars = array())
- {
- $vars['set'] = $this->set_form;
- $vars['available_record_types'] = main\mgLibs\custom\dns\Core::getAvailableRecordTypesByActiveServers();
- return AjaxResponse::I()->modal('set-edit', $vars)->toArray();
- }
- public function addNewRecordJSON($input, $vars = array())
- {
- $class = 'MGModule\DNSManager2\mgLibs\custom\dns\record\type\\' . $input['new_record_type'];
- if(class_exists($class))
- {
- $vars['counter'] = $input['records_counter'];
- $vars['record_type'] = $input['new_record_type'];
- $vars['record_obj'] = new $class();
- $vars['record_fields'] = get_object_vars($vars['record_obj']);
- AjaxResponse::I()->new_record = main\mgLibs\smarty::I()->view('new-record',
- $vars,
- main\addon::getModuleTemplatesDir().DS.'pages' . DS . main\addon::I()->page);
- }
- else
- {
- AjaxResponse::I()->addError('cannot_find_class', array('class' => $class));
- }
- return AjaxResponse::I()->toArray();
- }
- public function duplicateSetJSON($input, $vars = array()) {
- $set = new set\Set($input['id']);
- $vars['set']['id'] = $set->id;
- $vars['set']['name'] = $set->name.' Duplication';
- return AjaxResponse::I()->modal('set-duplicate', $vars)->toArray();
- }
- public function setDuplicateJSON($input, $vars = array()) {
- $duplicatedSet = new set\Set($input['id']);
- $newSet = new set\Set(false);
- $newSet->name = $input['name'];
- $newSet->idu = $duplicatedSet->idu;
- $newSet->save();
- foreach($duplicatedSet->getRecords() as $record_data) {
- $newSet->setRecord($record_data->name, $record_data->type, $record_data->ttl, $record_data->rdata, false);
- }
- AjaxResponse::I()->addInfo('changes_saved');
- return AjaxResponse::I()->toArray();
- }
- public function editSetJSON($input, $vars = array())
- {
- $set = new main\models\custom\set\Set($input['id']);
- $vars['set'] = $this->set_form;
- $vars['set']['edit'] = true;
- $vars['set']['id'] = $set->id;
- $vars['set']['name'] = $set->name;
- $vars['set']['default'] = $set->default;
- $vars['set']['records'] = $set->getRecords();
- $vars['set']['count'] = count($vars['set']['records']);
- $vars['counter'] = 0;
- $vars['available_record_types'] = main\mgLibs\custom\dns\Core::getAvailableRecordTypesByActiveServers();
- return AjaxResponse::I()->modal('set-edit', $vars)->toArray();
- }
- public function setSaveJSON($input, $vars = array())
- {
- if($input['default'] == '1')
- {
- $user_sets = main\mgLibs\MySQL\query::select(array('id','name','idu','default'), 'dns_manager2_set', array('idu' => $_SESSION['uid']))->fetchAll();
- foreach($user_sets as $u)
- {
- main\mgLibs\MySQL\query::update('dns_manager2_set', array('default' => ''), array('idu' => $_SESSION['uid']));
- }
- }
- $blockerHelper = new BlockerHelper();
- $isBlocked = false;
- if(!$blockerHelper->isLoggedUserExcluded()) {
- $rules = $blockerHelper->getRules();
- foreach($input['record'] as $singleRecord){
- foreach($rules as $rule) {
- $rule = trim($rule);
- if($blockerHelper->isRecordBlocked($rule, $singleRecord['name'])) {
- $isBlocked = true;
- break;
- }
- }
- }
- }
- if($isBlocked) {
- return AjaxResponse::I()->addError('value_is_blocked')->toArray();
- }
- $set = new main\models\custom\set\Set($input['id']?:false);
- $set->name = $input['name'];
- $set->idu = $_SESSION['uid'];
- $set->default = $input['default'];
- $set->save();
- foreach($input['record'] as $record_data)
- {
- $set->setRecord($record_data['name'], $record_data['type'], $record_data['ttl'], $record_data['field'], $record_data['id']?:false);
- }
- foreach($input['remove_record'] as $id)
- {
- $record = new main\models\custom\set\record\SetRecord($id);
- $record->delete();
- }
- AjaxResponse::I()->addInfo('dns_record_added_successfully');
- return AjaxResponse::I()->toArray();
- }
- public function removeSetJSON($input, $vars = array())
- {
- main\models\custom\set\Set::factory($input['id'])->delete();
- return AjaxResponse::I()->addInfo('set_removed')->toArray();
- }
- private function getClientSets()
- {
- $clientSets = set\Repository::factory()->byUserId((int)$_SESSION['uid'])->get();
- return $clientSets;
- }
- private function getDefaultSet()
- {
- $default = set\Repository::factory()->byUserId((int)$_SESSION['uid'])->setFilter('default',1)->get();
- return $default[0]->id;
- }
- public function setRecordsJSON($input, $vars = array())
- {
- if(!array_filter($input['zone']['checked']))
- {
- return AjaxResponse::I()->addError('select_one_at_least')->toArray();
- }
- $vars['sets'] = $this->getClientSets();
- return AjaxResponse::I()->modal('set-records', $vars)->toArray();
- }
- public function exportFromFileJSON($input, $vars = array())
- {
- $vars['exportId'] = $input['id'];
- AjaxResponse::I()->refreshPage(array('tpl' => 'export-list', 'vars' => $vars));
- return AjaxResponse::I()->toArray();
- }
- public function exportZonesJSON($input, $vars = array())
- {
- $add = false;
- $exported = false;
- foreach($input['zone'] as $result_id => $data)
- {
- if($data['export'] != 'on' && !isset($input['justOne']))
- {
- continue;
- }
- $exported = true;
- $result = new task\result\TaskResult($result_id);
- $task = custom\TaskManager::getTaskObjectByID($result->taskid);
- $main_task = $task->getParent(); //TODO: można zmniejszyć ilość danych poprzez odwołanie się do resulta
- $result->data['resultid'] = $result_id;
- $child = $main_task->addChild('export', $result->data);
- $result->data['status'] = 'exporting';
- $result->data['taskid'] = $child->obj()->id;
- $result->save();
- if(isset($input['runNow']))
- {
- $child->run();
- if($child->getStatus() !== 'finished')
- {
- AjaxResponse::I()->addError('something_went_wrong_during_import');
- }
- else
- {
- AjaxResponse::I()->addInfo('zone_imported');
- }
- }
- else
- {
- if($add === false)
- {
- AjaxResponse::I()->addInfo('new_task_added');
- $add = true;
- }
- }
- }
- if(!$exported)
- {
- AjaxResponse::I()->addError('no_zone_selected_for_import_export');
- }
- return AjaxResponse::I()->toArray();
- }
- function refreshExportTableJSON($input, $vars = array())
- {
- $pRep = task\Repository::factory()->byParentID($input['id'])->one();
- $pRepName = explode(':', $pRep->name);
- $task = custom\TaskManager::getXTasks(1, $pRepName[0].':fetchZonesList', $input['id'], false);
- $task = end($task);
- $rep = task\result\Repository::factory()->byTaskID($task->id);
- $helper = new main\mgLibs\custom\RepoTableHelper($rep, $input, array('data'));
- $vars = $helper->getDataTableArray();
- $whmcsZones = query::query('SELECT name, id FROM dns_manager2_zone')->fetchGroup();
- foreach($helper->get() as $task)
- {
- if(!isset($whmcsZones[$task->data['domain']]))
- {
- $task->data['status'] = 'notExistInWhmcs';
- }
- $vars['data'][] = $this->dataTablesParseRow('export-row',
- array(
- 'item' => $task,
- 'exportId' => $input['id'],
- )
- );
- }
- return $vars;
- }
- public function backupsHTML($input, $vars = array())
- {
- if(GlobalSettingHelper::getSetting(GlobalSettingEnum::LINK_TO_CLIENTAREA_IMPORT_EXPORT, true) != 'on')
- {
- redir('m=DNSManager2');
- }
- $this->redirectIfIsOnlyRDNSforCA();
- $vars['backupsTasks'] = $this->getImportToFileClientTasks();
- $newImportsToFile = custom\TaskManager::getXTasksObjects(0, 'ExportFromFileWHMCS:main', 0, task\TaskStatusEnum::START, $_SESSION['uid']);
- $this->parseNewImportTaskList($newImportsToFile, $vars['backupsTasks']);
- $toFileImports = custom\TaskManager::getXTasksObjects(0, 'ExportFromFileWHMCS:main', 0, task\TaskStatusEnum::IN_PROGRESS, $_SESSION['uid']);
- $this->parseInProgresImportTaskList($toFileImports, $vars['backupsTasks'], 'ExportFromFileWHMCS', $_SESSION['uid']);
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones');
- $filesList = main\mgLibs\custom\helpers\ImportExportFileHelper::listFilesForBulkExport($fileManager, false);
- $manualFilesList = ClientFilesManage::getManualBackups($_SESSION['uid'], $filesList, ClientFilesManage::BACKUP);
- $cronFilesList = ClientFilesManage::getCronBackups($_SESSION['uid'], $filesList, ClientFilesManage::BACKUP);
- $amountOfManualBackups = count($manualFilesList);
- $amountOfCronBackups = count($cronFilesList);
- $manualBackupsLimit = GlobalSettingHelper::getSetting(GlobalSettingEnum::CLIENTAREA_IMPORT_EXPORT_LIMIT);
- $cronBackupsLimit = GlobalSettingHelper::getSetting(GlobalSettingEnum::CRON_BACKUP_LIMIT);
- $manualBackupsLimit = $manualBackupsLimit != -1 ? $manualBackupsLimit : '∞';
- $cronBackupsLimit = $cronBackupsLimit != -1 ? $cronBackupsLimit : '∞';
- if($manualBackupsLimit != 0)
- {
- $vars['manualBackupLimitDisplay'] = "({$amountOfManualBackups}/{$manualBackupsLimit})";
- }
- if($cronBackupsLimit != 0)
- {
- $vars['cronBackupLimitDisplay'] = "({$amountOfCronBackups}/{$cronBackupsLimit})";
- }
- $vars['caCanAddBackup'] = $this->canAddBackup();
- return array(
- 'tpl' => 'backups',
- 'vars' => $vars
- );
- }
- private function getImportToFileClientTasks()
- {
- $vars = array();
- $waitingImportsToFile = custom\TaskManager::getXTasksObjects(0, 'ImportToFileWHMCS:main', 0, task\TaskStatusEnum::WAITING, $_SESSION['uid']);
- $this->parseNewImportTaskList($waitingImportsToFile, $vars);
- $newImportsToFile = custom\TaskManager::getXTasksObjects(0, 'ImportToFileWHMCS:main', 0, task\TaskStatusEnum::START, $_SESSION['uid']);
- $this->parseNewImportTaskList($newImportsToFile, $vars);
- $toFileImports = custom\TaskManager::getXTasksObjects(0, 'ImportToFileWHMCS:main', 0, task\TaskStatusEnum::IN_PROGRESS, $_SESSION['uid']);
- $this->parseInProgresImportTaskList($toFileImports, $vars, 'ImportToFileWHMCS', $_SESSION['uid']);
- return $vars;
- }
- private function canAddBackup()
- {
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones');
- $filesList = main\mgLibs\custom\helpers\ImportExportFileHelper::listFilesForBulkExport($fileManager, false);
- $filesList = ClientFilesManage::getFilesForClient($_SESSION['uid'], $filesList, ClientFilesManage::BACKUP);
- $taskImport = $this->getImportToFileClientTasks();
- $amountOfBackups = count($filesList) + count($taskImport);
- $limit = GlobalSettingHelper::getSetting(GlobalSettingEnum::CLIENTAREA_IMPORT_EXPORT_LIMIT);
- if($limit <= $amountOfBackups && $limit != -1)
- {
- return false;
- }
- return true;
- }
- public function uploadBackupFileJSON($input, $vars = array())
- {
- if(!$this->canAddBackup())
- {
- AjaxResponse::I()->addError('backups_limit_reached');
- return AjaxResponse::I()->toArray();
- }
- $fileName = main\mgLibs\custom\FileManager::removeFakePath($input['fileName']);
- if(!main\mgLibs\custom\FileManager::checkIfFileWasSent($fileName))
- {
- AjaxResponse::I()-> addError('sendingFailed', array('file' => $fileName));
- return AjaxResponse::I()->toArray();
- }
- $type = main\mgLibs\custom\FileManager::checkTypeByContent($fileName);
- if($type !== 'single' && $type !== 'bulk')
- {
- AjaxResponse::I()->addError('invalidContent', array('file' => $fileName));
- return AjaxResponse::I()->toArray();
- }
- $explodedFileName = explode('_', $fileName);
- $clientId = $explodedFileName[count($explodedFileName)-1];
- if($clientId != $_SESSION['uid'])
- {
- $newfileName = custom\helpers\ImportExportFileHelper::generateClientFileName($_SESSION['uid']);
- foreach ($_FILES as &$file)
- {
- if($file['name'] == $fileName)
- {
- $file['name'] = $newfileName;
- $fileName = $newfileName;
- }
- }
- }
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.$type.'Zones');
- if(!$fileManager->isStorageReadable() || !$fileManager->isStorageWritable())
- {
- AjaxResponse::I()-> addError('directoryPermissionWritableReadable', array('storageDir' => $fileManager->getStoragePath()));
- return AjaxResponse::I()->toArray();
- }
- if($fileManager->fileExists($fileName))
- {
- AjaxResponse::I()->addError('fileAlreadyExist', array('file' => $fileName));
- return AjaxResponse::I()->toArray();
- }
- if($fileManager->uploadFile($fileName))
- {
- ClientFilesManage::save($fileName, $_SESSION['uid'], ClientFilesManage::BACKUP, 'client');
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- AjaxResponse::I()->addInfo('uploadSuccesfull');
- return AjaxResponse::I()->toArray();
- }
- if(!main\mgLibs\custom\FileManager::checkIfFileWasSent($fileName))
- {
- AjaxResponse::I()-> addError('sendingFailed', array('file' => $fileName));
- return AjaxResponse::I()->toArray();
- }
- }
- private function sortBackupFiles(&$filesList, $order)
- {
- if($order)
- {
- rsort($filesList);
- return;
- }
- sort($filesList);
- }
- private function sortBackupFilesByZonesNumber(&$filesList, $order)
- {
- if($order)
- {
- arsort($filesList);
- return;
- }
- asort($filesList);
- }
- public function refreshBackupsTableJSON($input, $vars = array())
- {
- $vars['data'] = array();
- $vars['recordsTotal'] = 0;
- $vars['recordsFiltered'] = 0;
- $order = $input['order']['dir'] == 'desc' ? 1 : 0;
- $columnName = $input['order']['column'];
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones');
- $filesList = main\mgLibs\custom\helpers\ImportExportFileHelper::listFilesForBulkExport($fileManager, false, $order);
- $filesList = ClientFilesManage::getManualBackups($_SESSION['uid'], $filesList, ClientFilesManage::BACKUP);
- if($columnName == 'name')
- {
- $this->sortBackupFiles($filesList, $order);
- } elseif($columnName == 'type')
- {
- $newFilesList = [];
- foreach($filesList as $fileName)
- {
- $backupZone = main\mgLibs\custom\helpers\ImportExportFileHelper::loadFileContent('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones', $fileName.'_'.$_SESSION['uid']);
- $newFilesList[$fileName] = count((array)$backupZone);
- }
- $this->sortBackupFilesByZonesNumber($newFilesList, $order);
- $filesList = array_keys($newFilesList);
- }
- foreach($filesList as $fileName)
- {
- $backupZone = main\mgLibs\custom\helpers\ImportExportFileHelper::loadFileContent('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones', $fileName.'_'.$_SESSION['uid']);
- $vars['recordsTotal']++;
- if($input['search'] && $this->isFilenameMatch($fileName, $input['search']))
- {
- $vars['data'][] = $this->dataTablesParseRow('backup-row', array('fileName' => $fileName, 'type' => 'bulk', 'zonesAmount' => count((array)$backupZone)));
- $vars['recordsFiltered']++;
- }
- elseif(!$input['search'])
- {
- $vars['data'][] = $this->dataTablesParseRow('backup-row', array('fileName' => $fileName, 'type' => 'bulk', 'zonesAmount' => count((array)$backupZone)));
- }
- }
- $vars['recordsFiltered'] = $input['search'] ? $vars['recordsFiltered'] : $vars['recordsTotal'];
- $limit = $input['limit'];
- $offset = $input['offset'];
- $vars['data'] = array_slice($vars['data'], $offset, $limit);
- return $vars;
- }
- public function refreshCronBackupsTableJSON($input, $vars = array())
- {
- $vars['data'] = array();
- $vars['recordsTotal'] = 0;
- $vars['recordsFiltered'] = 0;
- $order = $input['order']['dir'] == 'desc' ? 1 : 0;
- $columnName = $input['order']['column'];
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones');
- $filesList = main\mgLibs\custom\helpers\ImportExportFileHelper::listFilesForBulkExport($fileManager, false, $order);
- $filesList = ClientFilesManage::getCronBackups($_SESSION['uid'], $filesList, ClientFilesManage::BACKUP);
- if($columnName == 'name')
- {
- $this->sortBackupFiles($filesList, $order);
- } elseif($columnName == 'type')
- {
- $newFilesList = [];
- foreach($filesList as $fileName)
- {
- $backupZone = main\mgLibs\custom\helpers\ImportExportFileHelper::loadFileContent('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones', $fileName.'_'.$_SESSION['uid']);
- $newFilesList[$fileName] = count((array)$backupZone);
- }
- $this->sortBackupFilesByZonesNumber($newFilesList, $order);
- $filesList = array_keys($newFilesList);
- }
- foreach($filesList as $fileName)
- {
- $backupZone = main\mgLibs\custom\helpers\ImportExportFileHelper::loadFileContent('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones', $fileName.'_'.$_SESSION['uid']);
- $vars['recordsTotal']++;
- if($input['search'] && $this->isFilenameMatch($fileName, $input['search']))
- {
- $vars['data'][] = $this->dataTablesParseRow('cron-backup-row', array('fileName' => $fileName, 'type' => 'bulk', 'zonesAmount' => count((array)$backupZone)));
- $vars['recordsFiltered']++;
- }
- elseif(!$input['search'])
- {
- $vars['data'][] = $this->dataTablesParseRow('cron-backup-row', array('fileName' => $fileName, 'type' => 'bulk', 'zonesAmount' => count((array)$backupZone)));
- }
- }
- $vars['recordsFiltered'] = $input['search'] ? $vars['recordsFiltered'] : $vars['recordsTotal'];
- $limit = $input['limit'];
- $offset = $input['offset'];
- $vars['data'] = array_slice($vars['data'], $offset, $limit);
- return $vars;
- }
- private function isFilenameMatch($fileName, $search)
- {
- if(strpos($fileName, $search) || strpos($fileName, $search) === 0)
- {
- return true;
- }
- return false;
- }
- public function removeBackupFileJSON($input, $vars = array())
- {
- $type = $input['type'];
- $fileName = $input['id'] . '_' . $_SESSION['uid'];
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.$type.'Zones');
- $exist = true;
- if(!$fileManager->fileExists($fileName))
- {
- $exist = false;
- // AjaxResponse::I()-> addError('fileDoesNotExist', array('file' => $fileName));
- // return AjaxResponse::I()->toArray();
- }
- if(!$exist)
- {
- ClientFilesManage::delete($_SESSION['uid'], $fileName, ClientFilesManage::BACKUP);
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- AjaxResponse::I()->addInfo('fileRemoved');
- return AjaxResponse::I()->toArray();
- }
- if($fileManager->deleteFile($fileName) && $exist)
- {
- ClientFilesManage::delete($_SESSION['uid'], $fileName, ClientFilesManage::BACKUP);
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- AjaxResponse::I()->addInfo('fileRemoved');
- return AjaxResponse::I()->toArray();
- }
- AjaxResponse::I()-> addError('fileDeleteFailed', array('file' => $fileName));
- return AjaxResponse::I()->toArray();
- }
- public function backupScheduleImportJSON($input, $vars = array())
- {
- custom\TaskManager::getTaskObjectByID($input['id'])->run(true);
- AjaxResponse::I()->addInfo('import_scheduled');
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- return AjaxResponse::I()->toArray();
- }
- public function backupRemoveTaskJSON($input, $vars = array())
- {
- custom\TaskManager::removeTask($input['id']);
- ClientFilesManage::delete($_SESSION['uid'], $input['file'], ClientFilesManage::FROM_FILE_TO_WHMCS);
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- AjaxResponse::I()->addInfo('taskRemoved');
- return AjaxResponse::I()->toArray();
- }
- public function downloandBackupFileHTML($input, $vars = array())
- {
- $this->redirectIfIsOnlyRDNSforCA();
- $filePatch = $_GET['path'];
- if(!strpos($filePatch, 'DNSManager2'.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'zonesFilesStorage'))
- {
- $filePatch = false;
- }
- ob_clean();
- header('Content-Description: File Transfer');
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename="'.basename($filePatch).'"');
- header('Expires: 0');
- header('Cache-Control: must-revalidate');
- header('Pragma: public');
- header('Content-Length: '.filesize($filePatch));
- readfile($filePatch);
- die();
- }
- public function showBackupZonesJSON($input, $vars = array())
- {
- $fileName = $input['id'];
- $backupZone = main\mgLibs\custom\helpers\ImportExportFileHelper::loadFileContent('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones', $fileName.'_'.$_SESSION['uid']);
- AjaxResponse::I()->result = $backupZone;
- return AjaxResponse::I()->toArray();
- }
- public function showCronBackupZonesJSON($input, $vars = array())
- {
- $fileName = $input['id'];
- $backupZone = main\mgLibs\custom\helpers\ImportExportFileHelper::loadFileContent('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones', $fileName.'_'.$_SESSION['uid']);
- AjaxResponse::I()->result = $backupZone;
- return AjaxResponse::I()->toArray();
- }
- public function downloandBackupFileJSON($input, $vars = array())
- {
- $type = $input['type'];
- $fileName = $input['id'] . '_' . $_SESSION['uid'];
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.$type.'Zones');
- if(!$fileManager->fileExists($fileName))
- {
- AjaxResponse::I()-> addError('fileDoesNotExist', array('file' => $fileName));
- return AjaxResponse::I()->toArray();
- }
- $filePatch = $fileManager->getStoragePath().$fileName;
- $url = html_entity_decode(str_replace('mg-action=backups', 'mg-action=downloandBackupFile', $_SERVER['HTTP_REFERER']));
- return array('seturlto' => $url.'&path='.$filePatch);
- }
- public function addExportSaveJSON($input, $vars = array())
- {
- $fileManager = new main\mgLibs\custom\FileManager('zonesFilesStorage'.DIRECTORY_SEPARATOR.'bulkZones');
- $fileName = $input['id'] . '_' . $_SESSION['uid'];
- $vars['isReadable'] = $fileManager->isStorageReadable();
- if(!$vars['isReadable'])
- {
- AjaxResponse::I()->addError('pathInNotReadAble');
- return AjaxResponse::I()->toArray();
- }
- $vars['storagePath'] = $fileManager->getStoragePath();
- if(!$vars['storagePath'])
- {
- AjaxResponse::I()->addError('storageNotExists');
- return AjaxResponse::I()->toArray();
- }
- $res = ClientFilesManage::saveIfNotExists($fileName, $_SESSION['uid'], ClientFilesManage::FROM_FILE_TO_WHMCS, 'client');
- if(!$res)
- {
- AjaxResponse::I()->addError('exportFromThisFileExist');
- return AjaxResponse::I()->toArray();
- }
- $task = custom\TaskManager::addTask('ExportFromFileWHMCS:main', array('fromFile' => $fileName), 0, $_SESSION['uid']);
- custom\TaskManager::getTaskObjectByID($task->id)->run(true);
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- AjaxResponse::I()->addInfo('new_task_added');
- return AjaxResponse::I()->toArray();
- }
- public function importZonesJSON($input, $vars = array())
- {
- $add = false;
- $imported = false;
- foreach($input['zone'] as $resultId => $data)
- {
- if($data['import'] != 'on' && !isset($input['justOne']))
- {
- continue;
- }
- $imported = true;
- $task = new task\Task($input['id']);
- $task->status = task\TaskStatusEnum::IN_PROGRESS;
- $task->save();
- $result = new task\result\TaskResult($resultId);
- $task = custom\TaskManager::getTaskObjectByID($result->taskid);
- $main_task = $task->getParent();
- $result->data['resultid'] = $resultId;
- $result->data['domain'] = custom\helpers\IdnaHelper::idnaDecode($result->data['name']);
- $child = $main_task->addChild('import', $result->data);
- $result->data['status'] = 'importing';
- $result->data['taskid'] = $child->obj()->id;
- $result->save();
- if(isset($input['runNow']))
- {
- $child->run();
- if($child->getStatus() !== 'finished')
- {
- AjaxResponse::I()->addError('something_went_wrong_during_import');
- }
- else
- {
- AjaxResponse::I()->addInfo('zone_imported');
- }
- }
- else
- {
- if($add === false)
- {
- AjaxResponse::I()->addInfo('zonesUpdated');
- $add = true;
- }
- }
- }
- if(!$imported)
- {
- AjaxResponse::I()->addError('no_zone_selected_for_import_export');
- }
- return AjaxResponse::I()->toArray();
- }
- public function importJSON($input, $vars = array()) {
- return AjaxResponse::I()->refreshPage($this->importHTML($input, $vars))->toArray();
- }
- function refreshImportTableJSON($input, $vars = array())
- {
- $pRep = task\Repository::factory()->byParentID($input['id'])->one();
- $pRepName = explode(':', $pRep->name);
- $task = custom\TaskManager::getXTasks(1, $pRepName[0].':fetchZonesList', $input['id'], false);
- $task = end($task);
- $rep = task\result\Repository::factory()->byTaskID($task->id);
- $input['limit'] = $rep->count();
- $helper = new main\mgLibs\custom\RepoTableHelper($rep, $input, array('data'));
- $vars = $helper->getDataTableArray();
- foreach($helper->get() as $task)
- {
- $vars['data'][] = $this->dataTablesParseRow('import-row',
- array(
- 'item' => $task,
- 'importid' => $input['id'],
- )
- );
- }
- return $vars;
- }
- public function showListImportToFileJSON($input, $vars = array())
- {
- $vars['importid'] = $input['id'];
- AjaxResponse::I()->refreshPage(array('tpl' => 'import-list-to-file', 'vars' => $vars));
- return AjaxResponse::I()->toArray();
- }
- public function addBackupImportZonesJSON($input, $vars = array())
- {
- if(!$this->canAddBackup())
- {
- AjaxResponse::I()->addError('backups_limit_reached');
- return AjaxResponse::I()->toArray();
- }
- $fileName = custom\helpers\ImportExportFileHelper::generateClientFileName($_SESSION['uid']);
- $task = custom\TaskManager::addTask('ImportToFileWHMCS:main', array('from' => 'WHMCS', 'toFile' => $fileName, 'createdBy' => 'client'), 0, $_SESSION['uid']);
- custom\TaskManager::getTaskObjectByID($task->id)->run(true);
- AjaxResponse::I()->refreshPage($this->backupsHTML($input, $vars));
- AjaxResponse::I()->addInfo('new_task_added');
- $input['id'] = $task->id;
- return $this->showListImportToFileJSON($input);
- }
- public function addBackupFileJSON($input, $vars = array())
- {
- return AjaxResponse::I()->modal('add-backupFile', $vars)->toArray();
- }
- public function addExportShowZonesJSON($input, $vars = array())
- {
- return AjaxResponse::I()->modal('add-backupFile', $vars)->toArray();
- }
- public function setRecordsSaveJSON($input, $vars = array())
- {
- $zones = $input['zone']['checked'];
- $wipe = $input['wipe'];
- if(!$input['setRecord'])
- {
- $input['setRecord'] = $this->getDefaultSet();
- if(!$input['setRecord'])
- {
- return AjaxResponse::I()->addError('no_default_set_defined')->toArray();
- }
- }
- if($wipe == 'on')
- {
- $wipe = true;
- }
- else
- {
- $wipe = false;
- }
- $tasks = main\models\custom\task\Repository::factory()->setFilter('name', 'DnsRecord:main')->setFilter('status', 'start')->get();
- foreach($tasks as $task)
- {
- foreach($task->params['zones'] as $id => $zone)
- {
- if(array_key_exists($id, $zones) && $zones[$id] == 'on' && $zone == 'on')
- {
- return AjaxResponse::I()->addError('zone_already_in_task')->toArray();
- }
- }
- }
- foreach($zones as $id => $v)
- {
- if(!$v)
- {
- continue;
- }
- $zone = new Zone($id);
- $packageId = $zone->getPackage()->id;
- if($wipe == false)
- {
- $currentRecords = $zone->getModule()->getRecords();
- $limitCheck = custom\helpers\RecordSetHelper::checkAllowedRecordsLimits($packageId, $input['setRecord'],$currentRecords);
- }
- elseif($wipe == true)
- {
- $limitCheck = custom\helpers\RecordSetHelper::checkAllowedRecordsLimits($packageId, $input['setRecord']);
- }
- if(!$limitCheck)
- {
- return AjaxResponse::I()->addError('you_have_exceeded_limit')->toArray();
- }
- }
- $mainTask = custom\TaskManager::addTask('DnsRecord:main',array('recordId' => $input['setRecord'] , 'zones' => $zones, 'wipe' => $wipe));
- AjaxResponse::I()->addInfo('set_added_successfully');
- return AjaxResponse::I()->refreshPage($this->indexHTML($input))->toArray();
- }
- public function parseNewImportTaskList($list, &$vars)
- {
- foreach($list as $import)
- {
- $type = explode(':', $import->obj()->name);
- if($type[0] == 'ImportToFileWHMCS') //Panie rilis //TODO na langa to
- {
- $desc = str_replace('Import', 'Backup', $import->description());
- $desc = $this->praseTaskDescription($desc);
- }
- else
- {
- $desc = str_replace('Export', 'Restore', $import->description());
- $desc = $this->praseTaskExportDescription($desc);
- }
- $desc = str_replace('WHMCS', lang::T('backup', 'system'), $desc); // TODO przerobić to na next bo mess
- $vars[] = array(
- 'id' => $import->obj()->id,
- 'desc' => $import->description(),
- 'parsedDesc' => $desc,
- 'zones_imported' => '-',
- 'zones_total' => '-',
- 'progress' => -1,
- 'type' => $import->getTaskTypeCode()
- );
- }
- }
- private function praseTaskDescription($desc)
- {
- $parts = explode(' from: ', $desc);
- $parts[0] .= ' from: ';
- $tmpParts = explode(' to: ', $parts[1]);
- if(count($tmpParts) > 1)
- {
- $parts[1] = $tmpParts[0];
- $parts[2] = ' to: ';
- $parts[3] = ClientFilesManage::getFileNameWithoutClientId($tmpParts[1]);
- }
- return $parts;
- }
- private function praseTaskExportDescription($desc)
- {
- $parts = explode(' from: ', $desc);
- $parts[0] .= ' from: ';
- $tmpParts = explode(' to: ', $parts[1]);
- if(count($tmpParts) > 1)
- {
- $parts[1] = ClientFilesManage::getFileNameWithoutClientId($tmpParts[0]);
- $parts[2] = ' to: ';
- $parts[3] = $tmpParts[1];
- }
- return $parts;
- }
- private function getTaskError($task) {
- $erorr = false;
- if($task->getStatus() == task\TaskStatusEnum::ERROR) {
- $erorr = 'Error';
- $results = $task->getResults();
- $result = end($results);
- if(isset($result->data['error'])) {
- $erorr .= ' (' . $result->data['error'] . ')';
- }
- }
- return $erorr;
- }
- public function parseInProgresImportTaskList($list, &$vars, $type = 'Import', $clientId = false)
- {
- foreach($list as $import)
- {
- $rep = new task\Repository();
- $childTaskType = strpos($type, 'Export') === 0 ? 'export' : 'import';
- $rep->byParentID($import->obj()->id)->byName($type.':'.$childTaskType);
- $zones_total = $rep->count();
- $rep->byStatus(task\TaskStatusEnum::FINISHED);
- $zones_imported = $rep->count();
- if(is_array($type))
- {
- $type = $type[0];
- }
- $task = custom\TaskManager::getXTasksObjects(1, $type.':fetchZonesList', $import->obj()->id, false, $clientId);
- $error = $this->getTaskError(end($task));
- $type = explode(':', $import->obj()->name);
- if($type[0] == 'ImportToFileWHMCS') //Panie rilis //TODO na langa to
- {
- $desc = str_replace('Import', 'Backup', $import->description());
- $desc = $this->praseTaskDescription($desc);
- }
- else
- {
- $desc = str_replace('Export', 'Restore', $import->description());
- $desc = $this->praseTaskExportDescription($desc);
- }
- $desc = str_replace('WHMCS', lang::T('backup', 'system'), $desc); // TODO przerobić to na next bo mess
- $vars[] = array(
- 'id' => $import->obj()->id,
- 'desc' => $import->description(),
- 'zones_imported' => $zones_imported,
- 'zones_total' => $zones_total,
- 'progress' => $zones_total == 0 ? 0 : ceil($zones_imported * 100 / $zones_total),
- 'error' => $error,
- 'parsedDesc' => $desc,
- 'type' => $import->getTaskTypeCode(),//strpos($import->description(), 'Import') === 0 ? 'Import' : 'Export'
- 'status' => $import->obj()->status
- );
- }
- }
- private function redirectIfIsOnlyRDNSforCA()
- {
- if(GlobalSettingHelper::getSetting(GlobalSettingEnum::RDNS_IN_CLIENTAREA) == GlobalSettingEnum::CLIENTAREA_RNDS_ONLY)
- {
- header('Location: index.php?m=DNSManager2&mg-action=manageRDNS');
- die;
- }
- }
- /**
- * @param Zone $zone
- *
- * @return bool
- */
- private function isTransferAndShouldBeAbleToEdit( Zone $zone )
- {
- return $this->checkWhmcsProductStatus($zone->type, $zone->relid) === 'pending transfer';
- }
- }
|