public function create(RESTRequest $request)
 {
     $data = $request->getData();
     if (empty($data)) {
         throw new RESTCommandException('HTTP POST data is empty');
     }
     $allowed_to_update_fields = array_fill_keys(array('login', 'password', 'full_name', 'phone', 'account_number', 'tariff_plan', 'status', 'stb_mac', 'comment', 'end_date', 'account_balance'), true);
     $account = array_intersect_key($data, $allowed_to_update_fields);
     if (empty($account)) {
         throw new RESTCommandException('Insert data is empty');
     }
     if (!empty($account['stb_mac'])) {
         $mac = Middleware::normalizeMac($account['stb_mac']);
         if (!$mac) {
             throw new RESTCommandException('Not valid mac address');
         }
         $account['stb_mac'] = $mac;
     }
     if (empty($account['login'])) {
         throw new RESTCommandException('Login required');
     }
     $user = User::getByLogin($account['login']);
     if (!empty($user)) {
         throw new RESTCommandException('Login already in use');
     }
     if (!empty($account['stb_mac'])) {
         $user = User::getByMac($account['stb_mac']);
         if (!empty($user)) {
             throw new RESTCommandException('MAC address already in use');
         }
     }
     return (bool) User::createAccount($account);
 }
 public function create(RESTRequest $request)
 {
     $data = $request->getData();
     if (empty($data)) {
         throw new RESTCommandException('HTTP POST data is empty');
     }
     $allowed_to_update_fields = array_fill_keys(array('mac', 'login', 'password', 'status', 'additional_services_on', 'ls', 'end_date', 'account_balance'), true);
     $data = array_intersect_key($data, $allowed_to_update_fields);
     if (empty($data)) {
         throw new RESTCommandException('Insert data is empty');
     }
     if (isset($data['end_date'])) {
         $data['expire_billing_date'] = $data['end_date'];
         unset($data['end_date']);
     }
     if (!empty($data['mac'])) {
         $mac = Middleware::normalizeMac($data['mac']);
         if (!$mac) {
             throw new RESTCommandException('Not valid mac address');
         }
         $data['mac'] = $mac;
     }
     if (empty($data['mac']) && (empty($data['login']) || empty($data['password']))) {
         throw new RESTCommandException('Login and password required');
     }
     try {
         $uid = Stb::create($data);
     } catch (Exception $e) {
         throw new RESTCommandException($e->getMessage());
     }
     $stb_list = $this->manager->getByUids(array($uid));
     $stb_list = $this->formatList($stb_list);
     if (count($stb_list) == 1) {
         return $stb_list[0];
     }
     return $stb_list;
 }
