Skip to content

Commit

Permalink
Merge pull request #3 from Cyber-Root0/plano_ensino
Browse files Browse the repository at this point in the history
feat: plano de ensino | aulas | materiais | resumo
  • Loading branch information
Cyber-Root0 authored Sep 9, 2023
2 parents c571f65 + ea2a43c commit d4685bd
Show file tree
Hide file tree
Showing 9 changed files with 490 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/classes/HttpFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct($method,$url,$path,$body,$cookie=null){
public function request(){

$response = $this->client->request($this->method, $this->url . '/' . $this->path, [
'body' => $this->body,
'form_params' => $this->body,
'cookies' => $this->cookie,
"allow_redirects" => false,
"verify" => false,
Expand Down
5 changes: 5 additions & 0 deletions app/config/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
//Dados do Aluno
$this->get('/api/aluno/all', 'aluno\\aluno@get');

//Plano de ensino
$this->get('/api/plano-ensino/', 'planoensino\\planoensino@get');
$this->get('/api/plano-ensino/materiais/', 'planoensino\\materiais\\materiais@get');
$this->get('/api/plano-ensino/aulas/', 'planoensino\\aulas\\aulas@get');




52 changes: 27 additions & 25 deletions app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@
define("BASE", '/');
define('UNSET_URI_COUNT',0);
define('DEBUG_URI',false);

//HTTP REQUEST
define("SIGA_REQUEST_LOGIN",'{
"_EventName": "E\'EVT_CONFIRMAR\'.",
"_EventGridId": "",
"_EventRowId": "",
"MPW0005_CMPPGM": "login_top.aspx",
"MPW0005GX_FocusControl": "",
"vSAIDA": "",
"vREC_SIS_USUARIOID": "",
"GX_FocusControl": "vSIS_USUARIOID",
"GX_AJAX_KEY": "8E52B5B99D70A87D9EE89570291ACC86",
"AJAX_SECURITY_TOKEN": "A8B9DECE0E27179FF4F5F08F98769E720CB87ABB4460CC4A68C467A81BF554BB",
"GX_CMP_OBJS": {
"MPW0005": "login_top"
},
"sCallerURL": "",
"GX_RES_PROVIDER": "GXResourceProvider.aspx",
"GX_THEME": "GeneXusX",
"_MODE": "",
"Mode": "",
"IsModified": "1"
}'
);

define('PLANO_ENSINO', true);
define('GENEXUS_BYPASS', "https://genexus-key.vercel.app/");
define("DOMAIN_SIGA", "siga.cps.sp.gov.br");
define("PAGE_ALL_HISTORY", "https://siga.cps.sp.gov.br/aluno/historicocompleto.aspx");
define("PAGE_LOGIN","https://siga.cps.sp.gov.br/aluno/login.aspx");
define("PLANO_ENSINO_URL", "https://siga.cps.sp.gov.br/aluno/planoensino.aspx");


//HTTP REQUEST
define("SIGA_REQUEST_LOGIN",'{
"_EventName": "E\'EVT_CONFIRMAR\'.",
"_EventGridId": "",
"_EventRowId": "",
"MPW0005_CMPPGM": "login_top.aspx",
"MPW0005GX_FocusControl": "",
"vSAIDA": "",
"vREC_SIS_USUARIOID": "",
"GX_FocusControl": "vSIS_USUARIOID",
"GX_AJAX_KEY": "8E52B5B99D70A87D9EE89570291ACC86",
"AJAX_SECURITY_TOKEN": "A8B9DECE0E27179FF4F5F08F98769E720CB87ABB4460CC4A68C467A81BF554BB",
"GX_CMP_OBJS": {
"MPW0005": "login_top"
},
"sCallerURL": "",
"GX_RES_PROVIDER": "GXResourceProvider.aspx",
"GX_THEME": "GeneXusX",
"_MODE": "",
"Mode": "",
"IsModified": "1"
}'
);
57 changes: 57 additions & 0 deletions app/controller/planoensino/Helper/json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"_EventName":"W0008EHISTORYMANAGER.URLCHANGED.",
"_EventGridId":"",
"_EventRowId":"",
"W0005_CMPPGM":"planotitulo.aspx",
"W0008":"TabbedView",
"W0008AV18Tabs_PARM":[
{
"Code":"1",
"Description":"Apresentação",
"Link":"planoensino.aspx?1",
"WebComponent":"planoapresentacao.aspx?disciplina"
},
{
"Code":"2",
"Description":"Aulas",
"Link":"planoensino.aspx?2",
"WebComponent":"planoaulas.aspx?disciplina"
},
{
"Code":"3",
"Description":"Avaliações",
"Link":"planoensino.aspx?3",
"WebComponent":"planoavaliacoes.aspx?disciplina"
},
{
"Code":"4",
"Description":"Extra-classe",
"Link":"planoensino.aspx?4",
"WebComponent":"planoextraclasse.aspx?disciplina"
},
{
"Code":"5",
"Description":"Material",
"Link":"planoensino.aspx?5",
"WebComponent":"planomaterial.aspx?disciplina"
},
{
"Code":"6",
"Description":"Bibliografia",
"Link":"planoensino.aspx?6",
"WebComponent":"planobibliografia.aspx?disciplina"
}
],
"W0008_CMPPGM":"tabbedview.aspx",
"W0008HISTORYMANAGER_Hash":"5",
"GX_AJAX_KEY":"47864ACC55A417C2EF949947B382C5F5",
"AJAX_SECURITY_TOKEN":"FB5B4ADFA5A30DD14923A13AC1AE310451E1781A37B80C1C6CD4572C49B6B46E",
"GX_RES_PROVIDER":"GXResourceProvider.aspx",
"AV5SHOW_ACD_DisciplinaSigla":"disciplina",
"W0008W0013":"planoapresentacao.aspx?disciplina",
"W0008W0013AV39SHOW_ACD_DisciplinaSigla_PARM":"disciplina",
"W0008W0013_CMPPGM":"planoapresentacao.aspx",
"W0008W0013GX_FocusControl":"W0008W0013vACD_PLANOENSINOTITULO",
"W0008W0013AV39SHOW_ACD_DisciplinaSigla":"disciplina",
"AV39SHOW_ACD_DisciplinaSigla":"disciplina"
}
87 changes: 87 additions & 0 deletions app/controller/planoensino/MethodPlans.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/*
* @software API for the Siga Student System | Fatec
* @author Bruno Venancio Alves <boteistem@gmail.com>
* @copyrigh (c) 2023
* @license Open Software License v. 3.0 (OSL-3.0)
*/
namespace app\controller\planoensino;
use GuzzleHttp\Client;
trait MethodPlans{

public function GetAjaxKey($GXState){

$package = json_decode($GXState);
if (!empty($package->GX_AJAX_KEY)){
return $package->GX_AJAX_KEY;
}

return false;

}
public function EncryptAjaxKey($key){
$URL = GENEXUS_BYPASS."?".http_build_query($this->PackageKey($key));
return $this->MakeRequest("GET", $URL, []);

}
private function GetPlan($json, $disciplina, $action_code, $cookie = null){

$ajax_key = $this->GetAjaxKey($json);
$bypass_key = $this->EncryptAjaxKey($ajax_key);
$GXState = $this->GetGXState($disciplina, $action_code);
$PLAN_URL = PLANO_ENSINO_URL."?$bypass_key";
$plan = $this->MakeRequest("POST", $PLAN_URL, array(
"GXState" => $GXState
), $cookie);

return $plan;
}

private function MakeRequest(string $method, string $url,array $params = [], $cookie =null){
$client = new Client();
$response = $client->request($method, $url, [
'form_params' => $params,
'headers' => [
'gxajaxrequest' => '1',
'content-type' => 'application/x-www-form-urlencoded',
],
'cookies' => $cookie,
]);
$body = $response->getBody()->getContents();
return $body;

}

private function GetGXState($disciplina, $action_code){

$Gxstate = json_decode(file_get_contents( __DIR__.'/Helper/json.json'));
$GxstateReplaced = $this->ReplaceParamGxstate($Gxstate, $disciplina, $action_code);
return $GxstateReplaced;

}

private function ReplaceParamGxstate($content, $disciplina, $action){

foreach( $content->W0008AV18Tabs_PARM as $key => $actions ){

$webComponent = $content->W0008AV18Tabs_PARM[$key]->WebComponent;
$content->W0008AV18Tabs_PARM[$key]->WebComponent = str_replace("disciplina", $disciplina, $webComponent);
}

$content->W0008HISTORYMANAGER_Hash = $action;
$content->AV5SHOW_ACD_DisciplinaSigla = $disciplina;
$content->W0008W0013 = str_replace("disciplina", $disciplina, $content->W0008W0013);
$content->W0008W0013AV39SHOW_ACD_DisciplinaSigla_PARM = str_replace("disciplina", $disciplina, $content->W0008W0013AV39SHOW_ACD_DisciplinaSigla_PARM);
$content->W0008W0013AV39SHOW_ACD_DisciplinaSigla = str_replace("disciplina", $disciplina, $content->W0008W0013AV39SHOW_ACD_DisciplinaSigla);
$content->AV39SHOW_ACD_DisciplinaSigla = str_replace("disciplina", $disciplina, $content->AV39SHOW_ACD_DisciplinaSigla);

return json_encode($content);
}

private function PackageKey(string $key){
return array(
"key" => $key,
);
}

}
104 changes: 104 additions & 0 deletions app/controller/planoensino/aulas/aulas.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/*
* @software API for the Siga Student System | Fatec
* @author Bruno Venancio Alves <boteistem@gmail.com>
* @copyrigh (c) 2023
* @license Open Software License v. 3.0 (OSL-3.0)
*/
namespace app\controller\planoensino\aulas;
use app\core\Controller;
use app\interfaces\ControllerInterface;
use app\classes\Input;
use app\classes\FixJson;
use app\controller\Session\Cookie;
use app\classes\HttpFactory;
use Symfony\Component\DomCrawler\Crawler;
use app\controller\planoensino\MethodPlans;

Class aulas extends Controller{
use MethodPlans;
public $uid = null;
public $disciplina = null;
protected $header = "Content-Type:text/html; charset=utf-8";
protected $http_client = null;

protected Crawler $crawler;

protected string $action_code = "2";

public function index(){

}

public function __construct(){

$this->uid = Input::get("uid");
$this->disciplina = Input::get("disciplina");
$this->crawler = new Crawler;
parent::__construct();
}

public function get(){


if ($this->status_cookie && !empty($this->disciplina)){

$XML_HTML = $this->getContent($this->cookie->getCookie());
$this->crawler->addHtmlContent($XML_HTML);
$notas = $this->crawler->filter('input[name="GXState"]')->attr('value');
$json = $this->fixJson($notas);

$content = $this->GetPlan($json, $this->disciplina, $this->action_code, $this->cookie->getCookie());
$content = $this->fixJson($content);
$output = $this->trataJson(json_decode($content));
$this->response($output);
}else{

$this->response(array(
"error" => 400,
"msg" => "Crie uma sessão com um usuário válido || Envie o parametro disciplina"
));

}

}

private function getContent($cookie){

$http_client= new HttpFactory(
"GET",
"https://siga.cps.sp.gov.br/aluno/notasparciais.aspx",
null,
null,
$cookie
);
$response= $http_client->request();
return $response->getBody()->getContents();
}

public function Post(){



}


private function trataJson($dados){
$aulas = array();
$dados = $dados->gxHiddens->W0008W0013Grid1ContainerDataV;
$dados = json_decode($dados);
foreach($dados as $aula){

$aulas[] = array(
"AULA" => $aula[4],
"DESCRICAO" => $aula[11],
"TIPO" => $aula[18],
"DATA" => $aula[34],
"CONTEUDO" => $aula[42],
);

}
return $aulas;
}

}
Loading

0 comments on commit d4685bd

Please sign in to comment.