db = Zend_Db_Table::getDefaultAdapter(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $session = new Application_Model_Session(); $sm = new Application_Model_SessionMapper(); //TODO Error Messages if something failed $alpha = $this->_request->getParam('alpha'); $apikey = $this->_request->getParam('apikey'); $this->rightrolesMapper = new Application_Model_RightRolesMapper(); if($this->getRequest()->getActionName() == 'login') { $email = $this->_request->getParam('email'); $password = $this->_request->getParam('password'); if(!isset($email)) { header('HTTP/1.0 401 No email is set'); die(); } if(!isset($password)) { header('HTTP/1.0 401 No password is set'); die(); } } else { if($apikey != ""){ $membershipMapper = new Application_Model_MembershipMapper(); $this->membership = new Application_Model_Membership(); list($this->membership) = $membershipMapper->findBy(array('apikey' => $apikey)); if($this->membership == null){ header('HTTP/1.0 401 Member not found'); die(); } } } if($alpha == "0"){ $bootmenuentryID = $this->_request->getParam('bootmenuentryID'); $this->page = $this->_request->getParam('page'); if(!is_numeric($bootmenuentryID)){ $this->_redirect('/user/bootmenu/index/page/'.$this->page.'/json/error'); } $bootmenuentry = new Application_Model_BootMenuEntries(); $bootmenuentryMapper = new Application_Model_BootMenuEntriesMapper(); $bootmenuMapper = new Application_Model_BootMenuMapper(); $bootmenuentryMapper->find($bootmenuentryID, $bootmenuentry); $session->setBootosID($bootmenuentry->getBootosID()) ->setBootmenuentryID($bootmenuentry->getID()) ->setTime(time()) ->setMembershipID('1') ->setIp($_SERVER['REMOTE_ADDR']) ->setAlphasessionID('0'); $this->thisSession = $session; } elseif($alpha != ""){ $alphasessionID = $alpha; $result = $sm->findBy(array('alphasessionID' => $alphasessionID),true); # print_a($result); $this->thisSession = $session->setOptions($result[0]); $this->thisSession->setID($result[0]['sessionID']); } } public function indexAction() { } //TODO Try/Catch + Metadata check public function addbootosAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '55', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Bootos'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; if($params['title'] == '' || $params['distro'] == '' || $params['distroversion'] == '' || $params['share'] == '' || $source == ''){ header('HTTP/1.0 400 Title, Distro, Distroversion and Share must be set'); die(); } if($_FILES['config']['size'] == 0 && $_FILES['config']['name'] != '' || $_FILES['kernel']['size'] == 0 && $_FILES['kernel']['name'] != ''|| $_FILES['init']['size'] == 0 && $_FILES['init']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); die(); } $bootosMapper = new Application_Model_BootOsMapper(); $groupID = $this->membership->getGroupID(); list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'], 'distro' => $params['distro'], 'distroversion' => $params['distroversion'], 'source' => $source, 'share' => $params['share'])); if($bootos != null){ header('HTTP/1.0 400 Bootos already exists'); die(); } $bootos = new Application_Model_BootOs(); $bootos->setOptions($params); $bootos->setGroupID($groupID); $bootos->setSource($source); $bootos->setCreated(time()); $bootos->setPublic('-1'); $bootosID = $bootosMapper->save($bootos); $bootos->setID($bootosID); $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $configpath = "../resources/bootos/".$bootosID."/config/"; mkdir($initpath ,0777, true); mkdir($kernelpath ,0777, true); mkdir($configpath ,0777, true); if($_FILES['config']['name'] != ''){ move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); } if($_FILES['kernel']['name'] != ''){ move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); } if($_FILES['init']['name'] != ''){ move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); $newconfig = new Pbs_NewConfig(); $newconfig->createDefaultConfig($bootos); } header('HTTP/1.0 201 Bootos created'); } public function editbootosAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '58', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Edit Bootos'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; if($params['title'] == '' || $params['distro'] == '' || $params['distroversion'] == '' || $params['share'] == '' || $source == ''){ header('HTTP/1.0 400 Title, Distro, Distroversion and Share must be set'); die(); } $bootos = new Application_Model_BootOs(); $bootosMapper = new Application_Model_BootOsMapper(); $groupID = $this->membership->getGroupID(); list($bootos) = $bootosMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'], 'distro' => $params['distro'], 'distroversion' => $params['distroversion'], 'source' => $source, 'share' => $params['share'])); if($bootos == null){ header('HTTP/1.0 400 Bootos not found'); die(); } $bootosID = $bootos->getID(); $bootossrc = $bootos->getSource(); $bootos->setOptions($params); $bootos->setID($bootosID); $bootos->setGroupID($groupID); $bootos->setSource($bootossrc); $bootos->setCreated(time()); $bootos->setPublic('-1'); $initpath = "../resources/bootos/".$bootosID."/initramfs/"; $kernelpath = "../resources/bootos/".$bootosID."/kernel/"; $configpath = "../resources/bootos/".$bootosID."/config/"; mkdir($initpath ,0777, true); mkdir($kernelpath ,0777, true); mkdir($configpath ,0777, true); if($_FILES['config']['name'] != ''){ $bootos->setSource($_SERVER['REMOTE_ADDR']); move_uploaded_file($_FILES['config']['tmp_name'], $configpath."default.tgz"); } if($_FILES['kernel']['name'] != ''){ $bootos->setSource($_SERVER['REMOTE_ADDR']); move_uploaded_file($_FILES['kernel']['tmp_name'], $kernelpath."kernel"); } if($_FILES['init']['name'] != ''){ $bootos->setSource($_SERVER['REMOTE_ADDR']); move_uploaded_file($_FILES['init']['tmp_name'], $initpath."initramfs"); } $bootosMapper->save($bootos); header('HTTP/1.0 201 Bootos edited'); } public function addfilterAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '87', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Filter'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $groupID = $this->membership->getGroupID(); $filterMapper = new Application_Model_FilterMapper(); $filter = new Application_Model_Filter(); $filter->setOptions($params); $filter->setGroupID($groupID); $filter->setCreated(time()); $filterid = $filterMapper->save($filter); $filter->setID($filterid); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $filter->getID() . "\n"; $xml .= "\t\t" . $filter->getBootmenuID() . "\n"; $xml .= "\t\t" . $filter->getCreated() . "\n"; $xml .= "\t\t" . $filter->getDescription() . "\n"; $xml .= "\t\t" . $filter->getMembershipID() . "\n"; $xml .= "\t\t" . $filter->getPriority() . "\n"; $xml .= "\t\t" . $filter->getTitle() . "\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="filter.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function addfilterentryAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '87', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Filter'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $filterentriesMapper = new Application_Model_FilterEntriesMapper(); $filterentries = new Application_Model_FilterEntries(); $filterentries->setOptions($params); $filterentriesID = $filterentriesMapper->save($filterentries); $filterentries->setFilterID($filterentriesID); $filterentries->setID($filterentriesID); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $filterentries->getID() . "\n"; $xml .= "\t\t" . $filterentries->getFilterID() . "\n"; $xml .= "\t\t" . $filterentries->getFiltertypeID() . "\n"; $xml .= "\t\t" . $filterentries->getFiltervalue() . "\n"; $xml .= "\t\t" . $filterentries->getFiltervalue2() . "\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="filterentry.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function deletefilterAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '90', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to delete Filter'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $groupID = $this->membership->getGroupID(); $filterid = $params['filterid']; $filterMapper = new Application_Model_FilterMapper(); $filter = new Application_Model_Filter(); $filterMapper->find($filterid, $filter); if(isset($filter)) { if($filter->getMembershipID() == $this->membership->getID() || $filter->getGroupID() == $this->membership->getGroupID()) { $filterMapper->delete($filter); header('HTTP/1.0 201 Filter deleted'); } else { header('HTTP/1.0 403 No Right to delete this Filter'); die(); } } else { header('HTTP/1.0 400 Filter not found'); die(); } } public function changefilterAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '88', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Filter'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $filterMapper = new Application_Model_FilterMapper(); $filterid = $params['filterid']; $filter = new Application_Model_Filter(); $filterMapper->find($filterid, $filter); if($filter->getID) { $filter->setOptions($params); if($filter->getMembershipID() == $this->membership->getID()) { $filterMapper->save($filter); header('HTTP/1.0 201 Filterentry changed'); } else { header('HTTP/1.0 403 No Right to change this Filterentry'); die(); } } else { header('HTTP/1.0 400 Filter not found'); die(); } } public function changefilterentryAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '88', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Filter'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $filterentriesMapper = new Application_Model_FilterEntriesMapper(); $filterentriesid = $params['filterentriesid']; $value1 = $params['value1']; $value2 = $params['value2']; if($filterentriesid) { $filterentries = new Application_Model_FilterEntries(); $filterentriesMapper->find($filterentriesid, $filterentries); $filterid = $filterentries->getFilterID(); } else { $oldvalue1 = $params['oldvalue1']; $oldvalue2 = $params['oldvalue2']; $filterid = $params['filterid']; $filterentries = $filterentriesMapper->findBy(array('filtervalue' => $oldvalue1, 'filtervalue2' => $oldvalue2, 'filterID', $filterid)); } if(isset($filterentries)) { $filterMapper = new Application_Model_FilterMapper(); $filter = new Application_Model_Filter(); $filterMapper->find($filterid, $filter); if($filter->getMembershipID() == $this->membership->getID()) { $filterentries->setFiltervalue($value1); $filterentries->setFiltervalu2($value2); $filterentriesMapper->save($filterentries); header('HTTP/1.0 201 Filterentry changed'); } else { header('HTTP/1.0 403 No Right to change this Filterentry'); die(); } } else { header('HTTP/1.0 400 Filterentry not found'); die(); } } public function addbootmenuAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '65', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Bootmenus'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $groupID = $this->membership->getGroupID(); $bootmenuMapper = new Application_Model_BootMenuMapper(); $bootmenuEntriesMapper = new Application_Model_BootMenuEntriesMapper(); $bootmenu = new Application_Model_BootMenu(); $bootmenu->setOptions($params); $bootmenu->setGroupID($groupID); $bootmenu->setCreated(time()); $bootmenuid = $bootmenuMapper->save($bootmenu); $bootmenu->setID($bootmenuid); $bootmenuentries = new Application_Model_BootMenuEntries(); $bootosMapper = new Application_Model_BootOsMapper(); $bootos = new Application_Model_BootOs(); $bootosMapper->find($params['bootosID'], $bootos); $params['title'] = $bootos->getTitle(); $bootmenuentries->setOptions($params); $bootmenuentries->setBootmenuID($bootmenu->getID()); $bootmenuentriesID = $bootmenuEntriesMapper->save($bootmenuentries); $bootmenuentries->setID($bootmenuentriesID); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $bootmenu->getID() . "\n"; $xml .= "\t\t" . $bootmenu->getCreated() . "\n"; $xml .= "\t\t" . $bootmenu->getGroupID() . "\n"; $xml .= "\t\t" . $bootmenu->getMembershipID() . "\n"; $xml .= "\t\t" . $bootmenu->getStartcounter() . "\n"; $xml .= "\t\t" . $bootmenu->getDefaultbootmenu() . "\n"; $xml .= "\t\t" . $bootmenu->getTitle() . "\n"; $xml .= "\t\t\n"; $xml .= "\t\t\t" . $bootmenuentries->getID() . "\n"; $xml .= "\t\t\t" . $bootmenuentries->getBootosID() . "\n"; $xml .= "\t\t\t" . $bootmenuentries->getConfigID() . "\n"; $xml .= "\t\t\t" . $bootmenuentries->getKcl() . "\n"; $xml .= "\t\t\t" . $bootmenuentries->getKclappend() . "\n"; $xml .= "\t\t\t" . $bootmenuentries->getOrder() . "\n"; $xml .= "\t\t\t" . $bootmenuentries->getTitle() . "\n"; $xml .= "\t\t\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="bootmenu.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function deletebootmenuAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '66', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to delete Bootmenus'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $groupID = $this->membership->getGroupID(); $bootmenuid = $params['bootmenuid']; $bootmenuMapper = new Application_Model_BootMenuMapper(); $bootmenu = new Application_Model_BootMenu(); $bootmenuMapper->find($bootmenuid, $bootmenu); if(isset($bootmenu)) { if($bootmenu->getMembershipID() == $this->membership->getID() || $bootmenu->getGroupID() == $this->membership->getGroupID()) { $bootmenuMapper->delete($bootmenu); header('HTTP/1.0 201 Bootmenu deleted'); } else { header('HTTP/1.0 403 No Right to delete this Bootmenu'); die(); } } else { header('HTTP/1.0 400 Filter not found'); die(); } } public function addprebootAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '40', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Create Preboots'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; if($params['title'] == '' || $_FILES['preboot']['name'] == ''){ header('HTTP/1.0 400 Title and Preboot must be set'); die(); } if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); die(); } $prebootMapper = new Application_Model_PreBootMapper(); $groupID = $this->membership->getGroupID(); list($preboot) = $prebootMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'])); if($preboot != null){ header('HTTP/1.0 400 Preboot already exists'); die(); } $preboot = new Application_Model_PreBoot(); $preboot->setOptions($params); $preboot->setGroupID($groupID); $preboot->setSource($source); $preboot->setCreated(time()); $prebootID = $prebootMapper->save($preboot); $prebootpath = "../resources/bootmedium/".$prebootID."/"; mkdir($prebootpath ,0777, true); if($_FILES['preboot']['name'] != '' ){ move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip"); } header('HTTP/1.0 201 Preboot created'); } public function editprebootAction() { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '41', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Edit Preboot'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; if($params['title'] == ''){ header('HTTP/1.0 400 Title must be set'); die(); } if($_FILES['preboot']['size'] == 0 && $_FILES['preboot']['name'] != ''){ header('HTTP/1.0 400 File must be larger than 0 bytes'); die(); } $prebootMapper = new Application_Model_PreBootMapper(); $groupID = $this->membership->getGroupID(); $preboot = new Application_Model_PreBoot(); list($preboot) = $prebootMapper->findBy(array('groupid' => $groupID, 'title' => $params['title'])); if($preboot == null){ header('HTTP/1.0 400 Preboot not found'); die(); } $prebootsrc = $preboot->getSource(); $prebootID = $preboot->getID(); $preboot->setOptions($params); $preboot->setGroupID($groupID); $preboot->setSource($prebootsrc); $preboot->setCreated(time()); $prebootpath = "../resources/bootmedium/".$prebootID."/"; mkdir($prebootpath ,0777, true); if($_FILES['preboot']['name'] != ''){ $preboot->setSource($source); move_uploaded_file($_FILES['preboot']['tmp_name'], $prebootpath."preboot.zip"); } $prebootMapper->save($preboot); header('HTTP/1.0 201 Preboot edited'); } public function getinitramfsAction() { $bootosID = $this->thisSession->getBootosID(); if(is_dir("../resources/bootos/$bootosID/initramfs/") && is_numeric($bootosID)){ header('Content-Type: application/x-gzip'); $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="initramfs"'); header('Pragma: no-cache'); header('Expires: 0'); // create file. chdir("../resources/bootos/$bootosID/initramfs/"); $initname = array_pop(scandir("./")); header("Content-Length: ".filesize(getcwd()."/".$initname)); passthru( "cat ".$initname); }else{ header('HTTP/1.0 404 Not Found'); } } public function getconfigAction() { $bootmenuentryID = $this->thisSession->getBootmenuentryID(); $bootmenuentry = new Application_Model_BootMenuEntries(); $bmm = new Application_Model_BootMenuEntriesMapper(); $bmm->find($bootmenuentryID,$bootmenuentry); $configID = $bootmenuentry->getConfigID(); $bootosID = $this->thisSession->getBootosID(); if(is_dir("../resources/bootos/$bootosID/config/")){ header('Content-Type: application/x-gzip'); $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="default.tgz"'); header('Pragma: no-cache'); header('Expires: 0'); if($configID == null){ chdir("../resources/bootos/$bootosID/config/"); passthru( "cat default.tgz"); }else{ $bootosuserMapper = new Application_Model_BootOsUserMapper(); $bootosuser = $bootosuserMapper->findBy(array('configID' => $configID)); $hash = md5(microtime(1)); $tmp_conf = "../resources/config/$hash"; mkdir($tmp_conf ,0777, true); exec("tar -C $tmp_conf -xf ../resources/bootos/$bootosID/config/default.tgz",$result); exec("tar -C $tmp_conf/rootfs/ -xf ../resources/config/etc.tgz"); $username = ''; $userpassword = ''; if($this->thisSession->getMembershipID() != null){ $person = new Application_Model_Person(); $personMapper = new Application_Model_PersonMapper(); $membershipMapper = new Application_Model_MembershipMapper(); $personID = $membershipMapper->find($this->thisSession->getMembershipID())->getPersonID(); $person = $personMapper->find($personID); $username = strtolower($person->getName()); $username = preg_replace("!\s!","",$username); $userpassword = $person->getLoginPassword(); } $anzUsers = count($bootosuser); $test = array(); if($anzUsers <= 2){ foreach($bootosuser as $user) $test[] = $user->getLogin(); } $configView = new Zend_View(); $f = fopen("$tmp_conf/initramfs/postinit.local", "a"); foreach($bootosuser as $user){ if($user->getLogin() == '%username%'){ $configView->loginname = $username; }else{ $configView->loginname = $user->getLogin(); } if($user->getPassword() == '%password%'){ $configView->password = $userpassword; }else{ $configView->password = $user->getPassword(); } if($user->getHometypeID() == 2){ $configView->homepath = $user->getHomepath(); }elseif($user->getHometypeID() == 1){ $configView->homepath = "/media/openslx-stick/home/".$configView->loginname; }else{ $configView->homepath = "/home/".$configView->loginname; } if($configView->loginname != '' && $configView->password != ''){ if($user->getHometypeID() == 1){ $configView->usb = true; } else{ $configView->usb = false; if($anzUsers <= 2 && $user->getLogin() == 'kiosk' && in_array('%username%',$test) && $this->thisSession->getMembershipID() == null) $configView->autologin = true; elseif($anzUsers <= 2 && $user->getLogin() == '%username%' && $this->thisSession->getMembershipID() != null) $configView->autologin = true; else $configView->autologin = false; } $configView->addScriptPath(APPLICATION_PATH.'/views/scripts/resource/'); $config = $configView->render('getconfig.phtml'); fputs($f, $config); } } fclose($f); // create the gzipped tarfile. chdir($tmp_conf); passthru( "tar cz *"); exec("rm -rf ../$hash"); } }else{ header('HTTP/1.0 404 Not Found'); } } public function getkernelAction() { $bootosID = $this->thisSession->getBootosID(); if(is_dir("../resources/bootos/$bootosID/kernel/") && is_numeric($bootosID)){ header('Content-Type: application/x-gzip'); $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="kernel"'); header('Pragma: no-cache'); header('Expires: 0'); // create the gzipped tarfile. chdir("../resources/bootos/$bootosID/kernel/"); $kernelname = array_pop(scandir("./")); header("Content-Length: ".filesize(getcwd()."/".$kernelname)); passthru( "cat ". $kernelname); }else{ header('HTTP/1.0 404 Not Found'); } } public function getkclAction() { $bmeID = $this->thisSession->getBootmenuentryID(); if(is_numeric($bmeID)){ $bmemapper = new Application_Model_BootMenuEntriesMapper(); $bme = new Application_Model_BootMenuEntries(); $bootosmapper = new Application_Model_BootOsMapper(); $bmemapper->find($bmeID,$bme); header('Content-Type: text/html'); $content_disp = ( ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']) == 'IE') ? 'inline' : 'attachment'; header('Content-Disposition: ' . $content_disp . '; filename="kcl.txt"'); header('Pragma: no-cache'); header('Expires: 0'); $kcl = $bootosmapper->find($bme->getBootosID())->getDefaultkcl(); if($bme->getKcl() && $kcl != null){ $result = $kcl . " alpha=" . $this->_request->getParam('alpha') . " file=http://".$_SERVER['HTTP_HOST']."/c/".$this->_request->getParam('alpha')."/default.tgz ".$bme->getKclappend(); }else{ $result = "alpha=" . $this->_request->getParam('alpha') . " file=http://".$_SERVER['HTTP_HOST']."/c/".$this->_request->getParam('alpha')."/default.tgz ".$bme->getKclappend(); } $result = trim($result); header("Content-Length: ".(strlen($result))); echo $result; } } public function getbootmenuentryAction() { // obsolete function (now only for debugging) // after selecting the BootOS it will be saved in session // so getkclAction, getkernelAction, getconfigAction and getinitramfsAction // can be called with session-identifier $return_val = array( 'info' => 'This function is for debugging purpose only', 'kernel' => $this->generateURL('getkernel', 'alpha', $this->thisSession->getAlphasessionID(), "kernel"), 'initramfs' => $this->generateURL('getinitramfs', 'alpha', $this->thisSession->getAlphasessionID(), "initramfs"), 'kcl' => $this->generateURL('getkcl', 'alpha', $this->thisSession->getAlphasessionID(), "kcl.txt"), 'config' => $this->generateURL('getconfig', 'alpha', $this->thisSession->getAlphasessionID(), 'default.tgz') ); $result = $return_val; $result2 = ""; $result2 .= ""; $result2 .= ""; $result2 .= ""; $result2 .= ""; $result2 .= ""; $result2 .= "
info: ".$result['info']."
kernel: ".$result['kernel']."
initramfs: ".$result['initramfs']."
kcl: ".$result['kcl']."
config: ".$result['config']."
"; echo $result2; } public function getbootosAction() { list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '56', 'roleID' => $this->membership->getRoleID())); list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '57', 'roleID' => $this->membership->getRoleID())); if($rightroles1 == null && $rightroles2 == null){ header('HTTP/1.0 403 No Right to Show Bootos'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $source = $_SERVER['REMOTE_ADDR']; $bootos = new Application_Model_BootOs(); $bootosMapper = new Application_Model_BootOsMapper(); $configsMapper = new Application_Model_ConfigMapper(); $groupID = $this->membership->getGroupID(); if(isset($params['bootosid'])) { $bootos = array($bootosMapper->find($params['bootosid'])); if($bootos[0]->getGroupID() != $groupID) { header('HTTP/1.0 403 No Right to Show this Bootos'); die(); } } else { $groupgroupsMapper = new Application_Model_GroupGroupsMapper(); $parents = array(); $bootos = array(); $parents = $groupgroupsMapper->getParentGroups($groupID); foreach($parents as $k => $parent) { foreach($parent as $p) { $results = $bootosMapper->findBy(array("groupID" => $p)); foreach ($results as $result) { if($result->getPublic() - $k >= 0 ) { $bootos[] = $result; } else if($k == 0 && $result->getPublic() == -1 && Pbs_Acl::checkRight('boc')) { $bootos[] = $result; } } } } } if($bootos == null){ header('HTTP/1.0 400 No Bootos was found'); die(); } $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; foreach($bootos as $bootosobj) { $xml .= "\t\t\n"; $xml .= "\t\t\t" . $bootosobj->getID() . "\n"; $xml .= "\t\t\t" . $bootosobj->getGroupID() . "\n"; $xml .= "\t\t\t" . $bootosobj->getMembershipID() . "\n"; $xml .= "\t\t\t" . $bootosobj->getTitle() . "\n"; $xml .= "\t\t\t" . $bootosobj->getDefaultkcl() . "\n"; $xml .= "\t\t\t" . $bootosobj->getCreated() . "\n"; $xml .= "\t\t\t" . $bootosobj->getDescription() . "\n"; $xml .= "\t\t\t" . $bootosobj->getExpires() . "\n"; $xml .= "\t\t\t" . $bootosobj->getPublic() . "\n"; $xml .= "\t\t\t" . $bootosobj->getSource() . "\n"; $xml .= "\t\t\t" . $bootosobj->getDistro() . "\n"; $xml .= "\t\t\t" . $bootosobj->getDistroversion() . "\n"; $xml .= "\t\t\t" . $bootosobj->getShortname() . "\n"; $xml .= "\t\t\t" . $bootosobj->getShare() . "\n"; $xml .= "\t\t\t\n"; $configs = $configsMapper->findBy(array('bootosID' => $bootosobj->getID())); if(is_array($configs)) { foreach($configs as $config) { if($config->getVisible()) { $xml .= "\t\t\t\t\n"; $xml .= "\t\t\t\t\t" . $config->getID() . "\n"; $xml .= "\t\t\t\t\t" . $config->getTitle() . "\n"; $xml .= "\t\t\t\t\t" . $config->getDescription() . "\n"; $xml .= "\t\t\t\t\t" . $config->getGroupID() . "\n"; $xml .= "\t\t\t\t\t" . $config->getMembershipID() . "\n"; $xml .= "\t\t\t\t\t" . $config->getCreated() . "\n"; $xml .= "\t\t\t\t\t" . $config->getVisible() . "\n"; $xml .= "\t\t\t\t\n"; } } } $xml .= "\t\t\t\n"; $xml .= "\t\t\n"; } $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="bootos.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function getpoolAction() { list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '79', 'roleID' => $this->membership->getRoleID())); if($rightroles1 == null){ header('HTTP/1.0 403 No Right to Show Pools'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $poolMapper = new Application_Model_PoolMapper(); $poolEntriesMapper = new Application_Model_PoolEntriesMapper(); $clientMapper = new Application_Model_ClientMapper(); $client = new Application_Model_Client(); $groupID = $this->membership->getGroupID(); if(isset($params['poolid'])) { $pool = array(new Application_Model_Pool()); $poolMapper->find($params['poolid'], $pool[0]); if($pool[0]->getGroupID() != $groupID) { header('HTTP/1.0 403 No Right to Show this Pool'); die(); } } else { $pool = $poolMapper->findBy(array('groupid' => $groupID)); } if($pool == null){ header('HTTP/1.0 400 No Pool was found'); die(); } $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; foreach($pool as $poolobj) { $xml .= "\t\t\n"; $xml .= "\t\t\t" . $poolobj->getID() . "\n"; $xml .= "\t\t\t" . $poolobj->getGroupID() . "\n"; $xml .= "\t\t\t" . $poolobj->getTitle() . "\n"; $xml .= "\t\t\t" . $poolobj->getDescription() . "\n"; $xml .= "\t\t\t" . $poolobj->getLocation() . "\n"; $poolentries = $poolEntriesMapper->findBy(array('poolID' => $poolobj->getID())); list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '75', 'roleID' => $this->membership->getRoleID())); if($rightroles2 != null){ $xml .= "\t\t\t\n"; foreach($poolentries as $poolentry) { $clientMapper->find($poolentry->getClientID(), $client); $xml .= "\t\t\t\t\n"; $xml .= "\t\t\t\t\t" . $client->getID() . "\n"; $xml .= "\t\t\t\t\t" . $client->getGroupID() . "\n"; $xml .= "\t\t\t\t\t" . $client->getMacadress() . "\n"; $xml .= "\t\t\t\t\t" . $client->getIp() . "\n"; $xml .= "\t\t\t\t\t" . $client->getIp6() . "\n"; $xml .= "\t\t\t\t\t" . $client->getHardwarehash() . "\n"; $xml .= "\t\t\t\t\t" . $client->getCreated() . "\n"; $xml .= "\t\t\t\t\n"; } $xml .= "\t\t\t\n"; } $xml .= "\t\t\n"; } $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="pool.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function getpersonAction() { $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } if($this->_request->getParam('personid')) { $personid = $this->_request->getParam('personid'); if($personid != $this->membership->getPersonID()) { list($rightroles) = $this->rightrolesMapper->findBy(array('rightID' => '6', 'roleID' => $this->membership->getRoleID())); if($rightroles == null){ header('HTTP/1.0 403 No Right to Show Details of other Person'); die(); } } } else { $personid = $this->membership->getPersonID(); } $personMapper = new Application_Model_PersonMapper(); $person = new Application_Model_Person(); $personMapper->find($personid,$person); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $person->getID() . "\n"; $xml .= "\t\t" . $person->getCity() . "\n"; $xml .= "\t\t" . $person->getEmail() . "\n"; $xml .= "\t\t" . $person->getFirstname() . "\n"; $xml .= "\t\t" . $person->getHousenumber() . "\n"; $xml .= "\t\t" . $person->getLogin() . "\n"; $xml .= "\t\t" . $person->getLogindate() . "\n"; $xml .= "\t\t" . $person->getName() . "\n"; $xml .= "\t\t" . $person->getPostalcode() . "\n"; $xml .= "\t\t" . $person->getRegisterdate() . "\n"; $xml .= "\t\t" . $person->getStreet() . "\n"; $xml .= "\t\t" . $person->getSuspend() . "\n"; $xml .= "\t\t" . $person->getTitle() . "\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="person.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function getgroupAction() { list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '79', 'roleID' => $this->membership->getRoleID())); if($rightroles1 == null){ header('HTTP/1.0 403 No Right to Show Groups'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $groupMapper = new Application_Model_GroupMapper(); if($this->_request->getParam('groupid')) { $groupid = $this->_request->getParam('groupid'); if($groupid != $this->membership->getGroupID()) { list($rightroles2) = $this->rightrolesMapper->findBy(array('rightID' => '11', 'roleID' => $this->membership->getRoleID())); if($rightroles2 == null){ header('HTTP/1.0 403 No Right to Show Details of other Group'); die(); } } } else { $groupid = $this->membership->getGroupID(); } $group = new Application_Model_Group(); $groupMapper->find($groupid, $group); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $group->getID() . "\n"; $xml .= "\t\t" . $group->getDescription() . "\n"; $xml .= "\t\t" . $group->getTitle() . "\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="group.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function getmembershipAction() { $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $membershipMapper = new Application_Model_MembershipMapper(); $membershipid = $this->membership->getID(); $membership = new Application_Model_Membership(); $membershipMapper->find($membershipid, $membership); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $membership->getID() . "\n"; $xml .= "\t\t" . $membership->getApikey() . "\n"; $xml .= "\t\t" . $membership->getGroupID() . "\n"; $xml .= "\t\t" . $membership->getPersonID() . "\n"; $xml .= "\t\t" . $membership->getRoleID() . "\n"; $xml .= "\t\t" . $membership->getSuspend() . "\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="membership.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function getclientAction() { list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '75', 'roleID' => $this->membership->getRoleID())); if($rightroles1 == null){ header('HTTP/1.0 403 No Right to Show Groups'); die(); } $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $params = $this->_request->getParams(); $clientid = $params['clientid']; $poolid = $params['poolid']; if(!isset($clientid)) { if(!isset($poolid)) { header('HTTP/1.0 400 No ID'); die(); } } $clientMapper = new Application_Model_ClientMapper(); $clientlist = array(); if($poolid) { $poolEntriesMapper = new Application_Model_PoolEntriesMapper(); $poolentries = $poolEntriesMapper->findBy(array("poolID" => $poolid)); foreach($poolentries as $entry) { $client = new Application_Model_Client(); $clientMapper->find($entry->getClientID(), $client); $clientlist[] = $client; } } else if($clientid) { $client = new Application_Model_Client(); $clientMapper->find($clientid, $client); $clientlist[] = $client; } $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; if(count($clientlist) > 0) { foreach($clientlist as $client) { $xml .= "\t\t\n"; $xml .= "\t\t\t" . $client->getID() . "\n"; $xml .= "\t\t\t" . $client->getGroupID() . "\n"; $xml .= "\t\t\t" . $client->getMacadress() . "\n"; $xml .= "\t\t\t" . $client->getIp() . "\n"; $xml .= "\t\t\t" . $client->getIp6() . "\n"; $xml .= "\t\t\t" . $client->getHardwarehash() . "\n"; $xml .= "\t\t\t" . $client->getCreated() . "\n"; $xml .= "\t\t\n"; } } else { $xml .= "\t\tno clients\n"; } $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="client.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function getroleAction() { $params = $this->_request->getParams(); $apikey = $params['apikey']; if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $roleMapper = new Application_Model_RoleMapper(); if(isset($params['roleid'])) { $roleID = $params['roleid']; if($this->membership->getRoleID() != $roleID) { list($rightroles1) = $this->rightrolesMapper->findBy(array('rightID' => '24', 'roleID' => $this->membership->getRoleID())); if($rightroles1 == null){ header('HTTP/1.0 403 No Right to Show Roles'); die(); } } } else { $roleID = $this->membership->getRoleID(); } $role = new Application_Model_Role(); $roleMapper->find($roleID, $role); $newRoleID = $role->getID(); if(!isset($newRoleID)) { header('HTTP/1.0 400 No Role was found'); die(); } $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $xml .= "\t\t" . $role->getID() . "\n"; $xml .= "\t\t" . $role->getGroupID() . "\n"; $xml .= "\t\t" . $role->getTitle() . "\n"; $xml .= "\t\t" . $role->getDescription() . "\n"; $xml .= "\t\t" . $role->getInheritance() . "\n"; $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="role.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function checkrightAction() { $apikey = $this->_request->getParam('apikey'); if($apikey == ""){ header('HTTP/1.0 400 No API-Key'); die(); } $rightShortcut = $this->_request->getParam('rightshortcut'); $rightMapper = new Application_Model_RightMapper(); $result = $rightMapper->findBy(array('shortcut' => $rightShortcut)); if(count($result) < 1) { header('HTTP/1.0 400 Wrong Right Shortcut'); die(); } $right = $result[0]; $roleid = $this->membership->getRoleID(); $rightid = $right->getID(); $rightrolesMapper = new Application_Model_RightRolesMapper(); $rightroles = $rightrolesMapper->find($roleid, $rightid); $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; if(is_object($rightroles)) { $xml .= "\t\ttrue\n"; } else { $xml .= "\t\tfalse\n"; } $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="checkright.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } public function loginAction() { $xml = "\n"; $xml .= "\n"; $xml .= "\t\n"; $email = $this->_request->getParam('email'); $password = $this->_request->getParam('password'); $auth = Zend_Auth::getInstance(); $adapter = new Zend_Auth_Adapter_DbTable( $this->db, 'pbs_person', 'email', 'password', 'MD5(CONCAT(?, password_salt))'); $adapter->setIdentity($email); $adapter->setCredential($password); $result = $auth->authenticate($adapter); if(!$result->isValid()) { $xml .= "\t\tfalse\n"; $xml .= "\t\twrong email or password\n"; } else { $personMapper = new Application_Model_PersonMapper(); $result = $personMapper->findBy(array('email' => Zend_Auth::getInstance()->getIdentity()),true); $person = new Application_Model_Person($result[0]); $person->setID($result[0]['personID']); if($person->getSuspend()) { $xml .= "\t\tfalse\n"; $xml .= "\t\t" . $person->getID() . ""; $xml .= "\t\tperson suspended\n"; } else { $xml .= "\t\ttrue\n"; $xml .= "\t\t" . $person->getID() . ""; $membershipMapper = new Application_Model_MembershipMapper(); $memberships = $membershipMapper->findBy(array('personID' => $person->getID())); $xml .= "\t\t\n"; if(is_array($memberships)) { foreach($memberships as $membership) { $xml .= "\t\t\t\n"; $xml .= "\t\t\t\t" . $membership->getID() . "\n"; $xml .= "\t\t\t\t" . $membership->getGroupID() . "\n"; $xml .= "\t\t\t\t" . $membership->getRoleID() . "\n"; $xml .= "\t\t\t\t" . $membership->getPersonID() . "\n"; $xml .= "\t\t\t\t" . $membership->getSuspend() . "\n"; $xml .= "\t\t\t\t" . $membership->getApikey() . "\n"; $xml .= "\t\t\t\n"; } } else { $xml .= "\t\t\tno memberships founded\n"; } $xml .= "\t\t\n"; } } $xml .= "\t\n"; $xml .= ""; header('Content-Type: text/xml'); header('Content-Disposition: inline; filename="login.xml"'); header('Content-Length: ' . strlen($xml)); header('Pragma: no-cache'); header('Expires: 0'); echo $xml; } private function generateURL($action, $varname, $varvalue, $filename){ $path = '/resource/'. $action .'/' . $varname .'/' . $varvalue .'/bootmenuentryID/'.$this->thisSession->getBootmenuentryID().'/file/' . $filename ; $path = "http://" . $_SERVER['SERVER_NAME'] . $path; return $path; } }