Ejemplo n.º 3
0
    $stb_groups = new StbGroup();
    $member = $stb_groups->getMemberByUid(intval($_GET['id']));
    if (empty($member)) {
        $stb_groups->addMember(array('mac' => Middleware::normalizeMac($_POST['mac']), 'uid' => Middleware::getUidByMac($_POST['mac']), 'stb_group_id' => $_POST['group_id']));
    } else {
        $stb_groups->setMember(array('stb_group_id' => $_POST['group_id']), $member['id']);
    }
    header("Location: profile.php?id=" . @$_GET['id']);
    exit;
}
if (@$_POST['account']) {
    Admin::checkAccess(AdminAccess::ACCESS_EDIT);
    $stb_groups = new StbGroup();
    $member = $stb_groups->getMemberByUid(intval($_GET['id']));
    if (empty($member)) {
        $stb_groups->addMember(array('mac' => Middleware::normalizeMac($_POST['mac']), 'uid' => Middleware::getUidByMac($_POST['mac']), 'stb_group_id' => $_POST['group_id']));
    } else {
        $stb_groups->setMember(array('stb_group_id' => $_POST['group_id']), $member['id']);
    }
    Mysql::getInstance()->update('users', array('fname' => $_POST['fname'], 'phone' => $_POST['phone'], 'ls' => $_POST['ls'], 'comment' => $_POST['comment'], 'expire_billing_date' => $_POST['expire_billing_date']), array('id' => intval($_GET['id'])));
    header("Location: profile.php?id=" . @$_GET['id']);
    exit;
}
if (@$_GET['video_out']) {
    Admin::checkAccess(AdminAccess::ACCESS_CONTEXT_ACTION);
    $video_out = @$_GET['video_out'];
    $id = intval($_GET['id']);
    if ($video_out == 'svideo') {
        $new_video_out = 'svideo';
    } else {
        $new_video_out = 'rca';
Ejemplo n.º 4
0
session_start();
include "./common.php";
Admin::checkAuth();
Admin::checkAccess(AdminAccess::ACCESS_VIEW);
foreach (@$_POST as $key => $value) {
    //$_POST[$key] = trim($value);
}
$error = '';
$action_name = 'add';
$action_value = _('Add');
$tariff_plans = Mysql::getInstance()->select('id, name')->from('tariff_plan')->orderby('name')->get()->all();
if (!empty($_POST)) {
    if (!empty($_POST['login']) && !empty($_POST['password'])) {
        $user = \User::getByLogin($_POST['login']);
        if (!empty($_POST['stb_mac'])) {
            $mac = Middleware::normalizeMac($_POST['stb_mac']);
            $_POST['stb_mac'] = $mac;
            if (!$mac) {
                $error = _('Error: Not valid mac address');
            } else {
                $user_by_mac = \User::getByMac($mac);
                if (!empty($user_by_mac)) {
                    $error = _('Error: STB with such MAC address already exists');
                }
            }
        }
        if ($error) {
        } else {
            if (!empty($user)) {
                $error = _('Error: Login already in use');
            } else {
Ejemplo n.º 5
0
 public static function getByMac($mac)
 {
     $mac = Middleware::normalizeMac($mac);
     if (empty($mac)) {
         return null;
     }
     return Mysql::getInstance()->from('users')->where(array('mac' => $mac))->get()->first();
 }
Ejemplo n.º 6
0
 private function saveUsersData(&$form, $edit = FALSE)
 {
     if (!empty($this->method) && $this->method == 'POST') {
         $form->handleRequest($this->request);
         $data = $form->getData();
         $action = isset($this->user) ? 'updateUserById' : 'insertUsers';
         if (array_key_exists('password', $data) && $edit && empty($data['password'])) {
             unset($data['password']);
         }
         if ($form->isValid()) {
             $stb_groups = new \StbGroup();
             $member = $stb_groups->getMemberByUid(intval($data['id']));
             $id = $data['id'];
             if (empty($member)) {
                 $stb_groups->addMember(array('mac' => \Middleware::normalizeMac($data['mac']), 'uid' => \Middleware::getUidByMac($data['mac']), 'stb_group_id' => $data['group_id']));
             } else {
                 $stb_groups->setMember(array('stb_group_id' => $data['group_id']), $member['id']);
             }
             $curr_fields = $this->db->getTableFields('users');
             $curr_fields = $this->getFieldFromArray($curr_fields, 'Field');
             $curr_fields = array_flip($curr_fields);
             $data = array_intersect_key($data, $curr_fields);
             $match = array();
             if (!empty($data['expire_billing_date']) && preg_match("/(0[1-9]|[12][0-9]|3[01])([- \\/\\.])(0[1-9]|1[012])[- \\/\\.](19|20)\\d\\d/im", $data['expire_billing_date'], $match)) {
                 $data['expire_billing_date'] = implode('-', array_reverse(explode($match[2], $data['expire_billing_date'])));
             } else {
                 $data['expire_billing_date'] = 0;
             }
             if ($data['reseller_id'] == '-') {
                 $data['reseller_id'] = NULL;
             }
             if (!empty($this->user) && array_key_exists('status', $this->user) && (int) $this->user['status'] != (int) $data['status']) {
                 $data['last_change_status'] = FALSE;
                 $event = new \SysEvent();
                 $event->setUserListById($data['id']);
                 if ((int) $data['status'] == 0) {
                     $event->sendCutOn();
                 } else {
                     $event->sendCutOff();
                 }
             } else {
                 unset($data['last_change_status']);
             }
             unset($data['version']);
             $result = call_user_func_array(array($this->db, $action), array($data, $data['id']));
             if (!empty($this->postData['tariff_plan_packages'])) {
                 $this->changeUserPlanPackages($id, $this->postData['tariff_plan_packages']);
             }
             return TRUE;
         }
     }
     return FALSE;
 }
Ejemplo n.º 7
0
$group = $stb_groups->getById($_GET['group_id']);
if (empty($group)) {
    echo 'wtf?';
    exit;
}
if (@$_POST['add']) {
    Admin::checkAccess(AdminAccess::ACCESS_CREATE);
    $stb_groups->addMember(array('mac' => Middleware::normalizeMac($_POST['mac']), 'uid' => Middleware::getUidByMac($_POST['mac']), 'stb_group_id' => $_GET['group_id']));
    header("Location: stbgroup_members.php?group_id=" . @$_GET['group_id']);
    exit;
}
$action = !empty($_POST['edit']) ? 'edit' : (!empty($_GET['del']) ? 'del' : FALSE);
if (!empty($id) && $action) {
    if ($action == 'edit') {
        Admin::checkAccess(AdminAccess::ACCESS_EDIT);
        $stb_groups->setMember(array('mac' => Middleware::normalizeMac($_POST['mac']), 'uid' => Middleware::getUidByMac($_POST['mac'])), $id);
    } else {
        Admin::checkAccess(AdminAccess::ACCESS_DELETE);
        $stb_groups->removeMember($id);
    }
    header("Location: stbgroup_members.php?group_id=" . @$_GET['group_id']);
    exit;
}
if (@$_GET['edit'] && !empty($id)) {
    $action_name = 'edit';
    $action_value = _('Save');
    $edit_member = $stb_groups->getMember($id);
}
$members = $stb_groups->getAllMembersByGroupId($_GET['group_id']);
$debug = '<!--' . ob_get_contents() . '-->';
ob_clean();
Ejemplo n.º 8
0
 $bonus2 = get_bonus2();
 $stb_id_arr = array();
 foreach ($f_cont as $cont_str) {
     list($ls, $macs, $ch) = explode(",", $cont_str);
     $macs_arr = explode(";", $macs);
     $ch = trim($ch);
     $ls = trim($ls);
     foreach ($macs_arr as $mac) {
         if (preg_match("/[а-я,А-Я]/", $mac)) {
             _log('mac "' . $mac . '", ЛС ' . $ls . ' содержит русские буквы ');
         }
         if (strpos($mac, 'ts') !== false) {
             $mac = str_replace('ts', '', $mac);
             $ch = '00203';
         }
         $mac = Middleware::normalizeMac($mac);
         if (@array_key_exists($mac, $stb_id_map)) {
             $stb = Stb::getByMac($mac);
             $status = $stb['status'];
             if ($status == 1 && $update_status) {
                 Mysql::getInstance()->update('users', array('status' => 0, 'last_change_status' => 'NOW()'), array('mac' => $mac));
                 $event = new SysEvent();
                 $event->setUserListByMac($mac);
                 $event->sendCutOn();
                 $cut_on++;
             }
             $stb_id = $stb_id_map[$mac];
             $stb_id_arr[] = $stb_id;
             if (array_key_exists($ch, $service_id_map)) {
                 if (!@array_key_exists($stb_id, $result)) {
                     $result[$stb_id] = array();
Ejemplo n.º 9
0
Admin::checkAuth();
Admin::checkAccess(AdminAccess::ACCESS_VIEW);
foreach (@$_POST as $key => $value) {
    $_POST[$key] = trim($value);
}
if (@$_POST['add']) {
    Admin::checkAccess(AdminAccess::ACCESS_CREATE);
    Mysql::getInstance()->insert('testers', array('mac' => Middleware::normalizeMac($_POST['mac'])));
    header("Location: testers.php");
    exit;
}
$id = @intval($_GET['id']);
if (!empty($id)) {
    if (@$_POST['edit']) {
        Admin::checkAccess(AdminAccess::ACCESS_EDIT);
        Mysql::getInstance()->update('testers', array('mac' => Middleware::normalizeMac($_POST['mac'])), array('id' => $id));
        header("Location: testers.php");
    } elseif (@$_GET['del']) {
        Admin::checkAccess(AdminAccess::ACCESS_DELETE);
        Mysql::getInstance()->delete('testers', array('id' => $id));
        header("Location: testers.php");
    } elseif (isset($_GET['status'])) {
        Admin::checkAccess(AdminAccess::ACCESS_CONTEXT_ACTION);
        $new_status = $_GET['status'];
        Mysql::getInstance()->update('testers', array('status' => $new_status), array('id' => $id));
        header("Location: testers.php");
    }
    exit;
}
if (@$_GET['edit'] && !empty($id)) {
    $action_name = 'edit';
 private function checkLoginAndMac($params)
 {
     if (empty($params['login'])) {
         throw new SoapMissingRequiredParam();
     }
     if (!empty($params['stb_mac'])) {
         $params['stb_mac'] = \Middleware::normalizeMac($params['stb_mac']);
         if (empty($params['stb_mac'])) {
             throw new SoapWrongMacFormat(__METHOD__, __FILE__ . ':' . __FILE__);
         }
         $user = \User::getByLogin($params['login']);
         if (empty($user) || $user->getMac() != $params['stb_mac']) {
             $stb = \Stb::getByMac($params['stb_mac']);
             if (!empty($stb)) {
                 throw new SoapMacAddressInUse(__METHOD__, __FILE__ . ':' . __FILE__);
             }
         }
     }
 }